Spam Agent

I have a agent that process Spam to the Spam Folder. I would like to add code that says if older than 30 days delete from the Spam Folder.

Can anyone help . Thanks in advance.

-Jeremy

Subject: Spam Agent

If you post your code I can take a look at it.

Subject: RE: Spam Agent

Here it is Steve. Thanks for helping. -Jeremy Sub Initialize

Dim Session As NotesSession

Dim DB As NotesDatabase

Dim ndNotesDoc As notesdocument

Dim docProfile As NotesDocument



Set Session = New NotesSession

Set ndNotesDoc = Session.DocumentContext



If ndNotesDoc Is Nothing Then Exit Sub



Call processDocument(ndNotesDoc)

End Sub

Public Function isSpamFlagged(doc As NotesDocument) As Variant

isSpamFlagged = False



If doc.hasItem("X_RBL_Warning") Then isSpamFlagged = True



If doc.hasItem("$DNSBLSite") Then isSpamFlagged = True



If doc.hasItem("X_Spam_Flag") Then 

	If doc.X_Spam_Flag(0) = "YES" Then 

		isSpamFlagged = True

	End If

End If



intSpamScore = GetSpamScore(doc)



If  intSpamScore >= 5 Then

	isSpamFlagged = True

End If

End Function

Sub ProcessDocument(ndNotesDoc As NotesDocument)

Dim db As NotesDatabase

Dim msg As String

Dim dbug As NotesLog



Set db = ndNotesDoc.parentDatabase



Set dbug = New NotesLog("Router log")

dbug.LogActions = True

dbug.OpenAgentLog

dbug.LogAction("begin")



If isSpamFlagged(ndNotesDoc) Then

	REM Get Mail Preferences with Spam Settings

	REM Move document to folder

	Call ndNotesDoc.PutInFolder("Spam",True)

	Call ndNotesDoc.replaceItemValue("$AutoForward", "1")

	Call ndNotesDoc.RemoveFromFolder( "($Inbox)" )

	Call ndNotesDoc.save(False,False)

End If



dbug.LogAction("Mail preprocessing agent is done")

dbug.Close 

End Sub

Public Function GetSpamScore(ndNotesDoc As NotesDocument) As Integer

strSpamScore = ndNotesDoc.X_Spam_Score(0)



intPos = Instr(1,strSpamScore,".")

strSpamScore = Mid(strSpamScore,1,intPos)



intSpamScore = Cint(strSpamScore)

GetSpamScore = intSpamScore

End Function

Subject: Spam Agent

You could add a Sub that is called at the end of your agent run that does this:

Sub CleanSpamFolder

Dim session As New NotesSession

Dim dbCurr As NotesDatabase

Dim docCurr As NotesDocument

Dim docNext As NotesDocument

Dim viewSpam As NotesView

Dim dateTime As New NotesDateTime( Now() )

Set createdDateTime = New NotesDateTime( "" )



Set dbCurr = session.CurrentDatabase

Set viewSpam = dbCurr.GetView("SPAM")

Set docCurr = viewSpam.GetFirstDocument

Set docNext = viewSpam.GetNextDocument(docCurr)

Call dateTime.AdjustDay(-30)

Do Until docCurr Is Nothing

	createdDateTime.LSLocalTime = docCurr.Created

	If dateTime.TimeDifference( createdDateTime  ) > 0  Then

		docCurr.RemovePermanently(True)

		

	End If

	Set docCurr = docnext

	If Not(docCurr Is Nothing) Then

		Set docNext = viewSpam.GetNextDocument(docCurr)

	End If

Loop

End Sub

Subject: RE: Spam Agent

Steven That worked great. Thank you so much .

Best,

Jeremy