1

我是 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"]
4

3 回答 3

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"]
于 2014-03-15T15:08:56.650 回答
1

您的编辑效果很好。我编辑了您的脚本以将对话框置于最前面。

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
于 2014-03-15T23:43:06.683 回答
0

此版本在继续之前测试要移动的版本数

# Applescript 清除超过 2 天的电子邮件

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
于 2020-07-24T00:43:18.730 回答