(*
de-junking script. save and run from scripts menu at need.
this script is not designed for accounts with multiple email addresses;
it will use the first email address in the list of addresses
*)
tell application "Mail"
if name of message viewer 1 does not start with "Junk" then return
-- get selected messages
set messList to selected messages of front message viewer
repeat with thisEmail in messList
tell thisEmail
-- reset properties
set junk mail status to false
set background color to green
set theList to address of every recipient
set read status to false
end tell
repeat with thisAddress in theList
-- find originating mailbox and move message there
set theAccount to (every account whose email addresses ¬
contains thisAddress and enabled is true)
if theAccount is not {} then
move thisEmail to mailbox "INBOX" of (item 1 of theAccount)
exit repeat
end if
end repeat
end repeat
end tell
-- reset message viewer away from Junk mailbox to something more reasonable
tell application "System Events" to tell process "Mail" to tell window 1 ¬
to tell splitter group 1 to tell scroll area 1 to tell outline 1
set theRow to item 1 of (every row whose value of text field 1 is "unread")
select theRow
end tell