Detach agent by subject field

Hi,

I am looking for advice on the script of detach agent. I would like to detach the attachment by a specific subject of mail instead of all the mails. And here is the script for the detach agent for all mails,


Sub Initialize

Dim session As New NotesSession

Dim db As NotesDatabase

Dim object As NotesEmbeddedObject

Dim collection As NotesDocumentCollection

Dim doc As NotesDocument

Dim downloadfolder As String

Set db = session.CurrentDatabase

Set collection = db.UnprocessedDocuments

downloadfolder = “D:\MailAttachment”

Print “*****************************************”

For i = 1 To collection.Count

Set doc = collection.GetNthDocument( i )

filen=Evaluate(“@AttachmentNames”,doc)

antalfiler=Evaluate(“@Attachments”, doc)

UserName=db.FileName

Print Str(i)+" (“+Str(collection.count)+”)"

If antalfiler(0)>0 Then

For filecounter=0 To antalfiler(0)-1

x=x+1

Print ( filen(filecounter))

Set Object = doc.GetAttachment( filen(filecounter) )

If ( object.Type = EMBED_ATTACHMENT ) Then

fileCount = fileCount + 1

If Dir(downloadfolder+“"+ filen(filecounter))=”" Then

extrachar=“”

Else

extrachar=Left(doc.universalid,4)+“—” 'in case attachmnet with same name exists in several documents

End If

Call object.ExtractFile (downloadfolder+""+extrachar+ filen(filecounter) )

End If

Next filecounter

End If

Next

Msgbox"Attachments: "+Str(fileCount )

End Sub


Please advice.

Thanks,

Ryan

Subject: Detach agent by subject field

For i = 1 To collection.CountSet doc = collection.GetNthDocument( i )

'++++++ NEW CODE

If doc.Subject(0) = WHATEVER_SUBJECT_YOU_SPECIFICALLY_WANT then

'++++++END OF NEW CODE

filen=Evaluate(“@AttachmentNames”,doc)

antalfiler=Evaluate(“@Attachments”, doc)

UserName=db.FileName Print Str(i)+" (“+Str(collection.count)+”)" If antalfiler(0)>0 Then

For filecounter=0 To antalfiler(0)-1

x=x+1

Print ( filen(filecounter))

Set Object = doc.GetAttachment( filen(filecounter) )

If ( object.Type = EMBED_ATTACHMENT ) Then fileCount = fileCount + 1 If Dir(downloadfolder+“"+ filen(filecounter))=”" Then

extrachar=“”

Else

extrachar=Left(doc.universalid,4)+“—” 'in case attachmnet with same name exists in several documents

End If

Call object.ExtractFile (downloadfolder+""+extrachar+ filen(filecounter) ) End If

'++++++++++++++NEW CODE

End IF

'++++++++++++++END OF NEW CODE

Next filecounter