property mboxName : "" using terms from application "Mail" on perform mail action with messages selectedMsgs my ml("beginning...") -- this is the log routine set logString to "" & return tell application "Mail" set selCount to (count of selectedMsgs) my ml(selCount & "messages selectionnes") repeat with counter from 1 to selCount set msg to item counter of selectedMsgs set theSubject to subject of msg set theSender to sender of msg set theSender to extract name from theSender tell application "Mail" try set thebox to "" set theMailboxes to (selected mailboxes of message viewer 1) if (count of theMailboxes) is 1 then set thebox to item 1 of theMailboxes set lenom to name of thebox if thebox is inbox then set thebox to "" end if end if on error bla my ml("an error : " & bla) set thebox to "" end try end tell try my ml("tough part...") try set anotherfolder to "folder " & lenom & " currently selected" if thebox ? "" then set listebouttons to {"cancel", anotherfolder, "OK"} else set listebouttons to {"cancel", "OK"} end if set res to display dialog "what is the destination folder (if it does not exist, it will be created" default answer (theSender as string) buttons listebouttons default button "OK" if button returned of res is anotherfolder then set mbox to thebox set mboxName to lenom else set mboxName to text returned of res end if on error bla my ml("there was an error : " & bla) return end try set mbox to mailbox named mboxName get name of mbox on error bla my ml("the destination folder did not exist, let's make a new one' " & bla) if mboxName is not "" then make new mailbox with properties {name:mboxName} set mbox to mailbox named mboxName my ml("done") end if end try try set headerKey to "Sender" my ml("let us create the rule") set lenom to "rule_" & mboxName try -- WATCH OUT ! FOR THE CONVENIENCE OF THE USER, WE ARE DELETING ANY PREVIOUS RULE THAT HAS THE SAME NAME delete rule lenom end try my ml("we will create rule " & lenom) set newRule to make new rule at end of rules with properties {name:lenom} set should move message of newRule to yes set move message of newRule to mbox delete rule conditions of newRule my ml("we are going to specipy a condition " & lenom) tell newRule set theCondition to make new rule condition at after last rule condition tell theCondition set type to from header set expression to theSender set qualifier to does contain value end tell end tell -- make new rule condition at beginning of (rule conditions of newRule) with properties {rule type:header key,-- --header:headerKey, expression:theSender, qualifier:does contain value} -- set enabled of newRule to true set enabled of newRule to true my ml("we have finished") -- display dialog "La r¸gle a ˇtˇ crˇˇe. Elle s'appliquera aux nouveaux messages. -- Pour l'appliquer aux messages de la bo”te de rˇception, allez dans le menu ") display dialog ("the rule has been created. Any new message will obey.") my ml("ok") on error bla my ml("an error creation rule : " & bla) end try end repeat end tell my ml("this is the end") end perform mail action with messages end using terms from -- If run as an ordinary script, instead of directly from the Scripts -- menu, it will call the default handler instead. using terms from application "Mail" on run tell application "Mail" to set sel to selection tell me to perform mail action with messages (sel) end run end using terms from on ml(texte) try with timeout of 4 seconds do shell script "echo `date` \"\"" & the quoted form of texte & return & "\"\" >> ~/log_creation.log" end timeout end try end ml