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??