【发布时间】:2023-03-26 19:11:02
【问题描述】:
首先,我知道,Leopard 在这一点上是老生常谈,但这是我希望能够支持此脚本的最低限度,所以请耐心等待(在 Mac OS X 10.4 下甚至不可能虎因bug w/Mail redirect/forward/reply bug I had uncovered long ago)。
我一直在重新审视构建一个 AppleScript 以与 Topic Desk's spamtrainer 一起工作,因此它会检查垃圾文件夹中的一系列邮件并尝试将它们重定向到指定的邮箱。到目前为止,这是我所拥有的(请注意,目前实际发送已被注释掉,稍后会详细介绍):
(* 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 "junkmail@domain.tld"
-- 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 run 和tell me to)并在邮件中选择少量垃圾邮件(这是在 Mac OS X 10.5.8 Leopard 下),它似乎处理第一条消息(打开一个新的重定向消息,带有收件人集,并且 CC/BCC 字段清空),其他重定向消息窗口打开,但它们的 To/CC/BCC 字段未更新,Script Editor.app 弹出出现“邮件出错: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:"junkmail@domain.tld"}
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:"junkmail@domain.tld"}
"Mail got an error: AppleEvent handler failed."
因此,显然失败似乎是在除第一条消息之外的所有设置中都设置了to recipients。随后在不重新启动 Mail 的情况下运行脚本也会导致第一条消息失败。
这个问题最奇怪的部分是,在运行脚本后退出邮件时,每条 重定向邮件(即使是成功的邮件)都会弹出一个隐藏的空白窗口询问您是否要保存更改。这听起来非常类似于this thread 中提到的内容,但我不确定是什么原因造成的。
那么,是什么导致了这个错误和失败?我该如何解决?而且,为了额外的功劳,为什么会创建隐藏的空白消息,我该如何防止这种情况发生?
【问题讨论】:
-
请注意,我无法在 10.6 上重现此内容。它在我的电脑上运行良好。在那张纸条上,不错的脚本:)
-
你有没有发现如何避免退出时弹出的草稿(你的“隐藏窗口”)?我正在尝试为我的脚本解决同样的问题,但在这方面找不到任何东西。谢谢!
-
@fastasleep 不幸的是,我没有。
标签: email applescript osx-leopard