Skip navigation

Mail Rule Not Working -- 10.8 issue?

2521 Views 10 Replies Latest reply: Oct 24, 2013 4:04 PM by Tony T1 RSS
William Hainline Calculating status...
Currently Being Moderated
Sep 2, 2012 2:51 PM

Question for my fellow AppleScripters. I have the following script which runs just fine if you run it in AppleScript Editor or Script Debugger, but that won't run at all if you try to run it from a Mail rule. The script is correctly placed in ~/Library/Application Scripts/com.apple.mail, and shows up in the "Run AppleScript" menu in the Mail rule, but simply refuses to work when new mail arrives.

on perform_mail_action(info)

  tell application "Mail"

  set themessages to |SelectedMessages| of info

  repeat with thisMessage in themessages

  set AppleScript's text item delimiters to {""}

  set thisSender to sender of thisMessage as string

  set quotepos to offset of "\"" in thisSender

  if (quotepos is not 0) then

  set thisSender to (text items (quotepos + 1) through -1) ¬

  of thisSender as string

  set quotepos to offset of "\"" in thisSender

  if (quotepos is not 0) then

  set thisSender to (text items 1 through (quotepos - 1)) ¬

  of thisSender as string

  end if

  else

  set atpos to offset of "@" in thisSender

  if (atpos is not 0) then

  set thisSender to (text items 1 through (atpos - 1)) ¬

  of thisSender as string

  end if

  set brkpos to offset of "<" in thisSender

  if (brkpos is not 0) then

  set thisSender to (text items (brkpos + 1) through -1) ¬

  of thisSender as string

  end if

  end if

  tell application "Finder" to say "Excuse me sir, but you have a new email from " & thisSender

  end repeat

  end tell

end perform_mail_action


Any ideas?

iMac, OS X Mountain Lion (10.8.1), Running iLife, iWork, FCP X
  • Camelot Level 8 Level 8 (45,670 points)
    Currently Being Moderated
    Sep 2, 2012 3:08 PM (in response to William Hainline)

    I've never seen a Mail rule use this format before:

     

    on perform_mail_action(info)

     

    Indeed, switching it to the 'normal' mode seems to work just fine:

     

    using terms from application "Mail"

              on perform mail action with messages messageList for rule aRule

                        tell application "Mail"

                                  repeat with thisMessage in messageList

    ...

  • Camelot Level 8 Level 8 (45,670 points)
    Currently Being Moderated
    Sep 2, 2012 3:43 PM (in response to William Hainline)

    Thanks!  That does clear things up.  But, are "messageList", "mbox", and "aRule" just any old variables, or are they like the "added_items" in a folder action, i.e., placeholds that Mail.app knows about?

     

    That's a valid question, and the answer is they have no bearing on the original application - they're just AppleScript variables.

     

    Given the line:

     

      on perform mail action with messages messageList in mailboxes mboxfor rule aRule


    the script is invoked when a mail rule triggers a script and it passes in three pieces of data - the list of messages, the mailbox the messages came into, and the rule that triggered the script.

    In this example, that data is put into three separate variables, namely messageList, mbox and aRule.

     

    Those variable names are purely arbitrary and at the whim of the script author. They might as well be called Larry, Moe and Curly for what difference it makes, although using descriptive names makes it easier to keep track of, of course.

  • Camelot Level 8 Level 8 (45,670 points)
    Currently Being Moderated
    Sep 2, 2012 10:19 PM (in response to William Hainline)

    This is an oddity, and I'm not sure I can explain it well, but changing the line:

     

      set sender_name to extract name from sender of messagethis_message

     

    to:

     

                        set sender_name to extract name from (get sender of this_message)


    fixes the problem.

  • Niko Nyman Level 2 Level 2 (270 points)
    Currently Being Moderated
    Sep 7, 2012 2:47 PM (in response to William Hainline)

    Are you getting mail from a POP or an IMAP account? Seems like Applescript Mail rules on POP accounts are not working under 10.8.

  • Tony T1 Level 6 Level 6 (8,125 points)
    Currently Being Moderated
    Sep 9, 2012 8:58 AM (in response to William Hainline)

    I may have a workaround until (if) Apple fixes this bug.

    See: https://discussions.apple.com/message/19514671

     

    You will need to add a line to your code to move the messages out of the inbox after processing.

  • Tony T1 Level 6 Level 6 (8,125 points)
    Currently Being Moderated
    Oct 24, 2013 4:04 PM (in response to Tony T1)

    A year later.......Fixed in OS X Mavericks

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.