Well that’s really two questions isn’t it? First, how to get a handle on the documents and there contents, and second, what algorythm to use to compare and trim the text?
To get a handle on the selected documents, you only have to use the database unprocessed documents collection. From an agent set to run on selected documents, this will always return the selected documents. The documentation says they are returned in random order, but actually that’s not true. They are, in fact, returned in the order they were added to the database, so you can easily grab the most recent document without any need to sort or process the list.
Then you have to look at the contents. The Body field in a Notes email is a RichText field and LotusScript only provides an easy way to get at its text contents. So if you want to be able to preservce rich text contents, your little project is quickly going to get very costly. But if you are content to trim the older messages down to archival text, you might do something like this:
Dim session As New NotesSession
Dim db As NotesDatabase
Dim Selected As NotesDocumentCollection
Dim Doc As NotesDocument
Dim Master As NotesDocument
Set db=session.CurrentDatabase ‘ Get handle to database
Set Selected=db.UnprocessedDocuments ‘ Get collection of all selected documents.
Dim MasterBody As NotesRichTextItem
Dim MasterBodytext As String
For i=1 To Selected.Count ‘ Scan selected documents (In the order they were added to the database).
Dim Body As NotesRichTextItem
Dim Bodytext As String
. . . INSERT COMPARISON CODE HERE …
Set Body = new NotesRichTextItem(Doc,”Body”,TheTextToKeep)
Next ‘ i