Neste exemplo, estamos tentando obter o remetente de um email e, em seguida, anexá-lo a uma regra de email que execute a mesma ação se o email estiver na lista.
tell application "Mail"
(* The nameOfJunkRule is the string you gave in Mail.app. *)
(* This is the part that begins to address the question. *)
set markAsJunkRule to get rule nameOfJunkRule
(* Get the selected messages in Mail.app *)
set theMessages to the selection
repeat with theMessage in theMessages
(* Get the sender of the message. *)
set senderAddress to sender of theMessage
(* We want to make sure the address isn't already in the list. *)
set foundAddress to false
repeat with theCondition in rule conditions of markAsJunkRule
if senderAddress = expression of theCondition then
set foundAddress to true
exit repeat
end if
end repeat
(* If we need to add a new address to the rule. This is to finish the answer. *)
if foundAddress = false then
tell markAsJunkRule
make new rule condition at end of rule conditions with properties {rule type:from header, qualifier:does contain value, expression:senderAddress}
end tell
end if
end repeat
end tell