Daily E-Mail Cleanup Agent

This agent will enable the document property "Folder References"* in each mail
file. Then it will run through the "Inbox", "Sent View", and "All Documents"
and remove any document that is over a specified number of days and not in a
folder or a repeating calendar entry. It will also log errors and actions to a
Mail-in DB. *Folder References must be enabled before the documents are moved
to a folder for safe keeping.
'"Common" Script Library
Option Public
Option Explicit

%INCLUDE "lsconst.lss"
%INCLUDE "lserr.lss"
%INCLUDE "lsxbeerr.lss"
%INCLUDE "lsxuierr.lss"

'************* Folder References Agent
'Options
Option Explicit
Option Public
Use "Common"

'Declarations
Dim currentlog As NotesLog

Const servername = "Servername/Domain"
Const subdir = "Mail\"

'Initialize
Sub Initialize
Dim dbase As NotesDatabase
Dim dbdirectory As New NotesDBDirectory(servername)

Set currentlog = New NotesLog("Folder References Agent")

Call currentlog.OpenMailLog _
("Mail Deletion Log", "Folder References Log")

Set dbase = dbdirectory.GetFirstDatabase (DATABASE)

While Not (dbase Is Nothing)
If Instr(dbase.filepath, subdir) Then

Call EnableFolderReference (dbase)
End If

Set dbase = dbdirectory.GetNextDatabase
Wend

Call currentlog.LogAction ("Folder References Enabled")
Call currentlog.Close

End Sub

'Function EnableFolderReferences
Function EnableFolderReference (dbase As NotesDatabase)
On Error Goto ErrHandler
Call dbase.Open("","")

If(dbase.FolderReferencesEnabled) Then
dbase.FolderReferencesEnabled = True
Else
dbase.FolderReferencesEnabled = True
End If

ErrHandler:
On Error Goto 0
Call currentlog.LogError ( Err, Error$ & " " & dbase.FileName)

Exit Function

End Function

'*******************Mail Deletion Agent
'Options
Option Explicit
Option Public
Use "Common"

'Declarations
Dim dbase As NotesDatabase
Dim db As NotesDatabase
Dim logdb As NotesDatabase
Dim inbox As NotesView
Dim sentbox As NotesView
Dim alldocs As NotesView
Dim cutoffdate As NotesDateTime
Dim doctocheck As NotesDocument
Dim nextdoc As NotesDocument
Dim collection As NotesDocumentCollection
Dim currentlog As NotesLog
Dim deleted As Integer
Dim totaldeleted As Long

Const daysold = 60
Const servername = "Servername/Domain"
Const subdir = "Mail\"

'Initialize
Sub Initialize

Dim dbdirectory As New NotesDBDirectory (servername)
Set currentlog = New NotesLog("E-Mail Deletion Agent")
Set dbase = dbdirectory.GetFirstDatabase (DATABASE)

Call currentlog.OpenMailLog _
("Mail Deletion Log", "E-Mail Deletion Log")

While Not (dbase Is Nothing)
If Instr(dbase.filepath, subdir) Then
Call ProcessMailFile (dbase)
End If
Set dbase = dbdirectory.GetNextDatabase
Wend


Call currentlog.Close

End Sub

'Process Mail File Function
Function ProcessMailFile ( indb As notesdatabase)
Dim i As Integer, age As Long, docref As Variant, session As New NotesSession
deleted = 0
totaldeleted = 0

On Error Goto MailErrHandler

Set cutoffdate = New NotesDateTime( "Today" )
Call indb.Open( "", "" )

'*************************************************'* Check Inbox
'*************************************************
Set inbox = indb.GetView("($Inbox)")

Set doctocheck = inbox.GetFirstDocument
While Not ( doctocheck Is Nothing )
age = Clng(cutoffdate.lsLocaltime - doctocheck.Created)
If (age => daysold) And OkToDelete(doctocheck.form(0)) Then
Set nextdoc = inbox.GetNextDocument( doctocheck )
Call doctocheck.remove(True)
Set doctocheck = nextdoc
deleted = deleted + 1 'Number of documents deleted
totaldeleted = totaldeleted + doctocheck.Size
Else
Set doctocheck = inbox.GetNextDocument( doctocheck )
End If
Wend

'*************************************************'* Check Sent View
'*************************************************
Set sentbox = indb.GetView("($Sent)")

Set doctocheck = sentbox.GetFirstDocument
While Not ( doctocheck Is Nothing )
i = 0
Forall FolderRef In doctocheck.FolderReferences<

This was first published in November 2000

Dig Deeper

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchDataCenter

SearchExchange

SearchContentManagement

Close