我希望我的脚本遍历邮箱树并删除空邮箱:
tell application "Mail"
my cleanup(mailbox "Archives")
end tell
on cleanup(box)
tell application "Mail"
if (count of mailboxes of box) > 0 then
repeat with mbx in mailboxes of box
my cleanup(mbx)
end repeat
else
if (count of messages of box) = 0 then delete box
end if
end tell
end cleanup
“删除框”会导致错误: 错误“邮件出错:无法获取邮箱每个邮箱的第1项的每个邮箱的第1项”Archives \“。”从邮箱“档案馆”的每个邮箱的项目1的每个邮箱的项目1中的号码-1728
答案 0 :(得分:1)
有两个问题:
•行
中的索引变量mbx
repeat with mbx in mailboxes of box
是item 1 of every mailbox of box
而不是mailbox "something" of box
的引用。在将变量传递给具有contents of
的处理程序之前,您必须取消引用该变量。
•如果例如项目1已被删除,则在同一行中您将收到错误,项目2现在是项目1,并且不再有项目2。为避免这种情况,请使用关键字get
来检索在循环期间不受删除影响的复制引用。
tell application "Mail"
my cleanup(mailbox "Archives")
end tell
on cleanup(box)
tell application "Mail"
if (count of mailboxes of box) > 0 then
repeat with mbx in (get mailboxes of box)
my cleanup(contents of mbx)
end repeat
else
if (count of messages of box) = 0 then delete box
end if
end tell
end cleanup