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
You don't have to make any modifications to the script itself to make it work. Simply save the above text as a compiled script editor and include it with a mail rule to see how it works.
[Editor's note: I have not tested this one other than ensuring that the script syntax is acceptable to the Script Editor.]