0

I wrote an AppleScript that moves selected emails to the Trash. The script works fine in that regard. The problem is that the emails remain on the server. Is there additional code I need to add to get it to do that? Here's the code:

using terms from application "Mail"
on perform mail action with messages these_messages for rule this_rule
    tell application "Mail"
        set the message_count to the count of these_messages
        repeat with i from message_count to 1 by -1
            set this_message to item i of these_messages
            set this_content to (every character of content of this_message) as Unicode text
            if "bowles" is not in this_content and "patton" is not in this_content then
                set theAccount to account of mailbox of this_message
                set mailbox of this_message to mailbox "Trash" of theAccount
            end if
        end repeat
    end tell
end perform mail action with messages
end using terms from
curt
  • 4,422
  • 3
  • 42
  • 61
  • Are you using pop, imap, exchange? – adayzdone Mar 07 '12 at 02:55
  • It's a POP server: goDaddy. I have a rule that deletes other emails. It had no problem leaving items on the server. – curt Mar 07 '12 at 07:22
  • I tried commenting out various parts of the code. It's the second line of code above that causes the problem. I even moved it to a second script that was executed by another rule. The emails remained on the server. – curt Mar 12 '12 at 16:29
  • I devised a workaround. In the Applescript run by the first rule, I set the selected messages to junk mail. I then added a second rule that moved all messages set to junk mail to the trash. The problem is that the mail app sets some messages to junk mail that aren't. – curt Mar 12 '12 at 16:54
  • It would still be nice to get the script to work cleanly. – curt Mar 12 '12 at 16:54
  • Would you mind posting the entire script? – adayzdone Mar 12 '12 at 18:01

2 Answers2

0

Sadly the answer appears to be to create a separate rule for email source. In the end, I just unsubscribed from the mailing lists as I hadn't seen any useful information from them in years.

curt
  • 4,422
  • 3
  • 42
  • 61
0

It is hard to troubleshoot without seeing the entire script and the other rules that may be causing a problem. Try adding the Stop evaluating rules action to your rule :

enter image description here

using terms from application "Mail"
on perform mail action with messages these_messages for rule this_rule
    tell application "Mail"
        repeat with this_message in these_messages
            set this_content to content of this_message
            if "bowles" is not in this_content and "patton" is not in this_content then
                set theAccount to account of mailbox of this_message
                set junk mail status of this_message to false
                set mailbox of this_message to mailbox "Trash" of theAccount
            end if
        end repeat
    end tell
end perform mail action with messages
end using terms from
adayzdone
  • 11,120
  • 2
  • 20
  • 37
  • All other emails are being deleted from the server so I don't see those first two commands being of any help. It seems as though the message has to make it to the inbox before it's deleted from the server. – curt Mar 12 '12 at 16:42
  • A single rule wouldn't work. The entire filter is (A or B or C or D) and (not E or not F). The first part is in the rule that invokes the script. Rules have to be all ands or all ors from what I can tell. I could break in down into four separate rules, but I may have filters that are even more complex and I wanted to learn AppleScript. As I mention in the comments of my first post, I did come up with a workaround. – curt Mar 13 '12 at 23:23