Applescript清除电子邮件超过2天

时间:2014-03-15 13:30:24

标签: macos email applescript purge recycle-bin

我是Applescript的新手。我有一个特定的电子邮件帐户,仅用于接收带有附加图像的错误报告。邮箱可以快速填满。

我希望能够运行一个删除超过两天邮件的脚本,所以我尝试了以下脚本。

我想纠正我所写的内容,这样我就可以从错误中吸取教训,而不是使用不同的方法。寻找一些建设性的批评:

set daysToPreserve to 2

tell application "Mail"
activate
set mailboxList to mailbox "INBOX" of account “MyAccount"
repeat with theCurrentMailbox in mailboxList
    set emailList to (every message of (mailbox theCurrentMailbox of account “MyAccount") whose date received is less than or equal to ((current date) - daysToPreserve * days))
    if (count mailboxList) is greater than 0 then
        move mailboxList to mailbox "Trash" of account “MyAccount"
    end if
end repeat
end tell

display dialog "Old Mail Messages Have Been Purged" buttons ["OK"]

3 个答案:

答案 0 :(得分:1)

您将1个项目放入重复块中:

set mailboxList to mailbox "INBOX" of account “MyAccount"
repeat with theCurrentMailbox in mailboxList

您可以尝试这样的事情:

set daysToPreserve to 2
set myAcount to "MyAccount"
set dateReference to (current date) - (daysToPreserve * days)

tell application "Mail"
    activate
    set myMailbox to mailbox "INBOX" of account myAcount
    set accountTrash to mailbox "Trash" of account myAcount
    set messagesToDelete to messages of myMailbox whose date received ≤ dateReference
    repeat with aMessage in messagesToDelete
        move aMessage to accountTrash
    end repeat
end tell

display dialog (count messagesToDelete) & " old Mail Messages Have Been Purged" as text buttons ["OK"]

答案 1 :(得分:0)

您的编辑效果很好。我编辑了你的脚本,把对话框放到了前面。

set daysToPreserve to 2
set myAcount to "MyAccount"
set dateReference to (current date) - (daysToPreserve * days)

tell application "Mail"
  activate
  set myMailbox to mailbox "INBOX" of account myAcount
  set accountTrash to mailbox "Trash" of account myAcount
  set messagesToDelete to messages of myMailbox whose date received ≤ dateReference
  repeat with aMessage in messagesToDelete
  move aMessage to accountTrash
end repeat
end tell

tell current application
  activate
  display dialog (count messagesToDelete) & " old Mail Messages Have Been Purged" as    text buttons ["OK"]
end tell

答案 2 :(得分:0)

此版本先测试要移动的版本数

Applescript Purge Email Older than 2 Days

set daysToPreserve to 7
set myAccount to "MyEmail Account"
set dateReference to (current date) - (daysToPreserve * days)

tell application "Mail"
    activate
    set myMailbox to mailbox "INBOX/7 days" of account myAccount
    set accountTrash to mailbox "Trash" of account myAccount
    set messagesToDelete to messages of myMailbox whose date received ≤ dateReference
    
    if (count messagesToDelete) as number = 0 then
        return
    end if

    repeat with aMessage in messagesToDelete
        move aMessage to accountTrash
    end repeat
end tell

tell current application
    activate
    display notification (count messagesToDelete) & " old messages have been purged from folder 7 days" as text
    delay 1
end tell