Get Rules From Users Mailfile
February 13, 2007 – 2:47 pm
A few days ago I was asked to create a report about all rules in all mailfiles. The easiest way to do this is to write an agent to examine the mailfiles.
The result of this scan is stored in a Notes database.
Put the following code into an agent ( start: manually from menue, target: All Selected Documents )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | Sub Initialize On Error Resume Next Dim session As New NotesSession Dim NAB As NotesDatabase Dim resultDocs As NotesDocumentCollection Dim MailFiles As NotesDocumentCollection Dim doc As NotesDocument Dim NABDoc As NotesDocument Dim rtitem As Variant Dim MailFileItem As NotesItem Dim i As Integer Dim NabDocCounter As Integer Dim fNAME As String Dim logline As String Set NAB = session.CurrentDatabase Set MailFiles = NAB.UnprocessedDocuments Dim RetCode As Integer Dim MailServer As String Dim MailFile As String Dim db_AllDocsCol As NotesDocumentCollection Dim db_User As String Dim archiveDb As New NotesDatabase( "", "RULEZ.NSF" ) Dim k As Integer For NabDocCounter = 1 To MailFiles.Count db_User = "" Set NABDoc = MailFiles.GetNthDocument ( NABDocCounter ) Set MailFileItem = NABDoc.GetFirstItem ( "LastName" ) db_User = MailFileItem.Text & ", " Set MailFileItem = NABDoc.GetFirstItem ( "FirstName" ) db_User = db_User + MailFileItem.Text Set MailFileItem = NABDoc.GetFirstItem ( "MailServer" ) MailServer = MailFileItem.Text Set MailFileItem = NABDoc.GetFirstItem ( "MailFile" ) MailFile = MailFileItem.Text Dim db As New NotesDatabase ("", "" ) Call db.Open ( MailServer, MailFile ) If db.IsOpen Then Dim dateTime As New NotesDateTime(_ Cstr(Datenumber(2000, 5, 1))) Set resultDocs = db.Search( {@UpperCase(Form)="MAILRULE"}, dateTime,0) Call ResultDocs.StampAll ("RuleOwner", db_user) For k = 1 To resultDocs.Count Set doc = resultDocs.GetNthDocument ( k ) Call doc.CopyToDatabase ( archiveDB ) Next End If Next End Sub |
When the agent finds rules in a mailfile, it copies the documents found into a Notesdatabase defined in the following line of code.
1 | Dim archiveDb As New NotesDatabase( "", "RULEZ.NSF" ) |
The database itself does not have any design elements except a modified DEFAULT view. The view contains 3 columns.
Column 1: Field RuleOwner
Column 2: Field ConditionList
Column 3: Field ActionList
That’s all !
Technorati: Show-n-Tell Thursday





1 Trackback(s)
Sorry, comments for this entry are closed at this time.