Title: "Digest reply to" AppleScript question
I subscribe to a couple lists in digest mode, and for the past, oh, eight years (first in Emailer then in Entourage) have been using a couple scripts called "Digest Reply to List" and "Digest Reply to Author" to send replies to messages. These scripts work by simply selecting the message in the digest (including the To/From/Date/Subject section) and running the script -- it creates a new message with the proper subject, attribution, and quoting, address to either the mailing list or to the author of the message.

I just discovered that my scripts break under Entourage 2004. Specifically, when run, both scripts provide the following error:

    Text in a single message must be selected.


Not being a scripter, I'm having trouble finding the problem. Here’s the “Digest Reply to List” script: anyone see the obvious cause?


-- routine to do a search and replace on text
to gblReplace of mainString from stringA by stringB
   set od to AppleScript's text item delimiters
   set AppleScript's text item delimiters to stringA
   set temp to every text item of mainString
   set AppleScript's text item delimiters to stringB
   set mainString to temp as text
   set AppleScript's text item delimiters to od
   return mainString
end gblReplace

on replyText(theText)
    set theReplyText to ""
    --    set theText to textSOAP "Spaces" on theText
   repeat while theText contains "  "
        set theText to gblReplace of theText from "  " by " "
    end repeat
   
    set theLines to the paragraphs of theText
   set blank to false
   set looking to true
   repeat with theLine in theLines
       if looking then
           if the length of theLine = 0 then set looking to false
       else
           if theLine starts with "-- " and the length of theLine is 3 then exit repeat
           if blank then set theReplyText to theReplyText & ">" & return
           set blank to false
           if the length of theLine is 0 then
               set blank to true
           else if theLine starts with ">" then
               set theReplyText to theReplyText & ">" & theLine & return
           else
               set theReplyText to theReplyText & "> " & theLine & return
           end if
       end if
   end repeat
   return theReplyText
end replyText

on getHeader(theText, theHeader)
    set theLines to the paragraphs of theText
   repeat with theLine in theLines
       --        set theLine to textSOAP "Spaces" on theLine
       repeat while theLine contains "  "
            set theLine to gblReplace of theLine from "  " by " "
        end repeat
       repeat while theLine starts with " "
            set theLine to text 2 thru -1 of theLine
       end repeat
       if theLine starts with theHeader then
           set theSubject to characters (2 + the (length of theHeader)) thru -1 of theLine as string
           return theSubject
       end if
   end repeat
   return ""
end getHeader

on makeRecipient(theMessage)
    tell application "Microsoft Entourage"
        set theHeaders to the headers of theMessage
       repeat with theHeader in the paragraphs of theHeaders
           if theHeader starts with "Reply-To:" then
               set theRecipient to characters 11 thru -1 of theHeader as string
               return theRecipient
           end if
       end repeat
       return ""
    end tell
end
makeRecipient


on replyOne(theMessage, theSelectedText)
    tell application "Microsoft Entourage"
        set theText to my replyText(theSelectedText)
        set theSubject to my getHeader(theSelectedText, "Subject:")
        if theSubject does not start with "Re: " then set theSubject to "re: " & theSubject
       set theRecipient to my makeRecipient(theMessage)
        if theRecipient is "" then
           set theAddress to the sender of theMessage
           set theAddressString to the address of theAddress
           set theName to the display name of theAddress
           if theName is "" then
               set theRecipient to theAddressString
           else
               set theRecipient to "\"" & theName & "\" <" & theAddressString & ">"
            end if
       end if
       set theDate to my getHeader(theSelectedText, "Date:")
        set theAuthor to my getHeader(theSelectedText, "From:")
        set theAttribution to ""
        if the length of theDate = 0 then
           if the length of theAuthor ≠ 0 then
               -- From: but no Date:
               set theAttribution to (theAuthor & " wrote:" & return)
            else
               -- neither From: nor Date:
               set theAttribition to ""
            end if
       else
           if the length of theAuthor = 0 then
               -- Date: but no From:
               set theAttribution to ("On " & theDate & ", " & " someone wrote:" & return)
            else
               -- Date: and From:
               set theAttribution to ("On " & theDate & ", " & theAuthor & " wrote:" & return)
            end if
       end if
       set theText to theAttribution & return & theText
       
        --        set the replied to of theMessage to true
       
        try
           set theAccount to the account of theMessage
           if default signature type of theAccount is not none then
               make new draft window with properties ¬
                    {subject:theSubject, content:theText, to recipients:theRecipient, account:theAccount, other signature choice:default signature choice of theAccount}
            else
               make new draft window with properties ¬
                    {subject:theSubject, content:theText, to recipients:theRecipient, account:theAccount}
            end if
       on error
           if default signature type of theAccount is not none then
               make new draft window with properties ¬
                    {subject:theSubject, content:theText, to recipients:theRecipient, other signature choice:default signature choice of theAccount}
            else
               make new draft window with properties ¬
                    {subject:theSubject, content:theText, to recipients:theRecipient}
            end if
       end try
   end tell
end
replyOne

on run
   tell application "Microsoft Entourage"
        set theMessages to the current messages
       set theSelection to the selection of the front window
       if the (count of theMessages) = 1 and the class of theSelection is string then
           set theMessage to item 1 of theMessages
           my replyOne(theMessage, theSelection)
        else
           display dialog "Text in a single message must be selected." buttons {"OK"} default button {"OK"}
        end if
   end tell
end
run


Reply via email to