This is our first Show’n Tell Thursday posting (what a great idea Mr. B Balaban and Mr. R Oliver!) and even though today is actually Friday, it’s better to be late than never! So here goes.

Show-n-tell ThursdaySince our office entirely moved to a Linux desktop environment, we ceased using the Lotus Notes client for email as it does not run natively under Linux (well, not yet at least…).

Instead we use the Mozilla Thunderbird Email (just a standard SMTP, IMAP, POP3 mail client) using SMTP/IMAP and SSL to send/retrieve email. The switch has been almost completely painless, with a few minor gotchas:

  1. Notes Mail has a unique feature whereby you can have a single email document in many Folders. This is not possible using IMAP.
  2. Moving email documents between Folders causes the document to be deleted from the database and recreated.
  3. Notes Mail uses Views for “All Documents”, “Sent” and “Drafts”. Using a IMAP client these are Folders and must be created separately. Which means that when you open your IMAP-enabled email using Lotus Notes you will have a “Sent” View as well as a “Sent” Folder.

Depending on your level of sophistication on using Lotus Notes these may or may not be major problems. For us these were really minor.

After using IMAP email for a few weeks, we noticed that all of the IMAP sent email appeared differently in the Lotus Notes mail client:

  • First of all, the email was being displayed in our new “Sent” Folder but was not being displayed in the “Sent” View.
  • Secondly, the “Who” column displayed the name of the Sender, not the recipient of the email. Which meant for me, that all of my sent email was addressed to “Justin Freeman”. Totally bizarre.

Some investigation revealed that the problem was caused by Domino stamping all IMAP sent email with a DeliveredDate field, which had the same value as the PostedDate.

Therefore, you would think that simply removing the DeliveredDate field from the IMAP sent email would solve the problem. Yes, this approach works when you know where the IMAP sent documents are all located, ie. the “Sent” Folder. Deleting the DeliveredDate field causes the document to be displayed in the “Sent” View and also display the correct value for “Who”.

But what happens when those documents are not in a known folder, how do you locate those? You need to search the Email database and locate all the IMAP documents, not a simple task.

So to identify a document created by a IMAP email client connecting directly to your Domino server, the following rules are used:

Document must not have the following fields set. As these indicate that the document was routed too, not created directly in the database.

  • Received
  • RouteServers

For Mozilla Thunderbird, document must have the following fields set:

  • DeliveredDate
  • PostedDate
  • $SMTPNotFromNotes
  • User_Agent

For Microsoft Outlook, document must have the following fields set:

  • DeliveredDate
  • PostedDate
  • $SMTPNotFromNotes
  • $Mailer

If the document meets the above criteria, then (I believe) it is a document created by a IMAP client. And the DeliveredDate can be removed.

You can then wrap this logic up into a simple scheduled Notes Agent that parses your email on a daily basis, fixing all of the IMAP sent email so that they display correctly within Lotus Notes. See below for an example.

Function to identify IMAP created documents

Function localImapSentDocument(docTarget As notesdocument) As Integer
'This function determines whether or not the target document was sent directly from a local IMAP client
'When this is performed Domino automatically assigns a delivereddate value which then interferes with the display of the "Who" column in the Inbox
localImapSentDocument = False
If Not docTarget.HasItem("Received") And Not docTarget.HasItem("RouteServers") And docTarget.HasItem("DeliveredDate") And docTarget.HasItem("PostedDate") And docTarget.HasItem("$SMTPNotFromNotes") then
'Check for email sent by Mozilla Thunderbird or Microsoft Outlook client
If docTarget.HasItem("User_Agent") or docTarget.HasItem("$Mailer") Then
localImapSentDocument = True
End If
End If
End Function

Example Agent code

Note: our internal system execution and error logging has been commented out:

Sub Initialize
'Dim syslog As New mylog(cAgent)
'sysLog.FunctionLocationA="Initialise"
'sysLog.FunctionDescription="Removes the delivereddate from imap documents"
'syslog.LogGeneral ("Starting")
On Error Goto errHdlr
Dim ns As New notessession
Dim dbCurrent As notesdatabase
Set dbCurrent = ns.currentdatabase
Dim colEmail As notesdocumentcollection
Set colEmail = dbCurrent.UnprocessedDocuments
Dim docEmail As NotesDocument
Set docEmail = colEmail.GetFirstDocument
Do While Not(docEmail Is Nothing)
'Check if this is a local IMAP document
If localImapSentDocument(docEmail) Then
'If so then remove the DeliveredDate
Call docEmail.RemoveItem("DeliveredDate")
Call docEmail.Save(True,False)
'syslog.LogGeneral ("Updated: " + docEmail.subject(0) + "; UNID: " + docEmail.UniversalID)
End If
Set docEmail = colEmail.GetnextDocument(docEmail)
Loop
'syslog.LogGeneral ("Completed")
Exit Sub
errhdlr:
'sysLog.ProcessError Err, Error$, PROCESSERROR_LOG
Exit Sub
End Sub

Technorati tags: ,