Электронная почта Applescript Purge старше 2 дней

Я новичок в 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"]

person Peter M    schedule 15.03.2014    source источник


Ответы (3)


Вы помещаете 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"]
person adayzdone    schedule 15.03.2014
comment
Это работает правильно, только если я удаляю: диалоговое окно отображения (количество сообщений для удаления) и старые почтовые сообщения были очищены. В противном случае я вижу ошибку: ошибка. Не удается преобразовать {1, \ старые почтовые сообщения были очищены \} в строку типа. число -1700 из {1, старые почтовые сообщения удалены} в строку - person Peter M; 15.03.2014

Ваше редактирование сработало отлично. Я отредактировал ваш сценарий, чтобы вывести диалог на передний план.

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
person Peter M    schedule 15.03.2014

эта версия проверяет количество версий, которые нужно перенести, прежде чем продолжить

#Почта Applescript Purge старше 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
person joshuascottpaul    schedule 24.07.2020