title: Getting at a Message from a Mail Rule in Applescript
body: <p>As an excuse to learn Applescipt, I writing a script to be attached to a Mail rule to filter messages. I scrounged around and put together this much code:</p>
  
  <pre><code>on perform_mail_action(theData)
      tell application "Mail"
          set theSelectedMessages to |SelectedMessages| of theData
          set theRule to |Rule| of theData
          repeat with a from 1 to count theSelectedMessages
              set theMessages to selection
              set theMessage to item 1 of theMessages
          end repeat
      end tell
  end perform_mail_action
  </code></pre>
  
  <p>I would have thought the rule would only pass one message, but you never know so the repeat makes sense. I presume "selection" is a pointer to an item in theSelectedMessages. What seems strange is "set theMessage to item 1 of theMessages". I would have thought you would code "set theMessage to selection". I want to get to the body, "content" of the message to test for certain words.</p>
  
  <p>Thanks for any help,
  Curt</p>