查找线程中的所有消息

时间:2016-12-05 20:46:20

标签: email applescript

对于给定的消息,我想在其线程中获取所有消息,例如:

tell application "Mail"
    if content of theMessage contains "merged #" then
        # repeat with otherMessage in the thread of theMessage
            set background color of otherMessage to green
        # end repeat
    end if
end tell

我该怎么做/它有可能吗?

(我知道我可以遍历theMessage邮箱中的所有邮件并比较主题,但效率不高)

2 个答案:

答案 0 :(得分:0)

相反,反过来说:' re:subject'包含' subject'。 这是一个小脚本,用于读取与主题相同部分的邮件:

set myTitle to "subject of my thread" --only the subject without 're:' or 'Fwd:'
tell application "Mail"
set myEmails to {}
set MailSent to {every message of sent mailbox whose subject contains myTitle}
set Mailreceived to {every message of inbox whose subject contains myTitle}
set BoxList to name of every mailbox
repeat with aBox in BoxList
    set end of myEmails to {every message of mailbox aBox whose subject contains myTitle}
end repeat
end tell
display dialog "sent=" & (count of MailSent) & return & "receipt=" & (count of Mailreceived) & return & "other=" & (count of myEmails)

答案 1 :(得分:0)

好吧,如果您收到主题为re: subj的邮件,则无法使用fwd: subj运营商找到主题为contains的邮件。

所以这是一个剥离refwd的函数:

-- Email subject canonization
-- Strips 're:', 'fwd:', etc. from the beginning of the text string passed in.
on canonizeSubject(theSubject)
    return do shell script "export LC_ALL=en_US.UTF-8; export LANG=en_US.UTF-8; shopt -u xpg_echo; echo " & quoted form of theSubject & " | perl -C -Mutf8 -pe 's/^(re|fwd|\\s|:)*//i'"
end canonizeSubject

用法是:

set theSubject to my canonizeSubject(subject of theMessage)
set messagesInTheThread to messages of mailbox of theMessage whose subject contains theSubject

但实际上,这并不是一种完整的电子邮件分组方式。为了正确,您应该分组到线程中,而不是通过匹配主题,而是使用References标题搜索原始邮件。

请在此处查看详细信息:https://cr.yp.to/immhf/thread.html