【问题标题】:Applescript to delete message in a category in Outlook 2011Applescript 在 Outlook 2011 中删除某个类别中的邮件
【发布时间】:2014-08-11 19:15:05
【问题描述】:

上下文

在 Outlook 2011 中,我有一条规则可以自动设置传入邮件的类别 - 比如说“紫色类别”。我希望一周后自动删除此类别的电子邮件。

我想使用 AppleScript 来选择我收件箱中属于“紫色类别”的所有邮件以及一周之前的邮件,并将它们移动到已删除的文件夹中。

问题

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

以下是 Outlook 字典中这两个项目的描述:

category n, pl 类别 [inh. object > item] : 一个类别。

由应用程序包含


消息 n [inh. todoable 对象 > 可分类对象 > 对象 > 项目;另请参阅调试套件]:一封电子邮件。

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

包含在应用程序中、邮件文件夹。

正如您所见,两者都包含在应用程序中,所以当我尝试时在 AppleScript 中:

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

我收到一条错误消息:

无法收到应用程序“Microsoft Outlook”的收件箱消息 {类别“紫色类别”}。不允许访问。

其余代码:

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"]

【问题讨论】:

    标签: macos outlook applescript


    【解决方案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
    

    【讨论】:

    • 我最初是这么想的,但我认为它不起作用,因为正如规则所述,它在邮件到达收件箱时应用。但也许你能找到解决方法,我没有。
    • 您的解决方案的问题是我需要手动应用规则,这并不令人满意:在 Outlook 中,我可以通过单击过滤器 -> 类别从类别中选择所有邮件并删除它们。我在这里寻找自动化。
    • 完全修改了我的答案lol我没有时间写日期比较和删除代码sorry
    • 很好的答案!快速添加:您将如何修改脚本以遍历所有收件箱?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-25
    • 2013-08-09
    • 2011-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多