Manage Learn to apply best practices and optimize your operations.

Striping files from email

Strip out specific attachments

Here's a tip that shows how to strip out specific attachments:

Set the agent as run "Before new mail arrives"

This is good for keeping none business related file attachments and virus from the mail box.

Dim db As NotesDatabase
Dim doc As NotesDocument
Dim attach As NotesEmbeddedObject
Dim filename As String
Dim extensions List As String, filenames List As String
Dim body As Variant
Dim Checker As Variant

Const filelocation = "d:StripFiles"
Const logdbfile = "misMailStripperLog.nsf"

Sub Initialize
	'This is the list of extensions we are checking for
	extensions("vbs") = "VBS attachments"
	extensions("vbe") = "VBE attachments"
	extensions("pif") = "Program Interface Files"
	extensions("scr") = "Screen Saver Files"
	extensions("exe") = "Executables"
	extensions("avi") = "Video"
	extensions("mpg") = "Movies"
	extensions("mpeg") = "Movies"
	extensions("mp3") = "MP3 music"
	'This is the list of filenames we are checking for
	filenames("mybabypic.exe") = "VB Worm"
	filenames("nakedwife.exe") = "VB Worm"
	Dim session As New NotesSession
	Set db = session.CurrentDatabase
	Set doc = session.DocumentContext
	Dim emphasize As NotesRichTextStyle
	Set emphasize = session.CreateRichTextStyle
	emphasize.Bold = True
	emphasize.NotesColor = COLOR_RED
	Dim FileExtension As String	
	Dim LogEntries As String
	LogEntries = doc.UniversalID
	Checker = False
	Forall o In doc.Items
		If (o.Type = ATTACHMENT) Then
			Set attach = doc.GetAttachment(o.Values(0))
			'Read the file name in lower case
			filename = Lcase(attach.Source)
			'Determine the final file extension
			FileExtension = Right$(filename, Len(filename)-Instr(1,filename,"."))
			Do Until (Instr(1,FileExtension,".")=0)
				FileExtension = Right$(FileExtension, Len(FileExtension)-Instr(1,FileExtension,"."))	
			'Does attachment fix the stripping requirement
			If (Iselement(extensions(FileExtension)) = True)  Or (Iselement(filenames(Lcase(filename)))) Then				
				Checker = True
				'Strip Attachment with email's unid
				Call attach.ExtractFile( Trim(filelocation) & Trim(doc.UniversalID) & Trim(filename))
				Call attach.Remove
				'Append message
				Set body = doc.GetFirstItem("Body")
				Call body.AddNewLine(1)
				Call body.AppendStyle(emphasize)
				Call body.AppendText("The following file has been stripped out of this email by a virus checking procedure: " & filename)
				LogEntries = LogEntries + ":" + Trim(filename & " stripped from " & db.Title)
			End If			
		End If		
	End Forall
	If checker Then
		'Append final message to email
		Call body.AddNewLine(1)
		Call body.AppendText("For assistance, please call MIS Admin Help Desk at ext. 4111 (M-F, 6am - 6pm)")
		Call doc.Save(True, False)
		Dim agentlog As New NotesLog("Mail Stripper Log")
		'Open log entries if one have not been open
		Call agentlog.OpenNotesLog("", logdbfile)
		'Recording to Mail Stripper Log
		Call agentlog.LogAction(LogEntries)
		'Close log		
		Call agentlog.Close						
	End If	
End Sub

Dig Deeper on Lotus Notes Domino Administration Tools

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...