Tip

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

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

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:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.