Striping files from email

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

This was first published in June 2001

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.