'LS.MailRoutines: Option Public Option Declare %REM --- Credit where credit is due: Portions of this code are shamelessly stolen from / modified from / inspired by... a posting from Andre Guirard at: http://www-10.lotus.com/ldd/bpmpblog.nsf/dx/sign-at-the-top --- Description of included functions --- FUNCTION: InsertSignature Description: Look to the user's mail profile document to determine their normal email signature (if one is designated). Append the signature at the bottom of the frontend document for which a handle has been passed. Input parameters: uiMemo As NotesUIDocument Handle to the front end document that will have sig appended at bottom docProfile As NotesDocument Handle to user's mail profile document Returns: Boolean indicating success (True) or failure (False) of the function execution. If the function is returning a False, an error message would already have been displayed, so no need to do so from the calling routine. Calls: This function calls no other functions. --- FUNCTION: createMemoWithLink Description: Create a new memo in the user's mail file. Insert some text and a doclink in the top area of the memo body, with the user's signature (if any) inserted at the bottom of the memo. The user is left with the new memo sitting open in the UI, waiting for them to complete and send the memo. NOTE: Due to the contortions we have to go through to get the sig to be placed at the bottom of the memo - after the inserted text and doclink - IF the user exits the new memo without sending, there WILL be a document left in their Drafts folder. Input parameters: doc As NotesDocument Handle to the backend document that should be linked via doclink in new memo Returns: Boolean indicating success (True) or failure (False) of the function execution. If the function is returning a False, an error message would already have been displayed, so no need to do so from the calling routine. Calls: This function calls InsertSignature from this same library. %END REM Function InsertSignature( uiMemo As NotesUIDocument, docProfile As NotesDocument ) As Boolean ' Adapted from the InsertSignature sub contained in the CoreEmailClasses script library in mail template On Error Goto errHandler Dim bFuncStatus As Boolean bFuncStatus = True Dim strFilterList List As String strFilterList("JPG") = "JPEG Image" strFilterList("JPEG") = "JPEG Image" strFilterList("BMP") = "BMP Image" strFilterList("GIF") = "GIF Image" strFilterList("HTM") = "HTML File" strFilterList("HTML") = "HTML File" strFilterList("TXT") = "ASCII" Dim intSigOption As Integer Dim strSig As String intSigOption = Cint(docProfile.GetItemValue("SignatureOption")(0)) strSig = docProfile.GetItemValue("Signature")(0) Dim varFILTER As Variant Call uiMemo.GotoField("Body") Select Case intSigOption Case 1 ' Text sig contained within profile doc Call uiMemo.GotoField("Body") Case 2 ' Sig in profile doc is from an external file, so import with appropriate filter varFILTER = Evaluate(|@RightBack("| & strSig & |";".")|) Dim strFileExt As String Dim strFilterString As String If Trim(varFILTER(0)) <> "" Then strFileExt = Trim(Ucase(varFILTER(0))) If Iselement(strFilterList(strFileExt)) = True Then strFilterString = strFilterList(strFileExt) End If Else strFilterString = "" End If Call uiMemo.InsertText(Chr(10)) Call uiMemo.InsertText(Chr(10)) Call uiMemo.Import(strFilterString, strSig) uiMemo.GotoField("Body") End Select finally: InsertSignature = bFuncStatus Exit Function errHandler: bFuncStatus = False Dim sErrMsg As String Select Case Err Case Else sErrMsg = "Error #" & Err & Chr$(10) & Error$ & Chr$(10) _ & "Line #" & Erl & | in sub/function: "| & Lsi_info(2) & |"| Msgbox sErrMsg, 16, "Unexpected error" End Select Resume finally End Function Function createMemoWithLink( doc As NotesDocument ) As Boolean On Error Goto errHandler Dim bFuncStatus As Boolean bFuncStatus = True Dim ws As New NotesUIWorkspace Dim session As New NotesSession Dim dbThis As NotesDatabase Set dbThis = session.CurrentDatabase ' Create new memo in user's mail file Dim dbMail As New NotesDatabase("", "") Call dbMail.OpenMail Dim memo As NotesDocument Set memo = dbMail.CreateDocument memo.Form = "Memo" Dim body As New NotesRichTextItem( memo, "Body" ) Call memo.Save( True, True, True ) ' Open memo in ui Dim uiMemo As NotesUIDocument Set uiMemo = ws.EditDocument(True, memo ) ' Get user's mail profile doc Dim docMailProfile As NotesDocument Set docMailProfile = dbMail.GetProfileDocument("CalendarProfile") ' If user is set up to use a sig file, insert that sig in our temp doc Dim bSuspendSig As Boolean Dim varSigOption As Variant Dim intSigOption As Integer varSigOption = docMailProfile.GetItemValue("SignatureOption")(0) intSigOption = Cint(varSigOption) Dim strSig As String strSig = docMailProfile.GetItemValue("Signature")(0) If Trim$(strSig) <> "" Then ' They have either a text string or a filename designated as a sig - ' see if their profile doc is set to use the sig Select Case intSigOption Case 1, 2 ' They're set up with a sig file, so set the flag to remind us to ' reset their profile doc when we're done bSuspendSig = True ' Get their sig inserted into the memo; exit if any problems If Not InsertSignature( uiMemo, docMailProfile ) Then Error 1000, "" docMailProfile.SignatureOption = "" ' Disable the sig in their profile doc Case Else ' No sig specified End Select End If ' Save the mail doc Dim strMemoUNID As String strMemoUNID = uiMemo.Document.UniversalID uiMemo.Document.MailOptions = "0" Call uiMemo.Save uiMemo.Document.SaveOptions = "0" Call uiMemo.Close Delete uiMemo Delete memo ' --- ' Open memo in back end and insert the text and doclink. Set memo = dbMail.GetDocumentByUNID( strMemoUNID ) Dim rtiSig As NotesRichTextItem ' Get handle to rt field with sig (if there is a sig) Set rtiSig = memo.GetFirstItem( "Body" ) Dim rtiNew As New NotesRichTextItem( memo, "rtiTemp" ) ' Create new rt field and append text/doclink Call rtiNew.AddNewline( 2 ) Call rtiNew.AppendText( "To open the referenced document, please click here: ") Call rtiNew.AppendDocLink( doc, dbThis.Title & ": " & doc.title(0) ) Call rtiNew.AppendRTItem( rtiSig ) ' Append sig from earlier rt item Set body = New NotesRichTextItem( memo, "Body" ) ' Create fresh 'Body' rt item Call body.AppendRTItem( rtiNew ) ' Append text/doclink and sig Call rtiNew.Remove ' Remove temp rt item Call memo.Save( True, True, True ) ' Save the memo with reconstructed body ' Open memo in ui for user to continue.... Set uiMemo = ws.EditDocument(True, memo ) If bSuspendSig Then ' restore signature setting. Notice we didn't save the profile ' document. Since it is cached, there is no need; the memo form ' we just opened saw our modified value, and now we're putting ' it back so the cached document is still the same as the document ' on disk. docMailProfile.SignatureOption = varSigOption End If finally: createMemoWithLink = bFuncStatus Exit Function errHandler: bFuncStatus = False Dim sErrMsg As String Select Case Err Case 1000 ' just exit; any needed message was already displayed Case Else sErrMsg = "Error #" & Err & Chr$(10) & Error$ & Chr$(10) _ & "Line #" & Erl & | in sub/function: "| & Lsi_info(2) & |"| Msgbox sErrMsg, 16, "Mail memo could not be created" End Select Resume finally End Function
This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.