Sign in to follow this  
Followers 0
ioliver

Is this structure correct?

5 posts in this topic

Can anyone tell me if this is structured correctly?

If StringInStr($line, "x-sender:") And StringInStr($line, "@microsoft.com") Or StringInStr($line, "x-sender:") And StringInStr($line, "@windows.com") Then

Thanks,

Ian

Or, if it's not correct, how can I fix it?


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

Share this post


Link to post
Share on other sites



A suggestion

If StringInStr($line, "x-sender:") Then
    If StringInStr($line, "@microsoft.com") Or StringInStr($line, "@windows.com") Then
    ; Do something.
    EndIf
EndIf

Share this post


Link to post
Share on other sites

Thanks for the reply, but I'm not sure if that will work with my 'ExitLoop()' statement.

Full Code:

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

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:") And StringInStr($line, "@microsoft.com") Or StringInStr($line, "x-sender:") And StringInStr($line, "@windows.com") Then
           ; MsgBox(0, "Search IMF.au3 found an email from XP Systems", $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 & "\SearchIMF-Complete\" & $file)
    EndIf
        
WEnd

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

Thanks,

Ian


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

Share this post


Link to post
Share on other sites

Thanks for the reply, but I'm not sure if that will work with my 'ExitLoop()' statement.

Full Code:

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

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:") And StringInStr($line, "@microsoft.com") Or StringInStr($line, "x-sender:") And StringInStr($line, "@windows.com") Then
          ; MsgBox(0, "Search IMF.au3 found an email from XP Systems", $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 & "\SearchIMF-Complete\" & $file)
    EndIf
        
WEnd

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

Thanks,

Ian

i'd say to throw parentheses around the conditions....

If ( StringInStr($line, "x-sender:") And StringInStr($line, "@microsoft.com")) Or (StringInStr($line, "x-sender:") And StringInStr($line, "@windows.com"))

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

No problem just putting it in. Atleast I see none.

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

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, "@microsoft.com") Or StringInStr($line, "@windows.com") Then
             ; MsgBox(0, "Search IMF.au3 found an email from XP Systems", $file); Uncomment to test script
                $x = 1
                ExitLoop
            Else
                $x = 0
            EndIf
        EndIf
    WEnd
    
    FileClose($EML)
    
    If $x = 1 Then
        FileWriteLine($output, $file)
        FileMove($file, $dir & "\SearchIMF-Complete\" & $file)
    EndIf
        
WEnd

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

Edit: As you can see, I only test StringInStr($line, "x-sender:") once in the loop, where as your original example checks it a second time to reach the same result.

Edited by MHz

Share this post


Link to post
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
Sign in to follow this  
Followers 0