Re: selecting a message in Mail
Re: selecting a message in Mail
- Subject: Re: selecting a message in Mail
- From: Axel Luttgens <email@hidden>
- Date: Sun, 20 Sep 2009 18:42:30 +0200
Le 19 sept. 2009 à 23:56, Jim Brandt a écrit :
Chris,
Thanks to both you and Alex with the hints on the message viewer,
I managed to get this to work last night:
tell application "Mail"
tell front message viewer
set in_box to messages in inbox
set mcount to count of in_box
repeat with m from 1 to mcount
set ThisMess to item m of in_box
set read_status to read status of ThisMess
set subj to subject of ThisMess
set this_id to id of ThisMess
if not read_status then
if subj begins with "Applescript-" or subj begins with ¬
"MACSCRPT " or subj begins with "TidBits" then
(messages in inbox whose id is this_id)
set selected messages to result
my Save_and_Move()
end if
end if
end repeat
end tell -- message viewer 1
end tell -- Mail
The Save_and Move handler saves the message and moves it to
another mailbox and marks it as read.
Hello Jim,
From the above script and the description of your Save_and_Move
handler, it seems that selecting messages in the GUI isn't really
needed: Mail can directly act upon messages properties, and is able to
directly move messages from one mailbox to another as well.
So, taking a rather opposite approach (no message viewer and no
explicit loop), perhaps could something like this do the job as well:
tell application "Mail"
set MsgsRef to a reference to messages of inbox whose read status is
false and (subject begins with "Applescript-" or subject begins with
"MACSCRPT" or subject begins with "TidBits")
set Msgs to (contents of MsgsRef)
if Msgs is not {} then
set AppleScript's text item delimiters to ¬
linefeed & "From email@hidden Tue Jan 1 12:00:00 1970" &
linefeed
set MsgsMBox to ({""} & source of MsgsRef) as text
set AppleScript's text item delimiters to TIDs
set FRef to open for access file "Path:To:savedmessages.mbox" with
write permission
write MsgsMBox to FRef
close access FRef
set read status of MsgsRef to true
move Msgs to mailbox "AnotherMailbox"
end if
end tell
Depending on one's taste, this may be viewed as being more legible or,
on the contrary, as an awful piece of code... ;-)
The list of messages put into Msgs allows to remember the messages to
be moved, even if their read status has been changed.
I assumed that saving the messages as an (almost) regular mbox might
be OK for your needs (a pity that Mail's "save" command still doesn't
work...).
Note that there is a price to pay, since one may end with Mail
evaluating thrice the filter expression (the whose clause).
HTH,
Axel _______________________________________________
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