Show-n-Tell: Deleting items in Sent view with an agent

I wish I could take credit for this, but this one comes from my colleague, Phil Nocerini. Check out what’s rattling around in his warped head at http://nocerini.tumblr.com – Now, on with the tip:

We have a Lotus Notes user that is using a 3rd party mobile client to work with their mail and calendar. This 3rd party mobile client (to remain unnamed) always keeps a copy of any sent item in ‘Sent’. This cannot be changed for just one person, but this person wants items in their sent deleted. Phil wrote some quick code that would run on the mail file once an hour, and would delete the sent item using the Remove method, so that the items go into the Trash, instead of being directly removed from the mail file. This will remove the message from the ‘unnamed 3rd party app’ on the Smartphone as well. (In the ‘unnamed 3rd party app’, if the message is hard deleted, the message headers will not be removed from the app. Here’s the code:

%REM
       Agent Sent View Purge
       Created Nov 22, 2011 by Philip J Nocerini
       Description: Comments for Agent
%END REM
Option Public
Option Declare

Sub Initialize()
      Dim s As New NotesSession 
      Dim db As NotesDatabase 
      Dim view As NotesView 
      Dim doc As NotesDocument 
      Dim nextdoc As NotesDocument 
      
      Set db = s.CurrentDatabase 
      Set view = db.GetView(“$Sent“) 
      Set doc = view.GetFirstDocument 
      While Not ( doc Is Nothing
            Set nextdoc = view.getnextdocument(doc)
‘ the sample code from IBM purges documents after 30 days. CMA’s requirement is to
‘ purge documents immediately by sending them to the trash- PJN 
                  Call doc.Remove(True
            Set doc = nextdoc 
      Wend
End Sub

Simple and clean!