Opening a message in Mail by refering to an unique ID

I want to open a message by refering to an unique ID. While in Entourage I managed to do this, in Mail.app it seems this is more tricky. I found two ways to identify the message uniquely. One is to use the message ID, other is to use the reference to the message. But with the first one I cannot open a message (in Entourage “open message id messID” works, in Mail.app it doesn’t), while the second one I cannot coerce to string to store it in a file for later reference. Helping with either of these two approaches would make my day…
I didn’t include code samples but if you want let me know.
Thanks Zsolt

This works:

tell application "Mail"
	tell message viewer 1
		open (every message whose message id is "whatever")
	end tell
end tell

Thanks a million, it does work indeed. If you are interested I can post a script (differs very much in Entourage and Mail version) where you can create iCal event from Entourage/Mail, update the event by getting a unique ID of the followup messages, and finally opening the mail with that ID. I use it daily and works much better then the Entourage built-in link creation system. Thanks again.
Zsolt

Zsolt, thanks for the offer but I don’t use iCal at all. But if you think others could use it, post it to:

http://scriptbuilders.net/

or the Code Exchange on this site (see dropdown menu).

Ian

Message IDs actually can be generated from the client side, and they are not 100% unique (although they tend to be in most of the practical cases).

An ultimate solution is to generate a unique hash/signature for each message, and use that to refer to the message. MD5 checksum is a good choice.

rhostik,
Sorry but the joy was short. I did some tests once I saw your initial post and they worked, but now I found some problems:

  • if the message is moved into a different folder, this still works - this is good, however I don’t understand why, considering that this message doesn’t belong to “every message of mail viewer 1” any more??
  • if i select a different mailbox or some folder then code doesn’t work any more, simply nothing happens - is this expected?
  • for some messages it doesn’t work no matter the message is not moved, and the proper mailbox is selected. If I try to get the ID of that message I get the same ID as I got in the first pass, so it is not the ID?? I didn’t find a patter acording to which some message woud/wouldn’t open
  • finally a dummy question - how do I figure out that the Mail app needs another tell to this mail viewer? What is mailviewer anyway? It has a class mailviewer, but where do I learn that the Mail.app has mailviewer class too?

Many questions, I know, answer any, I will be gratefull :wink:

What did you mean by Message IDs actually can be generated from the client side ? I do create my ID, I simply use a sequencial number list, but the trouble is that later on I have to find the right message by refering to this number. I enter my generated ID then the script goes into the text file, finds the Message ID belonging to the ID I created and tells to Mail to open the message having that message ID…
Or I missunderstood that you missunderstood me? :wink: