English 中文(简体)
Lotus Notes - Export emails to plain text file
原标题:

I am setting up a Lotus Notes account to accept emails from a client, and automatically save each email as a plain text file to be processed by another application.

So, I m trying to create my very first Agent in Lotus to automatically export the emails to text.

Is there a standard, best practices way to do this?

I ve created a LotusScript Agent that pretty much works. However, there is a bug - once the Body of the memo exceeds 32K characters, it starts inserting extra CR/LF pairs.

I am using Lotus Notes 7.0.3.

Here is my script:

 Sub Initialize
 On Error Goto ErrorCleanup
 Dim session As New NotesSession
 Dim db As NotesDatabase
 Dim doc As NotesDocument
 Dim uniqueID As Variant 
 Dim curView As NotesView
 Dim docCount As Integer
 Dim notesInputFolder As String 
 Dim notesValidOutputFolder As String
 Dim notesErrorOutputFolder As String 
 Dim outputFolder As String
 Dim fileNum As Integer
 Dim bodyRichText As NotesRichTextItem
 Dim bodyUnformattedText As String
 Dim subjectText As NotesItem

                                                        
  INPUT OUTPUT LOCATIONS 
 outputFolder = "\PASCRIACignaDFSCUser1HomemikebecMyDocuments"
 notesInputFolder = "IBEmails" 
 notesValidOutputFolder = "IBEmailsDone"
 notesErrorOutputFolder="IBEmailsError"
                                                        

 Set db = session.CurrentDatabase
 Set curview = db.GetView(notesInputFolder ) 
 docCount = curview.EntryCount
 Print "NUMBER OF DOCS "  & docCount
 fileNum = 1
 While (docCount > 0)
   set current doc to 
  Set doc = curview.GetNthDocument(docCount)

  Set bodyRichText = doc.GetFirstItem( "Body" )
  bodyUnformattedText = bodyRichText.GetUnformattedText()
  Set subjectText = doc.GetFirstItem("Subject")
  If subjectText.Text = "LotusAgentTest" Then
   uniqueID = Evaluate("@Unique")
   Open "\PASCRIACignaDFSCUser1HomemikebecMyDocumentsemail_" & uniqueID(0) & ".txt" For Output As fileNum
   Print #fileNum, "Subject:" & subjectText.Text
   Print #fileNum, "Date:" & Now
   Print #fileNum, bodyUnformattedText
   Close fileNum
   fileNum = fileNum + 1
   Call doc.PutInFolder(notesValidOutputFolder)
   Call doc.RemoveFromFolder(notesInputFolder)
  End If
  doccount = doccount-1
 Wend
 Exit Sub
    ErrorCleanup: 
     Call sendErrorEmail(db,doc.GetItemValue("From")(0))
     Call doc.PutInFolder(notesErrorOutputFolder)
     Call doc.RemoveFromFolder(notesInputFolder)
    End Sub

Update Apparently the 32KB issue isn t consistent - so far, it s just one document that starts getting extra carriage returns after 32K.

问题回答

With regards the 32Kb thing, instead of this:

Set bodyRichText = doc.GetFirstItem( "Body" )

... you might want to consider iterating all "Body" fields in the email document. When dealing with large amounts of rich text, Domino "chunks" said content into multiple rich text fields. Check some documents you re processing: you may well see multiple instances of the "Body" field when you look at document properties.

I m not sure what is causing the 32K bug, but I know there are lots of limitations in the order of 32K or 64K within Lotus Notes, so perhaps you re running into one of those. I can t imagine what would add extra CR/LFs. Perhaps you could try using the GetFormattedText method on the NotesRichTextItem class and see if it fares better?

It s more complicated, but you might also be able to use the NotesRichTextNavigator class to iterate through all the paragraphs in the memo, outputting them one at a time. Breaking up the output that way might eliminate the CR/LF problem.

Lastly I always suggest Midas LSX for dealing with rich text in Lotus Notes. They sell an add-on that gives you much more control over rich text fields.

As for best practices, one that comes to mind when I read your code is the looping construct. It is more efficient to get the first document in a view, process it, and then get the next doc and check whether it is equal to Nothing. That sets the loop to run through the view in index order, and eliminates the need to search through the index to find the Nth document each time. It also saves you from maintaining a counter. The gist is as follows:

Set doc = curview.GetFirstDocument()
While Not (doc Is Nothing)

     Do processing here...

    Set doc = curview.GetNextDocument(doc)
Wend

The external eMail most likely comes in as MIME. So you could check the document.hasMime and then use the mime classes to get to the content. Then you don t have a 64k limit. Samples are in the help - or reply if you want code.





相关问题
Where are the javadocs for Lotus Notes.jar?

I need to use Lotus Notes/Domino as a data source from a Java application. The documentation at IBM says that the Notes.jar contains everything I will need, but where are the javadocs?

Is Interop.Domino dll thread safe?

I am using Interop.Domino dll version 1.2 in c# application, and using multithreading to access multiple NSF file at same time by creating new session for each thread created (Max 5 threads at a time)....

C#和Lotus Notes附录一

我正在使用C#,并需要附上一张空白(shortcut/link)档案和电子邮件给一个彩票账户。 问题是一对一幅通用形象的不实之词,没有像......那样显示双fold。

How to maintain Lotus Notes Version ? C#

I made one product which is retrieving attachment from mails and saving it on particular folder. But problem i am facing is it is not working in 8.0 version. I did development on Lotus Notes 8.5 ...

How to Edit NSF file using c#?

I want to programaticaly change some values to NSF item and then want to save it.(i.e to edit NSF File and then save the editions) for example: I want to set Sender name of all mails to "preeti@abc....

热门标签