2011-07-29 47 views
1

首先,我知道,Leopard是老老頑固在這一點上,但它是我希望能夠與這個腳本的支持,所以請多多包涵(它在Mac OS X 10.4 Tiger的甚至是不可能的最低由於bug w/Mail redirect/forward/reply bug I had uncovered long ago)。爲什麼AppleScript在Mac OS X 10.5 Leopard上收到「AppleEvent處理程序失敗」錯誤?

我一直在重新構建一個AppleScript,以便與Topic Desk's spamtrainer一起工作,因此它會通過Junk文件夾中的所有消息並嘗試將它們重定向到指定的郵箱。這裏是我到目前爲止(注意,實際的發送是在瞬間註釋掉,後來更多):

(* 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 runtell me to)和小郵件中選擇的垃圾郵件數量(這是在Mac OS X 10.5.8 Leopard下),它似乎適用於第一條郵件(打開新的重定向郵件,收件人設置,CC/BCC字段清空),以及其他重定向消息窗口打開,但他們/ 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:"[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." 

因此,很明顯,好像故障是與設置在所有to recipients但第一條消息。在沒有重新啓動郵件的情況下,腳本的後續運行也會導致第一條消息失敗。

這個問題的最奇怪的地方在於,運行腳本後退出郵件時,有一個爲的重定向消息(即使是一個成功)的每個彈出詢問是否要隱藏的,空白窗口保存或不保存更改。這聽起來非常類似的東西在this thread注意到,但我不知道是什麼原因造成的。

那麼,是什麼造成這個錯誤和失敗?我該如何解決它?而且,爲了獲得額外的信用,爲什麼會創建隱藏的空白郵件,以及如何防止發生這種情況?

+1

請注意,我不能重現這個在10.6。它可以在我的電腦上正常工作。在那個筆記,不錯的腳本:) – eykanal

+0

你有沒有發現如何避免退出時彈出的草稿(你的「隱藏窗口」)?我試圖解決我的腳本相同的問題,並找不到任何關於此。謝謝! – fastasleep

+0

@fastasleep不幸的是,我沒有。 – morgant

回答

0

您的腳本看起來好像沒什麼問題。

如果我是你,我會嘗試在同一臺計算機上的另一個OS X帳戶中運行腳本,修復權限,查看日誌(您已經完成了這一步,但仍然是個好主意),運行所有有關軟件更新,暫時將您的文件夾~/Library/Mail消除它的一個因素,等等。告訴我發生了什麼,尤其是如果它再次工作:)

相關問題