Title: Reply in digest to author [Script]--And a BUG report
As a companion to the earlier script I posted, to reply "In Digest to List", here is a script to reply "In Digest to Author". As before, I did not originate this script, which comes from Claris Emailer days; I just updated it for Entourage. When you are reading a digest and want to send a reply directed <only> to the author of the message, rather than to the entire list, this script will do the job. Just select the top portion of the message including the headers and as much of the message as you like, and run the script.

Important Note (BUG?): In both scripts, “In Digest to Author” and “In Digest to List”, there is a line that says: “set the replied to of theMessage to true”. I have discovered that if this line executes, the digest message that is open on screen scrolls to the top and the text selection of the specific message you were replying to (your position in the digest) is lost. I find that terribly inconvenient, and consider this unnecessary action a bug. Fortunately, I also do not find that marking the fact that I have replied to <something> in a digest is very helpful! Therefore, in the script below I have COMMENTED OUT that line. If you are using “In Digest to List” and find this behavior as annoying as I do, you may want to edit your copy of that script in a similar manner.

---------Script to reply "In Digest to Author"----------
-- 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
        -- Remove blanks at start of line
        --    set theLine to textSOAP "Spaces" on theText
        repeat while theLine contains "  "
            set theLine to gblReplace of theLine from "  " by " "
        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 theAuthor to my getHeader(theSelectedText, "From:")
        if the length of theAuthor is not 0 then
            set theRecipient to theAuthor
        else
            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
        end if
        set theDate to my getHeader(theSelectedText, "Date:")
        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

---------End of script----------------------------------
--
Peace,
Allen Watson <[EMAIL PROTECTED]> XNS name: =Allen Watson
A Mac family since 1984 <http://home.earthlink.net/~allenwatson/>
Applescripts for Outlook Express and Entourage: <http://homepage.mac.com/allenwatson/>

Reply via email to