ぽんぽこ日記

プログラミング、読書、日々の生活

entourageでメーリングリストからのメールを振り分け

最近Microsoft EntourageというMacのメーラー/オーガナイザを使っている。

職場ではプロジェクトが立ち上がる毎にメーリングリストが立ち上がるのだが、立場上かなりのメーリングリストに自動的に加入することになる。
その都度、メーリングリスト毎にフォルダに振り分けることになるのだが、設定の手間だけでもバカにならないコストだ。

そこで自動的にメーリングリストと同名のフォルダを作成してメールを移動させるapplescriptを作成した。

===使い方===

スクリプトエディタで下記コードをコンパイルして所定の場所(通常は"~/Documents/Microsoft ユーザー データ/Entourage Script Menu Items")に置いて,
[ツール]メニューから[ルール...]を選択し、新規ルールを作成する。ルールのアクションの部分で[AppleScriptを実行]を選択し、[スクリプト...]ボタンから作成したスクリプトを指定する。

tell application "Microsoft Entourage"
set selectedMessages to current messages
if selectedMessages is {} then
display dialog "メッセージを選択してからこのスクリプトを実行してください。" with icon 1
return
end if
repeat with theMessage in selectedMessages
set theParagraph to headers of theMessage
repeat with theHeader in paragraphs of theParagraph
if theHeader starts with "Delivered-To: mailing list" then
set oldDel to text item delimiters of AppleScript
set text item delimiters of AppleScript to {" "}
set theMLName to get fourth text item of theHeader
set text item delimiters of AppleScript to {"@"}
set theMLName to get first text item of theMLName
if not (exists folder theMLName of folder "ML") then
set theFolder to make folder of folder "ML"
set name of theFolder to theMLName
end if
move theMessage to folder theMLName of folder "ML"
set text item delimiters of AppleScript to oldDel
end if
end repeat
end repeat
end tell