Add Mail Message to Rule

Trying to create a script meant to add selected message(s) to my eMail spam delete rule. Here’s what I have written but I cannot seem to make it work. I believe the idea is good, but I cannot get the script to compile so I am not sure it will work as intended. Any ideas or assistance will be greatly appreciated…

use AppleScript version “2.8 or later”
set theProperties to {}
tell application id “com.apple.mail” – Mail.app
set theMessages to the selection
repeat with i in theMessages
set theSender to sender of currentMessage as string
set oldDelimiters to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to {“@”}
try
set theDomain to the second text item of theSender
set AppleScript’s text item delimiters to “”
if theDomain contains “>” then
set theDomain to leftStringFromRight(theDomain, “>”) of theScript
end if
repeat
if theDomain contains “.” then
set theDomain to leftStringFromRight(theDomain, “.”) of theScript
else
exit repeat
end if
end repeat
end try
tell rule “Delete”
repeat with i in theDomain
rule condition at end of rule conditions with properties {rule type:from header, qualifier:does contain value, expression:i}
end repeat
end tell
end repeat
end tell

Hi
Replace this

with

Other serious error in the script above is that the nested repeat loop variable (variable i) is the same as the containing repeat loop variable (variable i).

OK, I got that fixed.

Now, after adding the domain to the delete rule, I want to move the currently selected message to the junk folder.

I wrote the following lines, in many different ways (with and without quotes, moving to a mailbox and to a folder, etc) but I am unable to get the selected message to move, and most of the iterations won’t even compile.

Here’s one of the versions:

tell application id “com.apple.mail” – Mail.app
set move currentmessage to mailbox “Junk” of account “Lindscape” of application “Mail”
end tell

Sometimes this fails stating that the Lindscape account is not valid, but I have triple checked and that IS the name of my account.

Some guidance is appreciated… Thanx!

  1. Don’t tell to application “Mail” twice
  2. Don’t set the move command. You can set only variables and properties to something, but setting command move to some mailbox is nonsense.

tell application id "com.apple.mail" -- Mail.app
	set movedMessage to move currentmessage to mailbox "Junk" of account "Lindscape"
end tell