Applescript 更新现有的邮件规则

Applescript 更新现有的邮件规则

MacOS Sierra。

根据以下脚本,这似乎是可能的,创建一条新规则:

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

我希望能够做的事情如下:

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

我似乎找不到一种方法来取回已经存储的规则。

答案1

对于此示例,我们尝试获取电子邮件的发件人,然后将其附加到电子邮件规则中,如果电子邮件在列表中,则该规则执行相同的操作。

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

相关内容