Subject: Posted Code for Delete Email agent!
I am using PostedDate to catch any old mails that were forwarded. Also, I am just testing it in my own mailbox to delete email older than 45 days.Thanks, here’s the code:
Sub Initialize
Dim S As New NotesSession
Dim Db As NotesDatabase
Dim DateToday As String
Dim MonthToday As Integer
Dim DayToday As Integer
DateToday$ = Today()
Set db = S.currentdatabase
’ Check date; agent only runs on January 2 and July 2
MonthToday = Month( DateToday )
DayToday = Day( DateToday )
’ If MonthTo ay = 1 Or MonthToday = 7 Then
’ If DayToday = 2 Then
If MonthToday = 12 Then
If DayToday = 28 Then
Call CleanupEmails
Else
Print “Exited without processing. Agent will process only on January 2 or July 2.”
’ Exit Sub
End If
Else
Print “Exited without processing. Agent will process only on January 2 or July 2.”
Exit Sub
End If
End Sub
Sub CleanupEmails
Dim Dbdir As New NotesDbDirectory( “NotesServer1” )
Dim item As NotesItem
Set YrAgoDate = New NotesDateTime( “Today” )
Call YrAgoDate.AdjustDay( -45 )
’ Call YrAgoDate.AdjustYear( -5 )
Set Db = Dbdir.GetFirstDatabase( DATABASE )
While Not( Db Is Nothing )
’ If Instr(Db.Filepath, “ext”) <> 1 Then
If Db.filepath = “extmail\mherr.nsf” Then
Call Db.Open( “”,“” )
’ Opens currently-selected DB from DbDirectory.
Set docColl = Db.AllDocuments
Set doc = docColl.GetFirstDocument
x = 0
Do While Not( doc Is Nothing )
If doc.HasItem( “PostedDate” ) Then
Flag = 1
Set item = doc.GetFirstItem( “PostedDate” )
IsRFC = item.Type
If IsRFC = 1282 Then
Dim DocDate As New NotesDateTime( doc.PostedDate(0) )
Else
Set DocDate = item.DateTimeValue
End If
Else
Flag = 0
Dim abc As Variant
abc = Evaluate({@Created}, doc)
Dim DocDate1 As New NotesDateTime( abc(0) )
End If
Set docNext = docColl.GetNextDocument( doc )
If Flag = 1 Then
TimeDif = YrAgoDate.TimeDifference( DocDate )
Else
TimeDif = YrAgoDate.TimeDifference( DocDate1 )
End If
If ((doc.Form(0)=“” Or doc.Form(0)=“Memo” Or doc.Form(0)=“Reply” Or doc.Form(0)=“Reply With History” Or _
doc.Form(0)=“(Return Receipt)” Or doc.Form(0)=“Return Receipt” Or doc.Form(0)=“(ReturnNonReceipt)” Or _
doc.Form(0)=“ReturnNonReceipt”)) And TimeDif > 0 Then Call doc.Remove( True )
Set doc = docnext
x = x + 1
Loop
Print "Processed " & x & " documents in " & db.Title & “'s Mailbox.”
End If
Set Db = Dbdir.GetNextDatabase
Wend
End Sub