Subject: convert email to a document in another NSF
In one.nsf create an agent type After new mail has arrived.
Sub Initialize
Dim Ses As New NotesSession
Dim cDb As NotesDatabase
Dim tDb As New NotesDatabase(“”, “”)
Dim cCol As NotesDocumentCollection
Dim cDoc As NotesDocument
Dim tDoc As NotesDocument
Dim RTI As NotesRichTextItem
Dim Arr As Variant
Set cDb = Ses.CurrentDatabase
Call tDb.OpenByReplicaID(“”, “12345678:12345678”) 'here comes rep id of the two.nsf
If tDb Is Nothing Then Exit Sub
If Not tDb.IsOpen Then Exit Sub
Set cCol = cDb.UnprocessedDocuments
Set cDoc = cCol.GetFirstDocument
While Not cDoc Is Nothing
Set RTI = cDoc.GetFirstItem(“Body”)
If RTI.Type = RICHTEXT Then
Let Arr = ParseContent(RTI.GetUnformattedText, Arr)
Set tDoc = tDb.CreateDocument
Let tDoc.Form = “SomeForm”
Let tDoc.Pono = Arr(0)
Let tDoc.Amount = Arr(1)
Let tDoc.Date = Arr(2)
Call MovePDF(RTI, tDoc)
Call tDoc.Save(True, False)
End If
Call Ses.UpdateProcessedDoc(Doc)
Set cDoc = cCol.GetNextDocument(cDoc)
Wend
End Sub
Function ParseContent must parse text for strings pono=, amount=, date= and return content of those variables to the array.
Function MovePDF must detach PDF file from the Body field to the temporary directory on server harddrive and then attach that file to a newly created richtext field in the tDoc.
To get temporary directory I use following function:
Private Function GetTempDir As String
Select Case Session.Platform
Case “Windows/32”,“Windows/16”,“MS-DOS”
Let GetTempDir = Environ(“TEMP”) & ""
Case “Linux”,“UNIX”
Let GetTempDir = “/tmp/”
End Select
End Function
Enjoy.