home *** CD-ROM | disk | FTP | other *** search
Wrap
REM Description: Send current document as email note or attachment REM Filename: mailcmc.wmc REM Created by: Rich Zuris - 1/27/94 REM Supports CMC (Common Messaging Calls - XAPIA) standard REM Contact your email vendor regarding CMC support 'This macro will send the current document as an email attachment on a CMC- 'compatible email system. If the current document is in the form of an email 'note, containing recipient name(s) and a subject, it will send the document 'as a note instead of an attachment so that the message can be read by 'recipients without WSWin. 'The macro will search page 1 of the current document for "To:" and "Subject:" 'lines. If found, it will use these paragraphs to address the message. If an 'optional "Attachments:" line is found, it will attach these files to the 'message. If "To:" and "Subject:" lines are not found, the entire document 'will be attached to a blank message, and your email system will prompt you 'for recipients and other options. You may customize the options below to suit 'your needs. 'You may customize the following settings. They are used to determine whether 'the current document should be sent as a note or an attachment. CONST TO_TEXT$ = "To:" 'Text that marks the list of recipients CONST SUBJ_TEXT$ = "Subject:" 'Marks the subject text CONST ATT_TEXT$ = "Attachments:" 'Marks an optional list of attachments CONST DELIMITER$ = ";" 'Separates multiple recipients or attachments 'Note: Multiple recipients or attachments must appear in a single paragraph, 'with only the delimeter character and optional spaces in between each item. 'Should search for above keywords ignore upper/lowercase? 1 = yes, 0 = no CONST IGNORE_CASE% = 0 'Display email dialog if document is a message with subject and recipients? ' 0 = Don't display dialog ' 1 = Always display ' 2 = Always prompt before displaying ' 3 = Only prompt before displaying if there are no attachments 'Note: Microsoft Mail 3.0 will NOT paste the message text into the note field 'if you display the email dialog but do not include attachments. CONST DISPLAY_DIALOG% = 2 'Caption for MessageBox SHARED MsgTitle$ MsgTitle$ = "Mailcmc Macro" 'MessageBox flags from constant.wmc CONST OK_CANCEL% = 1 CONST YES_NO_CANCEL% = 3 CONST YES_NO% = 4 CONST RETRY_CANCEL% = 5 CONST STOP% = 16 CONST QUESTION% = 32 CONST EXCLAMATION% = 48 CONST INFORMATION% = 64 CONST OK% = 1 CONST CANCEL% = 2 CONST RETRY% = 4 CONST YES% = 6 CONST NO% = 7 'Initialize cmc_send_document parameters SHARED To$, Subject$, NoteText$, Attachments$, FileTitle$ To$ = "" Subject$ = "" NoteText$ = "" Attachments$ = "" FileTitle$ = "" 'Screen state SHARED freeze% 'File position SHARED NotePos% 'CMC Flags--do not modify CONST ERROR_UI_ALLOWED% = 1 * 16 ^ 6 'Do not modify this value CONST LOGON_UI_ALLOWED% = 2 * 16 ^ 6 'Do not modify this value CONST SEND_UI_REQUESTED% = 1 'Do not modify this value SHARED SENDFLAGS% SENDFLAGS% = ERROR_UI_ALLOWED% + LOGON_UI_ALLOWED% 'APIs DECLARE FUNCTION GetTempFileName LIB "kernel" (bDriveLetter AS WORD, lpszPrefixString AS STRING, uUnique AS WORD, lpszTempFileName AS STRING) As Word DECLARE FUNCTION cmc_send_documents LIB "cmc.dll" (lpRecip AS STRING, lpSubject AS STRING, lpTextNote AS STRING, ulFlags AS INTEGER, lpFilePaths AS STRING, lpFileNames AS STRING, lpDelim AS STRING, ulUID as INTEGER) AS Integer DECLARE FUNCTION GetKeyText$ (lpKeyword$) DECLARE FUNCTION GetFurthestPos% (prevPos%) DECLARE FUNCTION DisplayDialog% (ask%, att$) DECLARE FUNCTION MakeAttachment$ (lpFileTitle$, flags%) DECLARE SUB Status (ret%) DECLARE SUB AbortMacro () 'Can't run if no document open IF GetDocName$() = "" THEN Msg$ = "Please create a new document or open an existing document first." ret% = MessageBox(Msg$, MsgTitle$, EXCLAMATION%) STOP ENDIF 'Ensure we're in Edit mode in the Page Editor ViewEditor 1 ViewEditMode 1 'Prevent screen updates freeze% = ViewFreezeScreen(1) 'If not a normal text frame, send as attachment frameType% = GetTextFrameType() IF frameType% = 0 OR frameType% > 3 THEN GOTO SENDATT 'Get recipient list, subject, attachments, and note text, if this is a memo 'Use furthest keyword position from top of file as start of note text StatusMsg "Checking document for email text . . ." NotePos% = 0 TmpFile% = 0 To$ = GetKeyText$(TO_TEXT$) NotePos% = GetFurthestPos%(NotePos%) Subject$ = GetKeyText$(SUBJ_TEXT$) NotePos% = GetFurthestPos%(NotePos%) Attachments$ = GetKeyText$(ATT_TEXT$) IF Attachments$ <> "" THEN NotePos% = GetFurthestPos%(NotePos%) StatusMsg "" 'If no recipients or subject found, send doc as an attachment IF To$ = "" OR Subject$ = "" THEN GOTO SENDATT 'Go to beginning of note text and select rest of story as the note text EditGotoOffset NotePos%, 'Go to end of keyword list WordRight 'Go to beginning of next line EndOfStory 1 'Select rest of document NoteText$ = GetSelection$(1) 'Get note text 'If no attachments specified and email dialog is displayed, 'user may need to paste in the note text manually IF DisplayDialog%(DISPLAY_DIALOG%, Attachments$) THEN SENDFLAGS% = SENDFLAGS% OR SEND_UI_REQUESTED% END IF 'If there are dependent frames in this document, prompt whether to send current 'selection as a text note, or entire document as an attachment IF CountFrames() <> CountPages() THEN Msg$ = "This document contains dependent frames, and only the current frame " Msg$ = Msg$ + "is being used for the email note. Do you wish to attach the " Msg$ = Msg$ + "document to the email note?" ret% = MessageBox(Msg$, MsgTitle$, YES_NO_CANCEL% + QUESTION%) IF ret% = CANCEL% THEN AbortMacro IF ret% = NO% THEN GOTO SENDDOC ELSE GOTO SENDDOC END IF 'Send entire document as an attachment SENDATT: Attachments$ = MakeAttachment$(FileTitle$, SENDFLAGS%) TmpFile% = 1 'Call CMC.DLL to send the document or message SENDDOC: StatusMsg "Calling email system . . ." ret% = cmc_send_documents(To$, Subject$, NoteText$, SENDFLAGS%, Attachments$, FileTitle$, DELIMITER$, 0) StatusMsg "" IF TmpFile% = 1 THEN KILL Attachments$ Status (ret%) EditGotoOffset NotePos%, freeze% = ViewFreezeScreen(freeze%) 'Move this up if it interferes with UI STOP '************************************* 'Find keyword text for email note ' 'Search the first page of the doc only '************************************* FUNCTION GetKeyText$ (lpKeyword$) StartOfStory EndOfFrame IF (EditFind( lpKeyword$, 1, 0, 0, IGNORE_CASE%, 1, )) THEN 'Find first occurrence, searching backward DO ret% = EditFindNext(0) LOOP WHILE ret% = 1 'If keyword found only once, it's highlighted. If found more than once, 'it is unhighlighted. Unhighlight it for consistency. ret% = GetTextOffset(beg%, end%) EditGotoOffset beg%, 'Move one word to the right, then select remainder of paragraph WordRight EndOfPara 1 'Return selected text GetKeyText$ = GetSelection$(1) ELSE GetKeyText$ = "" END IF END FUNCTION '************************************************* 'Get furthest keyword position from start of file 'Used to determine where note text begins ' 'Param: previous position 'Returns: greater of previous or current position '************************************************* FUNCTION GetFurthestPos% (prevPos%) ret% = GetTextOffSet (beg%, end%) EditGotoOffset end%, IF prevPos% > end% THEN GetFurthestPos% = prevPos% ELSE GetFurthestPos% = end% END IF END FUNCTION '************************************************** 'Create temp file to send document as an attachment ' 'Params: ' buffer to hold file title ' send flags ' 'Returns: ' returns temp file name of attachment ' sets file title to name of document ' ensures flags will request email UI '************************************************** FUNCTION MakeAttachment$ (lpFileTitle$, flags%) 'Get temporary file name and save copy of document 'Hope there's enough disk space on temp drive, etc. MKTMP: lpFileName$ = STRING$(144, " ") ret% = GetTempFileName(I2W(0), "WSW", I2W(0), lpFileName$) FileSaveAsCopy (lpFileName$) IF ACCESS(lpFileName$, 0) = 0 THEN Msg$ = "Could not create temporary file. You may be low on disk space. " Msg$ = Msg$ + "Delete some files and choose Retry, or choose Cancel to quit." Flags% = RETRY_CANCEL% + EXCLAMATION% IF MessageBox(Msg$, MsgTitle$, Flags%) = RETRY% THEN GOTO MKTMP AbortMacro END IF 'Get title of this document from WSWin docName$ = GetDocName$() WHILE INSTR(docName$, "\") docName$ = MID$(docName$, INSTR(docName$, "\") + 1) WEND 'If doc is untitled, name it Untitled (sans number) IF LEFT$(docName$, 8) = "Untitled" THEN docName$ = "Untitled.wsd" END IF MakeAttachment$ = lpFileName$ lpFileTitle$ = docName$ flags% = flags% OR SEND_UI_REQUESTED% 'Ensure email dialog will be displayed END FUNCTION '********************************************************** ' ' Determine whether email dialog should be displayed ' ' Params: ' flag indicating whether to always prompt ' attachments (empty string if none) ' ' Copies selected text to clipboard if no attachments ' ' Returns: 1 if dialog should be displayed, else 0 ' '********************************************************** FUNCTION DisplayDialog% (ask%, att$) IF att$ = "" THEN EditCopy 'Copy note text to clipboard CharLeft 1, , 'Unhighlight the text selection END IF SELECT CASE ask% CASE 0 'Never display DisplayDialog% = 0 CASE 1 'Always display DisplayDialog% = 1 CASE 3 'Prompt before displaying if there are no attachments IF att$ = "" THEN GOTO ASK_DISP CASE 2 'Always prompt before displaying ASK_DISP: Question$ = "Display email dialog before sending message?" ret% = MessageBox (Question$, MsgTitle$, YES_NO_CANCEL% + QUESTION%) IF ret% = CANCEL% THEN AbortMacro IF ret% = NO% THEN DisplayDialog% = 0 ELSE 'Yes DisplayDialog% = 1 END IF END SELECT COPY_INFO: IF DisplayDialog% = 1 AND att$ = "" THEN Msg$ = "The note text has been copied to the clipboard. If the note text " Msg$ = Msg$ + "does not appear, you can paste it into the message body " Msg$ = Msg$ + "from the email menu." ret% = MessageBox (Msg$, MsgTitle$, INFORMATION%) END IF END FUNCTION '******************************* ' Abort macro '******************************* SUB AbortMacro BEEP IF NotePos% <> 0 THEN EditGotoOffset NotePos%, Status (36) freeze% = ViewFreezeScreen (freeze%) STOP END SUB '******************************* 'Display message if error occurs '******************************* SUB Status (status%) Select Case status% Case 0 Msg$ = "Success" Case 1 Msg$ = "Ambiguous recipient" Case 2 Msg$ = "Attachment not found" Case 3 Msg$ = "Attachment open failure" Case 4 Msg$ = "Attachment read failure" Case 5 Msg$ = "Attachment write failure" Case 6 Msg$ = "Counted string unsupported" Case 7 Msg$ = "Disk full" Case 8 Msg$ = "Failure" Case 9 Msg$ = "Insufficient memory" Case 10 Msg$ = "Invalid configuration" Case 11 Msg$ = "Invalid enum" Case 12 Msg$ = "Invalid flag" Case 13 Msg$ = "Invalid memory" Case 14 Msg$ = "Invalid message parameter" Case 15 Msg$ = "Invalid message reference" Case 16 Msg$ = "Invalid parameter" Case 17 Msg$ = "Invalid session ID" Case 18 Msg$ = "Invalid UI ID" Case 19 Msg$ = "Logon failure" Case 20 Msg$ = "Message in use" Case 21 Msg$ = "Not supported" Case 22 Msg$ = "Password required" Case 23 Msg$ = "Recipient not found" Case 24 Msg$ = "Service unavailable" Case 25 Msg$ = "Text too large" Case 26 Msg$ = "Too many files" Case 27 Msg$ = "Too many recipients" Case 28 Msg$ = "Unable to not mark as read" Case 29 Msg$ = "Unrecognized message type" Case 30 Msg$ = "Unsupported action" Case 31 Msg$ = "Unsupported character set" Case 32 Msg$ = "Unsupported data ext" Case 33 Msg$ = "Unsupported flag" Case 34 Msg$ = "Unsupported function ext" Case 35 Msg$ = "Unsupported version" Case 36 Msg$ = "Message canceled" Case 37 Msg$ = "User not logged on" Case Else Msg$ = "Unknown error" End Select IF status% <> 0 THEN ret% = MessageBox(Msg$, MsgTitle$, EXCLAMATION%) END SUB ***** WARNING ***** This is a WSWin macro file. Subsequent data is binary information and should not be modified.