2016-12-05 26 views
0

對於給定的消息,我想在其線程的所有消息的所有消息,例如:查找線程

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郵箱遍歷所有的消息和比較對象,但這不是有效的)

+0

Applescript Mail指令不支持線程。解決方法是選擇標題包含xxxx的所有消息,然後遍歷該列表。 – pbell

+0

@pbell,謝謝。好像我應該使用'將theThreadMessages設置爲郵件主題等於郵件主題的郵件箱'。你知道嗎,是否有一種方法可以封鎖主題(例如去掉所有'fwd:'和're:'等)? – Zelta

+0

而不是「誰的主題等於」,你應該使用「誰的主題包含」。 AS會給你所有關於哪個部分的主題是你正在尋找的信息。 – pbell

回答

0

好吧,如果你收到主題re: subj一個消息,你將無法找到消息使用contains運營主體fwd: subj

所以這裏是剝離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

0

周圍的其他方式:「再:主題」包含「主題」。 這裏是一個小腳本與主題的相同部分讀取郵件:

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)