为什么此 AppleScript 会收到“AppleEvent handler failed”消息? Mac OS X 10.5 Leopard 上出现错误?

发布于 2024-11-27 03:54:21 字数 6188 浏览 2 评论 0原文

首先,我知道,Leopard 在这一点上是老派,但这是我希望这个脚本能够支持的最低限度,所以请耐心等待(在 Mac OS X 10.4 Tiger 下甚至不可能,因为邮件的 错误redirect/forward/reply bug 我很久以前就发现了)。

我一直在重新考虑构建一个 AppleScript 来与 Topic Desk 的 spamtrainer< 结合使用/code>,因此它会检查“垃圾邮件”文件夹中选择的邮件,并尝试将它们重定向到指定的邮箱。这是我到目前为止所得到的(请注意,目前实际的发送已被注释掉,稍后会详细介绍):

(* Train Spam - Redirect (not forward) email from the Junk folder (which hasn't already been redirected or
 *             determined by the mail server to be spam) to an appropriate spam mailbox on the mail server.
 *             Developed to be used in conjunction w/spamtrainer on a Mac OS X Server mail server.
 * 
 * v0.1   2011-07-27 - Morgan Aldridge
 *                     Initial version.
 *)

using terms from application "Mail"
    on perform mail action with messages selectedMsgs in mailboxes selectedMailboxes
        tell application "Mail"
            -- configuration variables
            set junkPrefix to "***JUNK MAIL***"
            set junkRecipient to "[email protected]"

            -- ensure that we're in the Junk mailbox
            -- (it'd be disasterous to accidentally redirect mail for training from another mailbox)
            if (count of selectedMailboxes) is 1 and (first item of selectedMailboxes) is junk mailbox then
                set selCount to (count of selectedMsgs)
                set redirectedCount to 0
                repeat with counter from 1 to selCount
                    set msg to item counter of selectedMsgs
                    -- if the subject doesn't start with junkPrefix and the message hasn't already been redirected, then redirect it
                    -- (otherwise, if it starts with junkPrefix, it means it was already detected as junk by the mail server)
                    -- (and, obviously, if it was already redirected, that was probably for the sake of junk training as well)
                    if subject of msg does not start with junkPrefix and not was redirected of msg then
                        set newRedirectMsg to redirect msg with opening window
                        tell newRedirectMsg
                            -- set the to recipient to that of the specified spam mailbox on the mail server
                        make new recipient at beginning of to recipients with properties {address:junkRecipient}
                            -- remove any bcc or cc recipient (we don't want to be spamming anyone else in the process)
                            delete bcc recipients
                            delete cc recipients
                        end tell
                        -- actually send the message
                        -- send newRedirectMsg
                    else
                        display dialog "Oops, the message was already flagged as junk by the mail server or you've already redirected it!"
                    end if
                end repeat
            else
                display dialog "Oops, you're not in your Junk mailbox!"
            end if
        end tell
    end perform mail action with messages
end using terms from
-- this is required when _not_ running from the Script menu (e.g. Script Editor, FastScripts, etc.)
using terms from application "Mail"
    on run
        tell application "Mail" to set sel to selection
        tell application "Mail" to set selBox to selected mailboxes of message viewer 1
        tell me to perform mail action with messages (sel) in mailboxes (selBox)
    end run
end using terms from

Script Editor.app 运行它时(因此它会通过 on运行告诉我)并在邮件中选择少量垃圾邮件(这是在Mac OS X 10.5.8 Leopard下),它似乎适用于第一条邮件(打开一条新的重定向消息,w/to收件人设置,抄送/密件抄送字段被清空),其他重定向消息窗口打开,但其“收件人/抄送/密件抄送”字段未更新,并且 Script Editor.app 弹出对话框,其中包含“Mail收到错误:AppleEvent 处理程序失败”错误。事件日志的内容如下:

tell application "Mail"
    get selection
        {message id 464214 of mailbox "Junk", message id 464213 of mailbox "Junk", message id 464211 of mailbox "Junk"}
    get selected mailboxes of message viewer 1
        {junk mailbox}
    get junk mailbox
        junk mailbox
    get subject of message id 464214 of mailbox "Junk"
        ": Your Invitation Into a Global Directory"
    get was redirected of message id 464214 of mailbox "Junk"
        false
    redirect message id 464214 of mailbox "Junk" with opening window
        outgoing message id 400031520
    make new recipient at beginning of every to recipient of outgoing message id 400031520 with properties {address:"[email protected]"}
        to recipient 1 of outgoing message id 400031520
    delete every bcc recipient of outgoing message id 400031520
    delete every cc recipient of outgoing message id 400031520
    get subject of message id 464213 of mailbox "Junk"
        "Nominate Your Favorite Products for the Community Choice Awards"
    get was redirected of message id 464213 of mailbox "Junk"
        false
    redirect message id 464213 of mailbox "Junk" with opening window
        outgoing message id 378471104
    make new recipient at beginning of every to recipient of outgoing message id 378471104 with properties {address:"[email protected]"}
        "Mail got an error: AppleEvent handler failed."

因此,很明显,除了第一条消息之外,所有消息中的收件人设置似乎都失败了。如果后续运行该脚本而不重新启动“邮件”,也会导致第一封邮件失败。

这个问题最奇怪的部分是,运行脚本后退出邮件时,每条重定向消息(甚至是成功的消息)都会弹出一个隐藏的空白窗口,询问您是否是否要保存更改。这听起来非常类似于此线程中提到的内容,但我不确定是什么原因造成的。

那么,是什么导致了这个错误和失败呢?我该如何解决?而且,额外一点,为什么会创建隐藏的空白消息以及如何防止这种情况发生?

First, I know, Leopard is the old-fogey at this point, but it's the minimum I'd like to be able to support with this script, so please bear with me (it's not even possible under Mac OS X 10.4 Tiger due to a bug w/Mail redirect/forward/reply bug I had uncovered long ago).

I've been revisiting building an AppleScript to work in conjunction with Topic Desk's spamtrainer, so it goes through a selection of messages in the Junk folder and attempts to redirect them to a specified mailbox. Here's what I have so far (note that the actual sending is commented out at the moment, more on that later):

(* Train Spam - Redirect (not forward) email from the Junk folder (which hasn't already been redirected or
 *             determined by the mail server to be spam) to an appropriate spam mailbox on the mail server.
 *             Developed to be used in conjunction w/spamtrainer on a Mac OS X Server mail server.
 * 
 * v0.1   2011-07-27 - Morgan Aldridge
 *                     Initial version.
 *)

using terms from application "Mail"
    on perform mail action with messages selectedMsgs in mailboxes selectedMailboxes
        tell application "Mail"
            -- configuration variables
            set junkPrefix to "***JUNK MAIL***"
            set junkRecipient to "[email protected]"

            -- ensure that we're in the Junk mailbox
            -- (it'd be disasterous to accidentally redirect mail for training from another mailbox)
            if (count of selectedMailboxes) is 1 and (first item of selectedMailboxes) is junk mailbox then
                set selCount to (count of selectedMsgs)
                set redirectedCount to 0
                repeat with counter from 1 to selCount
                    set msg to item counter of selectedMsgs
                    -- if the subject doesn't start with junkPrefix and the message hasn't already been redirected, then redirect it
                    -- (otherwise, if it starts with junkPrefix, it means it was already detected as junk by the mail server)
                    -- (and, obviously, if it was already redirected, that was probably for the sake of junk training as well)
                    if subject of msg does not start with junkPrefix and not was redirected of msg then
                        set newRedirectMsg to redirect msg with opening window
                        tell newRedirectMsg
                            -- set the to recipient to that of the specified spam mailbox on the mail server
                        make new recipient at beginning of to recipients with properties {address:junkRecipient}
                            -- remove any bcc or cc recipient (we don't want to be spamming anyone else in the process)
                            delete bcc recipients
                            delete cc recipients
                        end tell
                        -- actually send the message
                        -- send newRedirectMsg
                    else
                        display dialog "Oops, the message was already flagged as junk by the mail server or you've already redirected it!"
                    end if
                end repeat
            else
                display dialog "Oops, you're not in your Junk mailbox!"
            end if
        end tell
    end perform mail action with messages
end using terms from
-- this is required when _not_ running from the Script menu (e.g. Script Editor, FastScripts, etc.)
using terms from application "Mail"
    on run
        tell application "Mail" to set sel to selection
        tell application "Mail" to set selBox to selected mailboxes of message viewer 1
        tell me to perform mail action with messages (sel) in mailboxes (selBox)
    end run
end using terms from

When running it from Script Editor.app (so it goes through the on run and tell me to) and a small number of Junk messages select in Mail (this is under Mac OS X 10.5.8 Leopard), it seems to work for the first message (opening a new redirected message, w/to recipient set, and CC/BCC fields emptied), and the other redirected message windows open, but their To/CC/BCC fields are not updated and Script Editor.app pops up the dialog with the "Mail got an error: AppleEvent handler failed" error. The contents of the Event Log are as follows:

tell application "Mail"
    get selection
        {message id 464214 of mailbox "Junk", message id 464213 of mailbox "Junk", message id 464211 of mailbox "Junk"}
    get selected mailboxes of message viewer 1
        {junk mailbox}
    get junk mailbox
        junk mailbox
    get subject of message id 464214 of mailbox "Junk"
        ": Your Invitation Into a Global Directory"
    get was redirected of message id 464214 of mailbox "Junk"
        false
    redirect message id 464214 of mailbox "Junk" with opening window
        outgoing message id 400031520
    make new recipient at beginning of every to recipient of outgoing message id 400031520 with properties {address:"[email protected]"}
        to recipient 1 of outgoing message id 400031520
    delete every bcc recipient of outgoing message id 400031520
    delete every cc recipient of outgoing message id 400031520
    get subject of message id 464213 of mailbox "Junk"
        "Nominate Your Favorite Products for the Community Choice Awards"
    get was redirected of message id 464213 of mailbox "Junk"
        false
    redirect message id 464213 of mailbox "Junk" with opening window
        outgoing message id 378471104
    make new recipient at beginning of every to recipient of outgoing message id 378471104 with properties {address:"[email protected]"}
        "Mail got an error: AppleEvent handler failed."

So, clearly it seems like the failure is with setting the to recipients in all but the first message. Subsequent runs of the script without relaunching Mail result in failures on the first message as well.

The oddest part of this issue is that, when quitting mail after running the script, there's a hidden, blank window for each of the redirected messages (even the one that was successful) that pops up asking if you want to save changes or not. This sounds very similar to something noted in this thread, but I'm not sure what causes it.

So, what's causing this error and failure? How can I resolve it? And, for extra credit, why are the hidden, blank messages created and how can I prevent that from occurring?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赠我空喜 2024-12-04 03:54:21

你的剧本对我来说看起来不错。

如果我是你,我会尝试在同一台计算机上的另一个 OS X 帐户中运行脚本,修复权限,查看日志(你已经这样做了,但这仍然是一个好主意),运行所有相关的软件更新,暂时移动您的 ~/Library/Mail 文件夹以消除它作为一个因素等。告诉我会发生什么,特别是如果它再次起作用:)

Your script looks fine to me.

If I were you, I would try running the script in another OS X account on the same computer, repair permissions, look at your logs (you've already done that, but it's still a good idea), run all relevant software updates, temporarily move your ~/Library/Mail folder to eliminate it as a factor, etc. Tell me what happens, especially if it works again :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文