-- Eudora-GPG-Sign version 0.008 -- Richard Chang -- Read the Notes file. Use at your own risk. -- If you make money with this, give me some. Otherwise free. -- -- Version .001: new -- Version .002: uses Unix fmt to wrap messages before signing with GPG -- Version .003: -- 1. Cleaned up code, uses subroutines for reading and writing -- 2. Figured out how to get user's home directory. -- 3. Uses 'do shell script' instead of 'system', but still need 'system' to ask for passphrase. -- 4. Better error checking and reporting. -- Version .004: -- 1. Single quotes around Unix directory name. -- 2. Uses "rm -P" to overwrite and remove files. (Thanks: Fredrik Jonsson.) -- Version .005: -- 1. Uses "POSIX path" to compute UnixDocumentsDir -- 2. Uses "character i" instead of "text item i" -- 3. WrapUnixFile wraps long lines semi-intelligently -- 4.. Asks user what to do with long lines. Allows user to "Cancel" and use Eudora for wrapping. -- Version .006 -- Figured out how to make new folder in "Temporary Items" -- Version .007 -- 1. More error checking for 0 length messages and files. -- 2. Fixed clean up bug in "Keep Long Lines" -- 3. Bug user about de-selecting wrap icon only if it really is selected in Eudora. -- 4. Does not chop off last line if last line doesn't end with CR. -- Version .008 -- 1. Put CleanUp in a function -- 2. Uses shred -uz if available -- 3. Fixed escalating tempxxx directory name problem? -- 4. Moved common functions into a shared file -- 5. Better clean up when user cancels passphrase set CR to ASCII character 13 set LF to ASCII character 10 set WrapLength to 76 -- Load library tell application "Finder" set EudoraScriptsFolder to folder "Contents:MacOS:Eudora Stuff:Scripts:" of (path to me) set LibFile to file "Eudora-GPG Stuff:Eudora-GPG-Lib" of EudoraScriptsFolder end tell set EGPGLib to load script file (LibFile as string) tell EGPGLib to set {theFolder, QuotedUnixDir} to MakeTempFolder() -- Get body of current message tell application "Eudora" to set OriginalMesg to body of message 0 if length of OriginalMesg = 0 then display dialog "Empty message body! No processing done." buttons {"OK"} default button "OK" return end if tell EGPGLib to set NeedsWrapping to WrapUnixFile(theFolder & "mesg", OriginalMesg, WrapLength) -- Check to see what user wants to do with long lines if NeedsWrapping then try set response to display dialog  "Wrapped lines OK?" & CR &  "Click on \"Cancel\" to use Eudora for wrapping." buttons {"Cancel", "Keep Long Lines", "OK"} default button "OK" if button returned of response is "Keep Long Lines" then tell application "Eudora" to set WrapSelected to wrap of message 0 if WrapSelected then display dialog "Looks like the wrap message icon in Eudora is selected. Remember to de-select wrap before sending!" buttons {"OK"} default button "OK" end if tell EGPGLib to WriteUnixFile(theFolder & "nowrap", OriginalMesg) set MesgFile to "nowrap" set CleanUpFiles to "mesg nowrap" else if button returned of response is "OK" then set MesgFile to "mesg" set CleanUpFiles to "mesg" end if on error display dialog "Your message was not altered. Use Eudora to wrap the long lines." buttons {"OK"} default button "OK" tell EGPGLib to CleanUp(theFolder, "mesg") return end try else set MesgFile to "mesg" set CleanUpFiles to "mesg output mesg.asc" end if -- get GPG passphrase try set passphrase to askPassword "GPG Passphrase" on error display dialog "Never Mind" buttons {"OK"} default button "OK" tell EGPGLib to CleanUp(theFolder, CleanUpFiles) return end try -- set up GPG command and execute it via "do shell script" command set CleanUpFiles to CleanUpFiles & " output " & MesgFile & ".asc" set doGPG to "cd " & QuotedUnixDir & "; echo '" & passphrase & "' " &  "| /usr/local/bin/gpg --clearsign --passphrase-fd 0 -q --batch " & MesgFile & " >& output" try do shell script doGPG on error tell EGPGLib to set ErrorMesg to ReadUnixFile(theFolder & "output") display dialog "Could not sign the message. GPG Output:" & CR & CR & ErrorMesg tell EGPGLib to CleanUp(theFolder, CleanUpFiles) return end try set SignedFile to theFolder & MesgFile & ".asc" tell application "Finder" if (file SignedFile exists) then tell EGPGLib to set SignedMesg to ReadUnixFile(SignedFile) tell application "Eudora" to set (body of message 0) to SignedMesg else tell application "Eudora" to display dialog "File disappeared: " & SignedFile end if end tell tell EGPGLib to CleanUp(theFolder, CleanUpFiles) return