Subject: Possible agent to delete a particular email on all mail databases
Hi Won
This will get you started, it is a manual agent to delete e-mails with a particular subject,or user, or sender.
REM Code Name = PurgeMailDocs
REM LS Program Type =Utility
REM Database Name = mail.nsf
REM Date = 6-01-2001
REM Author = Don Russell
REM Rev = A
REM Purpose = Agent to Purge E-Mail Documents
REM This agent should be run manually.
REM You can delete docs that contain the whole string or subset in any of 3 fields in the mail doc
REM Fields are From To and Subject
REM The agent log shows the total number of docs and number of docs deleted after the agent has run
REM The Status Bar shows the current Doc Count # & Subject of the E-mail being analyzed for deletion & ending Totals
On Error Goto GeneralErr ' put at very top before Dimension statements
Dim session As New NotesSession
Dim itm As NotesItem
Dim db As NotesDatabase
Dim doc1,doc2 As NotesDocument
Dim dc As NotesDocumentCollection
Dim itmv As Variant
Dim itms,SubField As String
Dim y As Integer
Dim fieldMstr,FieldChoic As String
Dim results,s1,s2,s3 As String
Dim SDocCntr,SDeldocNo As String
Dim resultv As Variant
Dim resulti As Integer
Dim agentLog As New NotesLog("Agent log")
Call agentLog.OpenAgentLog
FieldChoic = Inputbox$("Type in Field name for purge function. from to subject")
y = Strcomp(FieldChoic, "from", 5)
If(y = 0 ) Then
Goto Cont01
End If
y = Strcomp(FieldChoic, "to", 5)
If(y = 0 ) Then
Goto Cont01
End If
y = Strcomp(FieldChoic, "subject", 5)
If(y = 0 ) Then
Goto Cont01
End If
Print "Field Choice Incorrect - Abort"
Goto TEnd
Cont01:
FieldMstr = Inputbox$("Type in all or portion of " & FieldChoic & " Field purge string")
y = Strcomp(Cstr(FieldMstr), "", 5)
If(y = 0 ) Then
Goto Tend ' Cancel so go to End Of Pgm
End If
Set db = session.CurrentDatabase
Set dc = db.AllDocuments
Set doc1 = dc.GetFirstDocument
Set doc2 = doc1
x=0
DocCntr = 0
DeldocNo = 0
While Not (doc2 Is Nothing)
resultv = 0 ' Initialize
Set doc2 = dc.GetNextDocument(doc1)
Set itm = doc1.GetFirstItem("Subject")
itmv = doc1.GetItemValue("Subject")
itms=Cstr(itmv(0))
SubField=itms
Set itm = doc1.GetFirstItem(FieldChoic) '<< Choose field to analyze here
itmv = doc1.GetItemValue(FieldChoic) '<< Choose field to analyze here
itms = Cstr(itmv(0))
y = Strcomp(itms, "", 5) '<< ck for Blank then skip doc deletion if field is blank
If(y <> 0 ) Then
resultv = Instr(1, itms, FieldMstr,5)
resulti = Cint(resultv)
If(resulti > 0) Then
Call doc1.Remove(True)
Beep
DeldocNo = DeldocNo + 1
SDeldocNo = Cstr(DeldocNo)
End If
End If
Set doc1 = doc2
DocCntr = DocCntr + 1
SDocCntr = Cstr(DocCntr)
Print "Del " + DeldocNo + " of " + SDocCntr + " - " + SubField
Wend
Call agentLog.LogAction( "Del = " + SDeldocNo + " of " + SDocCntr + " Docs. Please run Compact to clean white space.")
Print "Del = " + DeldocNo + " of " + SDocCntr + " Docs. Please run Compact to clean white space."
Goto TEnd
GeneralErr:
'Note: Adding in more info such as the following can prevent any error logging because in this case no documents were read and another error was 'encountered which stopped the agent from running.
Call agentLog.LogAction( "Field Name in current document = " + SubField)
Call agentLog.LogAction( " Error # = " + Str(Err))
Call agentLog.LogAction(" Error String = " + Error$)
Call agentLog.LogAction( " Error Line # = " + Cstr(Erl))
Call agentLog.LogAction(" Report this error to your DB Designer with the following information ")
Call agentLog.LogAction(" Type and Name = Manual --PurgeMailDocs-- ")
Call agentLog.LogAction(" Database Title = " + db.Title)
Call agentLog.LogAction( " Database Filename = " + db.Filename)
Call agentLog.LogAction( " Database Directory Path = " + db.Filepath)
Print "Error - Agent Aborted - Check Agent PurgeMailDocs Log for more Detail"
Resume TEnd
TEnd:
Call AgentLog.Close
Copy code above this line.
End Sub