Re: Move message to another mailbox behaves erratically?
Re: Move message to another mailbox behaves erratically?
- Subject: Re: Move message to another mailbox behaves erratically?
- From: Michael Heinz <email@hidden>
- Date: Fri, 7 Mar 2003 19:29:41 -0500
That's an excellent suggestion, Shane!
I was actually thinking the same thing about the references, but it
didn't occur to me to reverse the list.
I'll post the results in a few!
On Friday, March 7, 2003, at 05:01 PM, Shane Stanley wrote:
On Thursday, March 6, 2003, at 9:38 PM, Michael Heinz wrote:
So, I figured out to set the mailbox property of each message to move
them between mailboxes. Okay; fine. But things still don't work as
expected. Here's a code fragment:
tell application "Mail"
set my_archive to mailbox ArchiveBox
ignoring case
repeat with cur_rule in CategoryList
set my_messages to (every message of mailbox ArchiveBox
whose
sender contains (item 1 of cur_rule))
set new_mailbox to mailbox (item 2 of cur_rule)
repeat with my_message in my_messages
display dialog (item 1 of cur_rule) & ": " & sender of
my_message
as string
set mailbox of my_message to mailbox (item 2 of
cur_rule)
end repeat
end repeat
end ignoring
end tell
The display dialog is there for diagnostic purposes. If I comment out
the "set mailbox" line, the script performs as expected. But when I
try to actually do the move, things quickly go sour. As near as I can
tell, once a message has been moved, the my_messages list becomes
corrupt - it starts pointing at the wrong messages! You can see this
in the display dialog, where you be told that the string "Todd"
contains the string "Penny", for example.
Can anyone tell me what I'm doing wrong? I'd like to write a script
that archives and sorts old mail into different bins, and I'm soooo
close.
My guess would be that Mail is returning references in the form of
"message
n of mailbox "Bloggs" of...", where n is a number. But once you move
one
message, what was message n is now message (n-1).
Try adding the line:
set my_messages to reverse of my_messages
before the repeat loop, and see if that solves the problem.
It would be preferable if Mail returned more robust references,
referring to
messages by id. I see the dictionary lists a "message id" property for
messages and an "id" property for outgoing messages. I wonder if they
are
the same thing.
--
Shane Stanley, email@hidden
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.