Apple脚本:更改符合条件的消息的标志

Apple script: Change flag for message which match criteria

好的,我正在创建脚本来为我读取收到的邮件。 我坚持一件事: 如何更改符合我的条件的消息的标志,因为我在循环中检查未读消息,如果当前检查的消息匹配,则应该标记它。选中的消息很容易做,但是如何在循环中标记消息?

请看我的尝试:

if (thisSubject contains projectName or thisSubject contains projectName1 or thisSubject contains projectName2 or thisSubject contains projectName3) then
        --mark required messages with red flag
        tell application "Mail"
            #set currentMail to thisMail
            set currentMail to selection
            repeat with s in currentMail
                set flag index of s to 1 as integer
            end repeat

        end tell

更新: 这是一个循环,应该用 flag

标记所有匹配的邮件
repeat with thisMail from 1 to count of theSubjects
set thisSubject to item thisMail of theSubjects
if (thisSubject contains searchWord or thisSubject contains searchWord2) then
    if (thisSubject contains projectName or thisSubject contains projectName1 or thisSubject contains projectName2 or thisSubject contains projectName3) then
        --mark required messages with flag  
        tell application "Mail"
            #   set allMessage to selection
            repeat with MyMessage in thisMail
                #   set read status of thisMail to true -- set read
                set flagged status of MyMessage to true -- display flag / false hide flag
                set flag index of MyMessage to 1 -- set first color for the flag (-1 remove the flag)
            end repeat
        end tell
    end if
end if  

结束重复

标志索引定义了标志的颜色。要使标志处于活动状态或不处于活动状态,您必须使用已标记状态。

这是一个带有读取标志、标志 on/off 和颜色

的示例
set projectName1 to "test1"
set projectName2 to "test2"
set projectName3 to "test3"
set SearchWord1 to "Myword1"
set SearchWord2 to "Myword2"

tell application "Mail"
set allMessage to every message of inbox whose (subject contains projectName1) or (subject contains projectName2) or (subject contains projectName3) or (subject contains SearchWord1) or (subject contains SearchWord2)
repeat with MyMessage in allMessage
    set read status of MyMessage to true -- set read
    set flagged status of MyMessage to true -- display flag / false hide flag
    set flag index of MyMessage to 1 -- set first color for the flag (-1 remove the flag)
end repeat
end tell