-- Eudora-GPG-Decrypt 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: fixed checking that temp file already exists -- 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. Extra CR before "END GPG DECRYPTED MESSAGE" for text missing final CR. (Thanks: Julian Koh) -- 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. Uses -v (verbose) option in gpg instead of -q (quiet) since some -- people are not getting any output when decrypting -- 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 -- 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 WriteUnixFile(theFolder & "mesg.asc", OriginalMesg) -- 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, "mesg.asc") return end try -- set up GPG command and execute it via "do shell script" command set doGPG to "cd " & QuotedUnixDir & "; echo '" & passphrase & "' " &  "| /usr/local/bin/gpg --passphrase-fd 0 -v --batch -o mesg --decrypt mesg.asc >& output" set CleanUpFiles to "mesg.asc output mesg" try do shell script doGPG on error tell EGPGLib to set ErrorMesg to ReadUnixFile(theFolder & "output") tell me to display dialog "Could not decrypt the message. GPG Output:" & CR & CR & ErrorMesg tell EGPGLib to CleanUp(theFolder, CleanUpFiles) return end try set DecryptedFile to theFolder & "mesg" set OutputFile to theFolder & "output" tell application "Finder" if ((file DecryptedFile exists) and (file OutputFile exists)) then tell EGPGLib set DecryptedMesg to ReadUnixFile(DecryptedFile) set response to ReadUnixFile(OutputFile) end tell set separator1 to "-----BEGIN GPG OUTPUT-----" & CR set separator2 to "-----END GPG OUTPUT-----" & CR set separator3 to "-----BEGIN GPG DECRYPTED MESSAGE-----" & CR set separator4 to CR & "-----END GPG DECRYPTED MESSAGE -----" & CR tell application "Eudora" to set (body of message 0) to  separator3 & DecryptedMesg & separator4 & CR & separator1 & response & separator2 else tell application "Eudora" to display dialog "A file disappeared: " & DecryptedFile & " or " & OutputFile end if end tell tell EGPGLib to CleanUp(theFolder, CleanUpFiles) return