Several hints have been published, here and elsewhere, detailing various ways of catching spam in rules from within Apple's Mail. Many of these are quite clever, but they (and every other such tip I've seen) all respond to an incoming junk message by simply moving it to the "Junk" folder. While this gets it out of your Inbox, Mail's built-in spam filtering never becomes aware of the message's spammy nature and, therefore, never learns from the experience.
A better (and more consistent) way would be to actually mark these messages as Junk Mail when they arrive. Mail's rules have no "Mark as Junk" option, which is rather silly, but as usual this can be done using the wonders of AppleScript. When Mail executes an AppleScript as the result of a rule action, it looks for a perform mail action with messages handler in the script it's running. If it finds one, it will populate the messages argument with the list of messages matching the rule and the rule argument with the rule that's running the script. Therefore, we can tell Mail to mark all messages matching the rule as junk mail using the following script:
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with eachMessage in theMessages
set junk mail status of eachMessage to true
end repeat
end tell
end perform mail action with messages
end using terms from
Simply save this script into ~/Library -> Scripts -> Mail Scripts (or wherever you'd prefer to keep it; putting it in the Mail Scripts folder just allows you to call the script on a set of selected messages as well), and then add a rule action "Run AppleScript" to the rule from which you wish to invoke it. Select the script, and you're done. From now on, junk mail will be flagged as such whenever it is encountered, and Mail's built-in spam filtering will pay attention.
Mac OS X Hints
http://hints.macworld.com/article.php?story=20040602114525386