Email 如何使用Applescript删除邮箱

Email 如何使用Applescript删除邮箱,email,applescript,Email,Applescript,我希望脚本遍历邮箱树并删除空邮箱: 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

我希望脚本遍历邮箱树并删除空邮箱:

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
“删除框”导致错误: 错误“Mail got a error:无法从邮箱“Archives”的每个邮箱的每个邮箱的每个邮箱的每个邮箱的每个邮箱的每个邮箱的每个邮箱的项目1中获取项目1”编号-1728邮箱“Archives”

有两个问题:

•行中的索引变量
mbx

repeat with mbx in mailboxes of box
是一个类似于box的每个邮箱的
项目1的引用,而不是box的
邮箱“某物”。在将变量传递给具有
内容的处理程序之前,必须取消对该变量的引用

•在同一行中,如果项目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