Attachment Remove in LS Agent not working

I have an agent running in my mail box that’s triggerd before new mail arrives.The purpose is detaching all attachments, scanning them with Bitdefender Antivirus and if it contains a virus remove the attachment.

Everything is working, virusses are detected and a field for checking the status is updated with virus found or not.

The only thing that doesn’t work is the removal of the attachment.

There is no script error, it’s just still there when the mail is delivered to the inbox.

This is the script:'Bitdefender:

Option Public

Option Declare

Function ScanAttachment() As Boolean

Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Dim dbug As NotesLog

Dim rtitem As Variant

Dim att As Variant

Dim Virus As Integer 

Dim Item As NotesItem



Set doc = session.documentcontext	

Print "Bitdefender virus scan starting"	



Forall f In Doc.Items

	Select Case f.Type 

	Case 1

		Set rtitem = doc.GetFirstItem( f.name )			

		If Isarray(rtitem.EmbeddedObjects) Then

			Forall o In rtitem.EmbeddedObjects

				If HasVirus(o) Then

					virus = virus + 1

					Call o.Remove

				End If

			End Forall

		End If

		

	Case 1084

		Set att = Doc.GetAttachment(f.values(0)) 

		If HasVirus(att) Then

			virus = virus + 1

			Call att.Remove

		End If

	End Select

	

End Forall



If virus > 0 Then

	Set Item = Doc.ReplaceItemValue("scanned","Bitdefender: virus removed")		

Else

	Set Item = Doc.ReplaceItemValue("scanned","Bitdefender: no virus found")		

End If

Call doc.save(True,True)			

End Function

Sub Initialize

Call ScanAttachment

End Sub

Function HasVirus(o As Variant) As Boolean

'



Const scandir = "/bitdefender/"

Dim cmdline As String

Dim x As Variant 

Dim logfile As String

Dim attname As String



On Error Resume Next

Let attname = scandir & o.name	

Call o.ExtractFile(attname)



Do While Dir$(attname) = ""

	Sleep(2)

Loop



x = Shell("chmod 777 " & attname)



Let logfile = scandir & Replace(o.name,".","_") & ".log"

cmdline = |bash -c "bdc | & attname & | --delete --all --log=|& logfile &|"|

x = Shell( cmdline ,1)

’ read the logfile and store virus info in log db

’ Do While Dir$(logfile) = “”

’ Sleep(2)

’ Loop

If Dir$(attname) = "" Then

	HasVirus = True		

	Print "Bitdefender found a virus in " & attname

Else

	HasVirus = False

End If

End Function

Did i make a mistake somewhere??

Subject: Attachment Remove in LS Agent not working

I can’t see anything wrong, but one thing throws me - why are you using documentcontext to get a back-end handle on the document. It really is intended for Web type acess. In your case, you should have a document collection and loop through it, passing each document as a parameter to this function. That’s about the only strange thing I see.

Subject: RE: Attachment Remove in LS Agent not working

Thanks for your response. A doc collection doesn’t work for agents running before new mail arives.

Documentcontext is what i found in the Agent Faq’s.

Strange thing is that the agent is updating the document with other fields, i have also changed the subject field when a virus is found etc.

The attachment also moved from the rtf field to the document as a V2 attachment…

I think a dirty trick is to copy the virus doc to a quarantine db, and make new message to inform the user.

This is just for fun, a free mail scanner for Domino on Linux, thanks to Bitdefender!

I someone knows how to remove the attachment please let me now.

Thanks in advance.