• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to select a message in Apple mail, given mail ID?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to select a message in Apple mail, given mail ID?


  • Subject: Re: How to select a message in Apple mail, given mail ID?
  • From: Ron Hunsinger <email@hidden>
  • Date: Mon, 26 Sep 2011 14:46:51 -0700


On Sep 26, 2011, at 9:50 AM, Shuba and Karthik wrote:

How do I *select* a message in the message viewer of Apple Mail given the message ID?

In case it makes a difference to your response, I am on Mac OS X 10.6.8.

(FWIW: tested on OS X 10.7.1, and I assume by "select" you mean "refer to from a script", rather than to actually change the selection.)

First off, ignore all references to the "Message-ID". That's a field in the headers of the mail message that is assigned by the original composer of the message, in a way that is supposed to be unique, but:
a) isn't always unique, and
b) isn't always present, and
c) isn't always useful, even if present and unique.

Many scriptable applications internally assign an id to some objects in the program's internal data model whose purpose is to uniquely identify it. How it does that is application-dependent, but in principle once you get an object's id you can continue to refer to that same object using its id, even if you originally found the object by name and it's since been renamed, or originally found it by position and it's since been moved.

Mail does assign an id to messages. It's basically a sequential number, assigned as Mail gets the message from wherever. For example, your message, the one I'm replying to, is identified in my copy of Mail as:

message id 185892 of mailbox "INBOX/Apple/AppleScript Users" of account "xxx"

and if I ask for its id I get 185892.

The trouble is, there's a bug in Mail's scripting. You should be able to refer to that message later using exactly that _expression_, but it perversely refuses to recognizes the keyword "id" in that context. It should mean "the message whose id is ..", but Mail seems to think you're talking about the "message id" property. The solution is to rephrase the reference so that the words "message" and "id" are not adjacent, as in for example:

tell application "Mail"
tell mailbox "INBOX/Apple/AppleScript Users" of account "xxx"
set theMessage to (some message whose id is 185892)
properties of theMessage
end tell
end tell

Notice that, even with the message id, you still cannot get to the message except through its mailbox, which you can only access through its account.

-Ron Hunsinger

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: How to select a message in Apple mail, given mail ID?
      • From: Shuba and Karthik <email@hidden>
References: 
 >How to select a message in Apple mail, given mail ID? (From: Shuba and Karthik <email@hidden>)

  • Prev by Date: Re: How to select a message in Apple mail, given mail ID?
  • Next by Date: Getting full file paths on clipboard with AS
  • Previous by thread: Re: How to select a message in Apple mail, given mail ID?
  • Next by thread: Re: How to select a message in Apple mail, given mail ID?
  • Index(es):
    • Date
    • Thread