In case you missed it, the version of mail included with 10.2.3 can execute Applescripts as part of a rule. This will open up a lot of possibilities. A member of the Mail.app development team passed along this script that uses the 'perform_mail_action' handler to access messages that match the given rule or rule object. In other words, it kicks up a dialog box that automagically tells you a rule was matched and what the message was that matched.
on perform_mail_action(info)In the example, 'info' is an Applescript record with two keys: |SelectedMessages| and |Rule|. |SelectedMessages| is a list of message objects that match the conditions for the rule. As messages are fetched and evaluated in batches, this list may contain more than one message, so be sure to take that into account. |Rule| is the rule object that triggered the script action.
tell application "Mail"
set selectedMessages to |SelectedMessages| of info
set theRule to |Rule| of info
repeat with eachMessage in selectedMessages
set theSubject to subject of eachMessage
set theRuleName to name of theRule
set theText to "The rule named '" & theRuleName & "' ¬
matched this message:" & return & return & ¬
"Subject: " & theSubject
display dialog theText
end repeat
end tell
end perform_mail_action
Mac OS X Hints
http://hints.macworld.com/article.php?story=20030116071118239