Applescript para atualizar a regra de correio existente

2

MacOS Sierra.

Isto parece ser possível com base no seguinte script, que cria uma nova regra:

tell application "Mail"
    set newRule to make new rule at end of rules with properties { ... }
    tell newRule
        make new rule condition at end of rule conditions with properties { ... }
    end tell
end tell

O que eu gostaria de poder fazer é algo assim:

tell application "Mail"
    set existingRule to (* get a specific rule already in Mail Preferences *)
    tell existingRule
        make new rule condition at end of rule conditions with properties {rule type:message content, qualifier:does contain value, expression:"woohoo"}
    end tell
end tell

O que eu não consigo encontrar é uma maneira de recuperar uma regra que já está armazenada.

    
por Josh Bruce 16.12.2016 / 21:45

1 resposta

2

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
    
por 17.12.2016 / 22:45