简体   繁体   English

通过Mavericks中的邮件规则处理Applescript中的传入消息

[英]Processing incoming messages in Applescript via mail rule in Mavericks

I have a simple auto-reply script, based on examples I have seen here and elsewhere, that is intended to run from a spam-filtering Mail rule. 我有一个简单的自动回复脚本,该脚本基于我在此处和其他地方看到的示例,旨在从垃圾邮件过滤邮件规则运行。 Here's the gist of it: 这是要点:

on perform_mail_action(theData)
    tell application "Mail"
        set theMessages to |selectedMessages| of theData
        repeat with theIncomingMessage in theMessages
            set theOriginalSender to sender of theIncomingMessage
            set theOriginalSubject to subject of theIncomingMessage
            set theOriginalContent to content of theIncomingMessage
            set t to ""
            set t to t & "This is an automated response to your message below..."
            set t to t & return & return & "===============================================" & return & return
            set t to t & "Subject:" & theOriginalSubject & return & return & theOriginalContent
            set theReply to make new outgoing message
            tell theReply
                make new to recipient at beginning of to recipients ¬
                    with properties {address:theOriginalSender}
                set sender to "xxx@xxx.net"
                set subject to "RE: your message"
                set content to t
                send
            end tell
            set mailbox of theIncomingMessage to mailbox "Trash"
        end repeat
    end tell
end perform_mail_action

I know the rule that invokes this script is firing, because it plays a sound. 我知道调用此脚本的规则正在触发,因为它会发出声音。 But nothing is sent, and the incoming message remains in my inbox. 但是什么也没发送,传入的消息仍保留在我的收件箱中。

If I remove the first and last lines, and replace the third line with 如果我删除第一行和最后一行,然后用

set theMessages to messages of mailbox "test" of account "iCloud"

then it successfully processes all messages in the "test" folder (it sends the reply and deletes the incoming message). 然后它将成功处理“测试”文件夹中的所有消息(它发送答复并删除传入的消息)。

The rule does nothing but play a sound and invoke the script. 该规则不执行任何操作,只播放声音并调用脚本。 As noted above, the sound plays. 如上所述,声音在播放。 What am I missing? 我想念什么?

Replace the first 3 lines (including set theMessage... ) with: 将前3行(包括set theMessage... )替换为:

using terms from application "Mail"
   on perform mail action with messages theMessages for rule theRule
      tell application "Mail"

Replace the last line with: 将最后一行替换为:

   end perform mail action with messages
end using terms from

To elaborate on Michele Percich's response, despite information available online (eg, Introduction to Scripting Mail ) Mail doesn't seem to run a handler of the form: 为了详细说明Michele Percich的回复,尽管在线上有可用信息(例如Scripting Mail简介 ),Mail似乎也没有运行以下形式的处理程序:

on perform_mail_action(theData)

But it does run the handler if it's written in this form: 但是,如果以这种形式编写,它将运行处理程序:

using terms from application "Mail"
   on perform mail action with messages theSelectedMessages for rule theRule

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM