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
|