Wednesday, June 09, 2004

Post IMF Archiving Event Sink

Once the IMF has achieved a message this is pretty final in regards to the delivery of this message, but it doesn't have to be so what you can do is create a WMI consumer on the archive directory so every time a message gets archived it will then trigger an event.  After this you can then open the new mail that was just archived using CDO have a look at who it was going to or do further inspection on the content and if you think that this message should have been delivered move it back into the pickup directory and have it delivered. The logic and things you can do with this is up to your own imagination one simple example is if you have an account that you want to allow all mail though no matter what this script will check the x-receiver field if the mail is going to that user it will then move the email into the pickup directory. You can set this up as a permanent consumer using a Mof file or my preference is to use Srvany and create a service that this script runs as.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE " _
& "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
& "TargetInstance.GroupComponent= " _
& "'Win32_Directory.Name=""c:\\\\program files\\\\exchsrvr\\\\mailroot\\\\vsi 1\\\\ucearchive""'")
Set objLatestEvent = colMonitoredEvents.NextEvent
set msgobj = createobject("CDO.Message")
fname = objLatestEvent.TargetInstance.PartComponent
set stm = createobject("ADODB.Stream")
fname = replace(fname,"\\","\")
fname = right(fname,len(fname) - instr(fname,chr(34)))
fname = replace(fname,chr(34),"")
stm.loadfromfile fname
msgobj.datasource.openobject stm, "_Stream"
wscript.echo msgobj.fields("urn:schemas:mailheader:x-receiver")
if msgobj.fields("urn:schemas:mailheader:x-receiver") = "" then
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.movefile fname, replace(fname,"ucearchive","pickup")
Wscript.echo fname
end if
set msgobj = nothing
set stm = nothing

No comments: