Jump to content

Recommended Posts

Posted

I'd like for the 2nd to innermost loop to not run if it finds the word 'x-sender', but I didn't know how to code that. Is that what you mean by exit condition?

Thanks again,

Ian

just incase you didn't see my previous post because you were posting your own, look above your last post...
Posted

try this:

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

$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
    $fc = FileRead($EML, FileGetSize($EML))
    If StringInStr($fc, "@ms.com") Then
        FileWriteLine($ouput, $file)
        FileClose($EML)
        FileMove($file, $dir & "\xp\" & $file)
;### Tidy Error: Level error -> WEnd is closing previous if
    WEnd
;### Tidy Error: Level error -> EndIf is closing previous While
EndIf

FileClose($output)
Looking at this code, it doesn't look like it checks to see if the line contains 'x-sender:' and then check for '@ms.com'. Instead only checks for '@ms.com'. But I need to only search for '@ms.com' in the 'x-sender:' line, becasue I only want email from '@ms.com'.

Am I reading it correctly?

Thanks,

Ian

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

Posted (edited)

Looking at this code, it doesn't look like it checks to see if the line contains 'x-sender:' and then check for '@ms.com'. Instead only checks for '@ms.com'. But I need to only search for '@ms.com' in the 'x-sender:' line, becasue I only want email from '@ms.com'.

Am I reading it correctly?

Thanks,

Ian

yes you are, is it likely that there will be other lines that have @ms.com in other fields? creating false positive conditions?

***edit***

also, forgot to switch two lines...

$output = FileOpen("C:\SearchIMF-Output.txt", 2); Opens for writing
$dir = InputBox("Search IMF for @ms.com", "Full Path to Directory:")
FileChangeDir($dir)
DirCreate($dir & "\xp")
$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
    $fc = FileRead($EML, FileGetSize($EML))
    If StringInStr($fc, "@ms.com") Then
        FileWriteLine($ouput, $file)
        FileClose($EML)
        FileMove($file, $dir & "\xp\" & $file)
    EndIf
WEnd
FileClose($output)
Edited by cameronsdad
Posted

yes you are, is it likely that there will be other lines that have @ms.com in other fields? creating false positive conditions?

Well, now that you mention it, probably not that many. While MS.com may be disussed a lot in company emails, @MS.com, probably isn't. But, if possible, I'd like to get it working where it only searches the 'x-sender:' line for '@ms.com'.

Ian

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

Posted

Well, now that you mention it, probably not that many. While MS.com may be disussed a lot in company emails, @MS.com, probably isn't. But, if possible, I'd like to get it working where it only searches the 'x-sender:' line for '@ms.com'.

Ian

np, one sec i'll re-write...

Posted

np, one sec i'll re-write...

here you go:

$output = FileOpen("C:\SearchIMF-Output.txt", 2); Opens for writing
$dir = InputBox("Search IMF for @ms.com", "Full Path to Directory:")
FileChangeDir($dir)
DirCreate($dir & "\xp")
$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
    $EML = FileOpen($file, 0)
; Check if file opened for reading OK
    If $EML = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf
    
    While 1
        $line = FileReadLine($EML)
        If @error = -1 Then ExitLoop
        If StringInStr($line, "x-sender:") And StringInStr($line, "@ms.com") Then
            FileWriteLine($output, $file)
            FileClose($EML)
            FileMove($file, $dir & "\xp\" & $file)
        EndIf
    WEnd
    
    
WEnd
FileClose($output)
Posted

here you go:

$output = FileOpen("C:\SearchIMF-Output.txt", 2); Opens for writing
$dir = InputBox("Search IMF for @ms.com", "Full Path to Directory:")
FileChangeDir($dir)
DirCreate($dir & "\xp")
$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
    $EML = FileOpen($file, 0)
; Check if file opened for reading OK
    If $EML = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf
    
    While 1
        $line = FileReadLine($EML)
        If @error = -1 Then ExitLoop
        If StringInStr($line, "x-sender:") And StringInStr($line, "@ms.com") Then
            FileWriteLine($output, $file)
            FileClose($EML)
            FileMove($file, $dir & "\xp\" & $file)
        EndIf
    WEnd
    
    
WEnd
FileClose($output)
Thanks.

This time it looks like if it finds the lines, it closes the file. But if it doesn't, then the file doesn't get closed. There are a lot of files to look though, so wouldn't it eventually error out for having to many files open?

Thanks,

Ian

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

Posted

Ok, I've got it.

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

$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
    
   ; 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, "@ms.com") Then
           ; MsgBox(0, "Search IMF.au3 found an email from ms", $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

FileClose($output)

@cameronsdad, thanks for all the help. I don't think I could have figured it out without you.

Ian

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

Posted

Ok, I've got it.

@cameronsdad, thanks for all the help. I don't think I could have figured it out without you.

Ian

no problem, i'm glad i could help. Yeah i was going to say just to move the fileclose outside of the condition, but it looks like you figured it out. as far as having too many files open, yes, on the 65th iteration without a text match, an error would have been generated...

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
×
×
  • Create New...