|
jmatos -> RE: New OutputFilter.vbs (6.Jun.2006 1:59:57 AM)
|
Hello, Here is a new version. More code cleanup and a proper inline logo. <SCRIPT language="VBScript"> ' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, ' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED ' WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. ' ' ' ************************************************************************** ' ' DESCRIPTION: ' This script is a CDOSYS OnArrival Transport Event Sink, which removes ' classified information from mail headers and adds a company disclaimer, ' AD information, company logo and attachments. ' ' COPYRIGHT: ' Copyright (c) Joćo Matos [joao.matos(at)inet.com.pt]. ' All rights reserved. ' ' CREDITS: ' http://support.microsoft.com/kb/317680 ' http://www.vamsoft.com/orf/howto-readreceipt.asp ' and many others which I cant't remember... ' ' ************************************************************************** Const CDO_RUN_NEXT_SINK = 0 Const CDO_REF_TYPE_ID = 0 Const DUMMY_TEXT = "***" Const DOMAIN = "MYDOMAIN.COM" Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus) ' Don't do nothing to internal messages (eg. DSNs - Delivery Status Notifications) If InStr(Msg.Fields("urn:schemas:mailheader:from"), "postmaster@" & LCase(DOMAIN)) = 0 Then ' Filter headers Msg.Fields("urn:schemas:mailheader:message-id") = Left(Msg.Fields("urn:schemas:mailheader:message-id"), _ InStr(Msg.Fields("urn:schemas:mailheader:message-id"), "@")) & DUMMY_TEXT & ">" Msg.Fields("urn:schemas:mailheader:received") = Left(Msg.Fields("urn:schemas:mailheader:received"), _ InStr(Msg.Fields("urn:schemas:mailheader:received"), "[")) & DUMMY_TEXT & _ Right(Msg.Fields("urn:schemas:mailheader:received"), _ Len(Msg.Fields("urn:schemas:mailheader:received")) - InStr(Msg.Fields("urn:schemas:mailheader:received"), "]") + 1) Msg.Fields("urn:schemas:mailheader:received") = Left(Msg.Fields("urn:schemas:mailheader:received"), _ InStr(Msg.Fields("urn:schemas:mailheader:received"), " with ") + 5) & DUMMY_TEXT & _ Right(Msg.Fields("urn:schemas:mailheader:received"), _ Len(Msg.Fields("urn:schemas:mailheader:received")) - InStr(Msg.Fields("urn:schemas:mailheader:received"), ";") + 1) Msg.Fields("urn:schemas:mailheader:x-mailer") = DUMMY_TEXT Msg.Fields.Delete("urn:schemas:mailheader:x-mimectl") Msg.Fields.Delete("urn:schemas:mailheader:x-ms-tnef-correlator") Msg.Fields.Delete("urn:schemas:mailheader:x-ms-has-attach") Msg.Fields.Delete("urn:schemas:mailheader:thread-index") Msg.Fields.Delete("urn:schemas:mailheader:thread-topic") Msg.Fields.Delete("urn:schemas:mailheader:x-mime-autoconverted") ' Update mail header Msg.Fields.Update ' Extract e-mail address strEmailAddr = Mid(Msg.Fields("urn:schemas:mailheader:from"), _ InStr(Msg.Fields("urn:schemas:mailheader:from"), "<") + 1, _ Len(Msg.Fields("urn:schemas:mailheader:from")) - _ InStr(Msg.Fields("urn:schemas:mailheader:from"), "<") - 1) ' Extract e-mail domain strEmailDomain = Right(strEmailAddr, Len(strEmailAddr) - InStr(strEmailAddr, "@")) ' Only add disclaimer to DOMAIN If UCase(strEmailDomain) = DOMAIN Then strTextDisclaimer = "" strHTMLDisclaimer = "" ' Determine DNS domain name from RootDSE object Set objRootDSE = GetObject("LDAP://RootDSE") strDNSDomain = objRootDSE.Get("defaultNamingContext") ' Use ADO to search Active Directory Set objConnection = CreateObject("ADODB.Connection") objConnection.Provider = "ADsDSOObject" 'objConnection.Properties("User ID") = "domain\username" 'objConnection.Properties("Password") = "password" objConnection.Open "Active Directory Provider" ' Search for e-mail address strBase = "<LDAP://" & strDNSDomain & ">" strFilter = "(mail=" & strEmailAddr & ")" ' Attributes to select strAttributes = "name,title,mobile,telephonenumber,facsimiletelephonenumber" strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree" Set objRecordSet = objConnection.Execute(strQuery) ' Start HTML disclaimer strHTMLDisclaimer = "Best regards,<BR><BR>" & _ objRecordSet.Fields("name") & "<BR>" & _ objRecordSet.Fields("title") & "<BR><BR>" ' Start text disclaimer strTextDisclaimer = "Best regards," & vbCrLf & vbCrLf & _ objRecordSet.Fields("name") & vbCrLf & _ objRecordSet.Fields("title") & vbCrLf & vbCrLf ' Only add the mobile if it exists If objRecordSet.Fields("mobile") <> "" Then strHTMLDisclaimer = strHTMLDisclaimer & _ "Cellphone: " & objRecordSet.Fields("mobile") & "<BR>" strTextDisclaimer = strTextDisclaimer & _ "Cellphone: " & objRecordSet.Fields("mobile") & vbCrLf End If ' Add multi-valued variable, don't forget to add the field to the strAttributes above 'arrTelephoneOthers = objRecordSet.Fields("othertelephone") 'For Each strTelephoneOther In arrTelephoneOthers ' strHTMLDisclaimer = strHTMLDisclaimer & "Tel.: " & strTelephoneOther & " / " & "Fax: " & _ ' objRecordSet.Fields("facsimiletelephonenumber") & "<BR>" ' strTextDisclaimer = strTextDisclaimer & "Tel.: " & strTelephoneOther & " / " & "Fax: " & _ ' objRecordSet.Fields("facsimiletelephonenumber") & vbCrLf ' Uncomment the next line if you only want the first of the group ' Exit For 'Next strHTMLDisclaimer = strHTMLDisclaimer & _ "Tel.: " & objRecordSet.Fields("telephonenumber") & "<BR>" & _ "Fax: " & objRecordSet.Fields("facsimiletelephonenumber") & "<P><IMG SRC=""logo.gif""></P>" strTextDisclaimer = strTextDisclaimer & _ "Tel.: " & objRecordSet.Fields("telephonenumber") & vbCrLf & _ "Fax: " & objRecordSet.Fields("facsimiletelephonenumber") & vbCrLf & vbCrLf ' Clean up objConnection.Close Set objRootDSE = Nothing Set objConnection = Nothing Set objRecordSet = Nothing strTextDisclaimer = strTextDisclaimer & "blabla" strHTMLDisclaimer = strHTMLDisclaimer & "blabla" ' Add text disclaimer to message If Msg.TextBody <> "" Then Msg.TextBody = Msg.TextBody & vbCrLf & strTextDisclaimer & vbCrLf End If ' Add HTML disclaimer to message If Msg.HTMLBody <> "" Then 'Search for the "</body>" tag and insert disclaimer before that tag iTagPos = InStr(1, Msg.HTMLBody, "</body>", vbTextCompare) strLeftPart = Left(Msg.HTMLBody, iTagPos - 1) strRightPart = Right(Msg.HTMLBody, Len(Msg.HTMLBody) - (iTagPos - 1)) Msg.HTMLBody = strLeftPart & strHTMLDisclaimer & strRightPart ' Add a company logo Msg.AddRelatedBodyPart "C:\scripts\logo.gif", "logo.gif", CDO_REF_TYPE_ID End If ' Add an attachment 'Msg.AddAttachment("c:\scripts\privacy.txt") End If ' Save changes Msg.Datasource.Save End If ' Continue with the next event sink EventStatus = CDO_RUN_NEXT_SINK End Sub </SCRIPT>
|
|
|
|