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 "