title: Apple script: Change flag for message which match criteria
body: <p>Ok, i'm creating script that should read my incoming Mail for me. 
  And i stuck with one thing:
  how to change flag for messages that match my criteria, cause I'm check unread message in loop, and if currently checked message match it should be flagged. It's easy to do with selected message but how to flag message in loop?</p>
  
  <p>Please see my attempt:</p>
  
  <pre><code>if (thisSubject contains projectName or thisSubject contains projectName1 or thisSubject contains projectName2 or thisSubject contains projectName3) then
          --mark required messages with red flag
          tell application "Mail"
              #set currentMail to thisMail
              set currentMail to selection
              repeat with s in currentMail
                  set flag index of s to 1 as integer
              end repeat
  
          end tell
  </code></pre>
  
  <p>Updated:
  Here is loop that should mark all matched mails with flag</p>
  
  <pre><code>repeat with thisMail from 1 to count of theSubjects
  set thisSubject to item thisMail of theSubjects
  if (thisSubject contains searchWord or thisSubject contains searchWord2) then
      if (thisSubject contains projectName or thisSubject contains projectName1 or thisSubject contains projectName2 or thisSubject contains projectName3) then
          --mark required messages with flag  
          tell application "Mail"
              #   set allMessage to selection
              repeat with MyMessage in thisMail
                  #   set read status of thisMail to true -- set read
                  set flagged status of MyMessage to true -- display flag / false hide flag
                  set flag index of MyMessage to 1 -- set first color for the flag (-1 remove the flag)
              end repeat
          end tell
      end if
  end if  
  </code></pre>
  
  <p>end repeat</p>