Jump to content

If you use IMF with Exchange


ioliver
 Share

Recommended Posts

Here's a script to look through the messages that IMF blocks, and search for a specific email address in the x-sender line, in this case it looks for the address '@ms.com'.

It will need to be modified for your use, but it works well. Thanks to cameronsdad for helping me with this.

Here's the code:

$dir = InputBox("Search IMF for @ms.com.com", "Full Path to Directory:")
FileChangeDir($dir)
DirCreate($dir & "\xp")
$output = FileOpen($dir & "\xp\SearchIMF.txt", 2); Opens for writing

SplashTextOn("Search IMF is looking for messages from @ms.com", "Searching file: ", 350, 20, "", "", 22, "", "10")

$search = FileFindFirstFile("*.EML")
; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $x = 0
    $file = FileFindNextFile($search) 
    If @error Then ExitLoop
   ; MsgBox(4096, "File:", $file); Uncomment to test script 
    
    $EML = FileOpen($file, 0)
   ; Check if file opened for reading OK
    If $EML = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf
    
    ControlSetText("Search IMF is looking for messages from @ms.com", "", "Static1", "Searching File: " & $file)
    
   ; Read in lines of text until the EOF is reached, or until "x-sender:" is found
    While 1
        $line = FileReadLine($EML)
        If @error = -1 Then ExitLoop
       ; MsgBox(0, "Line read:", $line); Uncomment to test script
        If StringInStr($line, "x-sender:") And StringInStr($line, "@xpsystems.com") Then
           ; MsgBox(0, "Search IMF.au3 found an email from @ms.com", $file); Uncomment to test script
            $x = 1
            ExitLoop
        Else
            $x = 0
        EndIf           
    WEnd
    
    FileClose($EML)
    
    If $x = 1 Then
        FileWriteLine($output, $file)
        FileMove($file, $dir & "\xp\" & $file)
    EndIf
        
WEnd

SplashOff()
FileClose($output)

Thanks for reading. Please let me know if there are any comments or questions.

Ian

"Blessed be the name of the Lord" - Job 1:21Check out Search IMF

Link to comment
Share on other sites

Here's an updated version, that will write the File Name, Sender's Address, and Receiver's Address to the log file. This version looks for specific email address in the 'x-sender:' field, so that you can schedule this to run:

; Looks though the JunkEmailArchive folder for messages from @xp.com,
; or @ms.com and moves messages found to the Pickup folder.

; For this script to work:
; Z: must be mapped to \\EXCHANGESERVER\d$
; P: must be mapped to \\EXCHANGESERVER\pickup

$dir = "Z:\JunkEmailArchive"
FileChangeDir($dir)
DirCreate($dir & "\SearchIMF-Complete")
$output = FileOpen($dir & "\SearchIMF-Complete\SearchIMF.txt", 1); Opens for writing in Append mode
$Date = @YEAR & @MON & @MDAY
$Time = @HOUR & ":" & @MIN
FileWriteLine($output, $Date & " " & $Time)

SplashTextOn("Search IMF is working...", "Searching file: ", 350, 20, "", "", 22, "", "10")

$search = FileFindFirstFile("*.EML")
; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $x = 0
    $file = FileFindNextFile($search) 
    If @error Then ExitLoop
   ; MsgBox(4096, "File:", $file); Uncomment to test script 
    
    $EML = FileOpen($file, 0)
   ; Check if file opened for reading OK
    If $EML = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf
    
    ControlSetText("Search IMF is working...", "", "Static1", "Searching File: " & $file)
    
   ; Read in lines of text until the EOF is reached, or until "x-sender:" is found
    While 1
        $line = FileReadLine($EML)
        If @error = -1 Then ExitLoop
       ; MsgBox(0, "Line read:", $line); Uncomment to test script
        If StringInStr($line, "x-sender:") Then
            If StringInStr($line, "@xp.com") Or StringInStr($line, "@ms.com") Then
               ; MsgBox(0, "Search IMF.au3 found an email from XP or MS", $file); Uncomment to test script
                $Sender = StringTrimLeft($line, 10)
                
               ; -> Gets the Receiver's address
                Do
                    $line = FileReadLine($EML)
                    If @error = -1 Then ExitLoop
                    If StringInStr($line, "x-receiver:") Then
                        $Receiver = StringTrimLeft($line, 12)
                       ; MsgBox(0, "Search IMF.au3 (Testing)", "X-Receiver: " & $Receiver); Uncomment to test script
                    EndIf
                Until $Receiver <> ""
               ; <- 
                
                $x = 1
                ExitLoop
            Else
                $x = 0
            EndIf
        EndIf           
    WEnd
    
    FileClose($EML)
    
   ; -> Writes to the log file, and moves the .EML file
    If $x = 1 Then
        FileWriteLine($output, $file & ", " & $Sender & ", " & $Receiver & " -> Moved to Picup")
        FileMove($file, $dir & "\SearchIMF-Complete\" & $file)
    EndIf
   ; <-
        
WEnd

SplashOff()
FileWriteLine($output, "")
FileClose($output)

Thanks for reading,

Ian

"Blessed be the name of the Lord" - Job 1:21Check out Search IMF

Link to comment
Share on other sites

What is IMF?

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Here's a script to look through the messages that IMF blocks, and search for a specific email address in the x-sender line, in this case it looks for the address '@ms.com'.

It will need to be modified for your use, but it works well. Thanks to cameronsdad for helping me with this.

glad i could help!
Link to comment
Share on other sites

i belive it's inbound mail filtering or something to that effect...

That's correct it Microsoft's free -which means difficult to use, and doesn't contain good reporting features- SPAM filter.

Ian

"Blessed be the name of the Lord" - Job 1:21Check out Search IMF

Link to comment
Share on other sites

What, you mean only Microsoft's free products are difficult to use and don't contain good reporting features?! :P:(:lmao:

the argument could be made that microsoft doesn't make free products, just buggy add-ons that they don't charge you for, which attempt to supplement some of the functionality lacking in their programs you've already wasted money on.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...