Le 28 sept. 2006 à 01:02, Emmanuel a écrit : At 6:26 PM +0200 9/27/06, Francis Derive wrote: I notice that, in the first and correct case, what is handled from the mailbox is a "message" ( message id 331045 ), while in the second case it is an "item" of the list "every message of mailbox xxx" - without any clue of the error.
My advice is to always force dereferencing of the "item" in the first place. If you don't do it yourself, AppleScript will do it each time the variable is invoked in the loop, so if you use the loop variable more than once in the loop you're improving speed.
repeat with myLoopVariable in someList set myLoopVariable to contents of myLoopVariable -- dereference once for all and be safe
Emmanuel
Hello Emmanuel.
It's the first thing I tried but it failed.
set {laSource, laDestination} to {"zzz", "xyz"}
tell application "Mail" set k to count of messages of mailbox laSource if k > 0 then repeat with myMessage in (every message of mailbox laSource) set my_message to contents of myMessage if year of (get date received of my_message) = 2005 then move my_message to mailbox laDestination end repeat end if end tell
Report:
tell application "Mail" count every message of mailbox "zzz" 4 count every message of mailbox "zzz" 4 get item 1 of every message of mailbox "zzz" message id 84223 of mailbox "zzz" get date received of message id 84223 of mailbox "zzz" date "mardi 22 novembre 2005 21:31:04" move message id 84223 of mailbox "zzz" to mailbox "xyz" get item 2 of every message of mailbox "zzz" message id 84222 of mailbox "zzz" get date received of message id 84222 of mailbox "zzz" date "vendredi 18 novembre 2005 08:36:04" move message id 84222 of mailbox "zzz" to mailbox "xyz" get item 3 of every message of mailbox "zzz" message id 84155 of mailbox "zzz" get date received of message id 84155 of mailbox "zzz" date "vendredi 18 juin 2004 14:35:13" get item 4 of every message of mailbox "zzz" "Erreur dans Mail : NSReceiverEvaluationScriptError: 4"
It seems that the script doesn't find an item 4 when the three first ones are already moved. This is why I first gave a loop running backwards .
Of course, if you are able to explain why the dereferencing code fails, I would be interested.
Yvan KOENIG |