因此,我终于对在Mac上手动排序和存档电子邮件以解决一些古老的邮箱大小限制感到厌倦。我不喜欢Apple处理邮件归档的方式,因此我举了一些其他人编写的示例来对邮件进行排序,并拍了一段简短的脚本来过滤我的电子邮件并归档90天以上的所有内容。在大多数情况下,简单的事情。
这有点烦人,因为Mail没有将“在My Mac上”视为本地帐户,因此您需要调整代码以盲目引用邮箱名称..但是,它可以工作。
我认为我只是在评估问题。我可以轻松地对“收件箱”进行分类并从那里存档邮件。
on archive_email(target_account, target_mailbox, destination_account, destination_mailbox, oldemaildate)
tell application "Mail"
#Identify messages that need to be moved. If unread messages shouldn't be moved, change the end of the variable definition to read "is less than oldsentdate and read status is true)
set _msgs_to_capture to (every message of mailbox target_mailbox of account target_account whose date received is less than oldemaildate)
repeat with eachMessage in _msgs_to_capture
set archiveMailbox to (mailbox (destination_mailbox as string))
move eachMessage to archiveMailbox
end repeat
end archive_email
但是,这不适用于“已发送”文件夹。我的猜测是对于“已发送”文件夹,“接收日期小于”的评估不正确。可悲的是,“发送日期是...”似乎也不起作用。我在这里努力寻找正确的变量和评估。
答案 0 :(得分:0)
下面的代码行工作正常,假设target_account和oldmaildate具有正确的值。可以肯定的是,我直接用“已发送的邮件”替换了target_mailbox:
set _msgs_to_capture to every message of mailbox "Sent Messages" of target_account whose date sent is less than oldemaildate
请检查变量的值/类型。
此外,我建议您在重复循环之前而不是在内部设置下面的行,以提高速度:
set archiveMailbox to (mailbox (destination_mailbox as string))
答案 1 :(得分:0)
您可以取消效率低下的repeat
循环,并使用单个命令来完成移动:
on archive_email(target_account as text, target_mailbox as text, ¬
destination_account as text, destination_mailbox as text, ¬
oldemaildate as date)
tell application "Mail" to ¬
move (every message ¬
of mailbox target_mailbox ¬
of account target_account ¬
whose date sent ¬
is less than oldemaildate) ¬
to mailbox destination_mailbox
end archive_email
将date sent
用于已发送项目,我可以确认其有效。