VIEW MEMBER FEEDACK TO THIS TIP
If you have several mail.boxes on your server and want your administrator to be able to occasionally run a manual agent to delete all dead messages, this agent will work for you. This agent prints the number of deleted messages to the status bar for each mail.box and then prompts the user with the total deletions from all. Just put this agent in it's own database on the server and manually run it.
Code: Sub Initialize
Dim nsSession As New NotesSession
Dim ndbDb As NotesDatabase
Dim ndcMessages As notesdocumentcollection
Dim ndocFirstDoc As notesdocument
Dim ndocNextDoc As notesdocument
Dim ws As New NotesUIWorkspace
Dim iCollCount As Integer
finalcount=0
'For all mail.boxes, find all dead messages
and delete them. We have
3 mail.boxes, so replace 3 with the number you have.
For i=1 To 3
iCollCount = 0
'Get handle to mail.box
filename = "mail"+i + ".box"
Set ndbDb= nsSession.GetDatabase
("serverNameHere", filename)
If ndbDb.IsOpen Then
'Search string
Const messages=
|@Contains(RoutingState; "DEAD")|
'Set document collection
Set ndcMessages =
ndbDb.search( messages, Nothing, 0 )
'Grab # of docs to be deleted
iCollCount = ndcMessages.count
'Delete all documents in the collection, because they
are dead messages
ndcMessages.RemoveAll(True)
'Print the number of deleted
messages to the status bar
Print Cstr(iCollCount)+ " dead messages deleted
from "+filename
End If
finalcount = finalcount+iCollCount
Next
p = ws.Prompt(PROMPT_OK,
"Complete", Cstr(finalcount)+" dead messages
have been deleted.") End Sub
MEMBER FEEDBACK TO THIS TIP
For this tip to work, you must change this line
Const messages= |@Contains(RoutingState; "DEAD")|
to
Const messages= |@Begins(RoutingState; "DEAD")|
You have to do this because all messages have the string "DEAD" (UNDEAD or DEAD)
Kleber C.
******************************************
I have modified this script, adding two lines to remove email messages with "ERROR" and "User" (for name_user (name_user@domain.com)) not listed in the public Name and Personal Address Book error:
Sub Initialize
Dim nsSession As New NotesSession
Dim ndbDb As NotesDatabase
Dim ndcMessages As notesdocumentcollection
Dim ndocFirstDoc As notesdocument
Dim ndocNextDoc As notesdocument
Dim ws As New NotesUIWorkspace
Dim iCollCount As Integer
finalcount=0
'For all mail.boxes, find all dead messages and delete them.
We have 3 mail.boxes, so replace 3 with the number you have.
For i=1 To 2
iCollCount = 0
'Get handle to mail.box
filename = "mail"+i + ".box"
Set ndbDb= nsSession.GetDatabase
("ServerNameHere", filename)
If ndbDb.IsOpen Then
'Search string
Const messages= |@Begins(RoutingState; "DEAD")|
Const messages2= |@Begins(FailureReason; "User")|
Const messages3= |@Begins(FailureReason; "Error")|
'Set document collection
Set ndcMessages = ndbDb.search
( messages, Nothing, 0 )
Set ndcMessages2 = ndbDb.search
( messages2, Nothing, 0 )
Set ndcMessages3 = ndbDb.search
( messages3, Nothing, 0 )
'Grab # of docs to be deleted
iCollCount = ndcMessages.count+
ndcMessages2.count+ndcMessages3.count
'Delete all documents in the collection, because
they are dead messages
ndcMessages.RemoveAll(True)
ndcMessages2.RemoveAll(True)
ndcMessages3.RemoveAll(True)
'Print the number of deleted messages to the status bar
Print Cstr(iCollCount)+ "
dead messages deleted from "
+filename
End If
finalcount = finalcount+iCollCount
Next
p = ws.Prompt(PROMPT_OK, "Complete",
Cstr(finalcount)+" dead messages have been deleted.")
End Sub
Andre A.
Do you have comments on this tip? Let us know.
This tip was submitted to the SearchDomino.com tip exchange by member Brittany Lazarski. Please let others know how useful it is via the rating scale below. Do you have a useful Notes/Domino tip or code to share? Submit it to our monthly tip contest and you could win a prize and a spot in our Hall of Fame.