Get email addresses of people from selected messages

I’m working on my first Applescript … so please excuse any ignorance … this script will eventually get the email address of the sender of each selected message, look it up in and get the ‘full name’ (first + last name) from Address Book, look for a mailfolder with this name in Mail and if it’s there, move the message to this folder.

So … step 1: get the email address of the send of each selected message … I wrote the following:

using terms from application “Mail”
on perform mail action with messages theSelectedMessages
tell application “Mail”
if (count of theSelectedMessages) is equal to 0 then
display dialog “Please select a message in Mail first, then run this script again.”
else if (count of theSelectedMessages) is greater than 0 then
display dialog “Good, you selected some messages. Let’s see …” & return
repeat with eachMessage in theSelectedMessages
set theSender to address of sender of eachMessage
display dialog theSender & return
end repeat
display dialog “done.”
end if
end tell
end perform mail action with messages
end using terms from

Which (when messages are selected) returns the ‘Good, …’ line … and then nothing.
What am I doing wrong?

Hi,

I didn’t check out the whole script, but this one line didn’t look right:

set theSender to address of sender of eachMessage

Then, I looked in the Mail dictionary for ‘sender’ and it returns text. Anyway, there isn’t any ‘address’ property of 'sender". I then got a sample incoming message and looked at the form of the text and it had this form:

senderName

So, to get the address, you need to get the address from the text.

gl,

Hm ok …

I found several scripts that seemed to use ‘address of sender of aMsg’ … but I guess I won’t be able to use it then. So I guess I’m going to have to go back to character by character analysation.