用于删除Outlook 2011中某个类别中的邮件的Applescript

时间:2014-06-21 00:55:29

标签: macos outlook applescript

上下文

在Outlook 2011中,我有一条规则会自动为传入邮件设置类别 - 例如“紫色类别”。我希望这个类别的电子邮件在一周后自动删除。

我想使用AppleScript选择收件箱中“紫色类别”中的所有邮件,并选择较早的邮件,并将其移至已删除的文件夹。

问题

问题是我无法使用Applescript选择紫色类别中的消息。从Outlook词典的描述中,似乎消息类别处于同一级别:

以下是Outlook词典中两个项目的说明:

  

类别n,pl类别[inh。对象> item]:一个类别。

     
    应用程序包含

  

  消息n [inh。 对象>项目;另请参阅Debug Suite]:电子邮件。

     
    

包含收件人,收件人,抄送收件人,密送收件人,附件;

         

包含在应用,邮件文件夹中。

  

正如你所看到的那样,AppleScript中的应用程序都包含了这两个内容:

set messagesToDelete to message in inbox whose {category "Purple Category"}

我收到一条错误消息:

  

无法获取应用程序“Microsoft Outlook”的收件箱的消息   {category“Purple Category”}。不允许访问。

其余代码:

set daysToPreserve to 7
set dateReference to (current date) - (daysToPreserve * days)
tell application "Microsoft Outlook"
set messagesToDelete to message in inbox whose {category "Purple Category"} and time received ≤ dateReference
if messagesToDelete is {} then
return
end if
permanently delete messagesToDelete
end tell
display dialog (count messagesToDelete) & " old Mail Messages Have Been Purged" as text buttons ["OK"]

1 个答案:

答案 0 :(得分:1)

你必须遍历所有具有类别的消息

tell application "Microsoft Outlook"

    repeat with afolder in mail folders
        set theMsgs to (every message of afolder where it's category is not {})

        -- loop through the messages
        repeat with aMsg in theMsgs
            -- get all the categories of the message
            set cats to categories of aMsg
            -- loop through the categories
            repeat with aCat in cats
                set catName to name of aCat
                -- check to see if this is the category of emails we want to delete
                if catName is "Purple Category" then
                    get time received of aMsg
                    set foo to date of time received of aMsg
                    -- compare dates  and delete aMsg
                    -- exit the loop so we don't error after deleting the message
                    exit repeat
                end if
            end repeat
        end repeat
    end repeat
end tell