Spam Filtering Agent work from Notes client but not working for iNotes users

Hello,

I hope you all can see what I missed from attached LS for Spam filtering.

I have this agent to filter spam since new released Notes version 6.03. It was working great from Notes users and apparently when user already logged on Notes Client once, the agent never fails. But if it is new Notes account and user never access to open Notes mail client this agent fails with the message found from the log

“Can’t find mail db” from the LS below:

I have the feeling that if the user never open the Notes mail client this agent never works.

My question is: should I create another agent to open the users’ mail file and close in Notes before this agent triggered? and is that something do-able?

Everyday I have at least 50 to 100 mail request to trigger this agent but only the mailfile which already access through Notes the profile changed, iNotes user mail file is unchanged.

Thanks alot for all of your advises.

Myle

===============================================

Option Public

Option Declare

Sub Initialize()

'-----------------------------SET THESE CONSTANTS AS REQUIRED---------------------

Const SERVERNAME="AUMAIL4/AmericanU" 

Const AUDBNAME="iNotesRequest.nsf" 

Const SPAMVIEW="SPAM" 

Const MAILFILEFIELD="MailFile" 

Const USERNAMEFIELD="UserName" 

Const FINISHED="Processed" 

Const FAULT="notProcessed" 

'------------------------------------------------------------------------------------------------------------

Dim ss As New notessession 

Dim AUdb As notesdatabase 

Dim maildb As notesdatabase 

Dim AUview As notesview 

Dim audoc As notesdocument 

Dim userdoc As notesdocument 

Dim tmpdoc As notesdocument 

Dim docProfile As notesdocument 

Dim mailname As String 

Dim sStatus As String, user As String 

Dim saveprofile As Integer 

Dim cnt As Integer 



On Error Goto lerr 



cnt=0 

Msgbox "Starting"

Set AUdb=ss.GetDatabase(SERVERNAME,AUDBNAME,False) 

If AUdb Is Nothing Then Error 4712, "Can't find db "+AUDBNAME 

Set AUview=AUdb.getview(SPAMVIEW) 

If AUview Is Nothing Then Error 4712,"View "+SPAMVIEW+" not found" 

'scan view backwards as we are removing the docs from the view by changing the status

Set audoc=AUview.GetLastDocument() 

While Not audoc Is Nothing 

	sStatus=FAULT 'preset status

'get user name

	user=audoc.GetItemValue(USERNAMEFIELD)(0) 

'get user mailfile

	mailname=audoc.getitemvalue(MAILFILEFIELD)(0) 

	Set maildb=ss.GetDatabase(SERVERNAME,mailname,False) 

	If maildb Is Nothing Then 

		Msgbox "Can't find mail db " + mailname 

	Else 

'get profile doc

		Set docProfile = maildb.GetProfileDocument("CalendarProfile") 

		If docProfile Is Nothing Then 

			Msgbox "user profile not found: " + maildb.Title 

		Else 

'rest of document logic as previously

			If setField (docProfile, AUDoc, "SpamAction", user) _ 

			Or setField (docProfile, AUDoc, "SpamFolder", user) _ 

			Or setField (docProfile, AUDoc, "SpamWhiteList", user) Then  'at least one field changed, save doc  

				Call docProfile.save(True,False) 

			End If

			sStatus=FINISHED 'status OK

		End If 

	End If

'goto next doc

	Set tmpdoc=audoc 

	Set audoc=AUview.getprevdocument(audoc) 

'stamp doc as processed

	Call tmpdoc.replaceitemvalue("Status",sStatus) 

	Call tmpdoc.save(True,False) 

	cnt=cnt+1 

Wend 



Msgbox "END: Processed" & cnt & "documents" 

Exit Sub 

lerr:

Msgbox "Error: " & Error$ & " Line: " & Erl 

Msgbox "ABORTING: Processed" & cnt & "documents" 

Exit Sub 

End SubFunction setField(docProfile As notesdocument, AUDoc As notesdocument, fieldname As String, user As String) As Integer

Dim pv As String, av As String 



setField=False 

If docProfile.HasItem(fieldName) Then 

	pv=docProfile.getitemvalue(fieldName)(0) 

	av=AUdoc.getitemvalue(fieldName)(0) 

	If pv <> "" Then 

		Msgbox fieldName +" set to (" + av + ") for user "+user 

	Else 

		Msgbox "Field "+fieldName+" contains " + pv + " for user " +user 

	End If 

	Call docProfile.replaceitemvalue(fieldName, av) 

	setField=True 'show field was updated 

End If 

End Function