2015-01-29 | Max

Read Apple-Mails strange gpg

Using gpg to secure your communication is great. It would also be great to end this topic at this point but I guess an unwritten law in end user cryptology is: "It would not be secure if it was not somehow obscure and user unfriendly."

The Problem:

Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;

If you receive a pgp encrypted mail from Apple users it will not only have a obscure char set encoding it will also be encoded as quoted-printable before the encryption with gpg. This results in a lot of pain for e.g. German mails. Not only newlines (=20) will look great also the umlauts ä (=E4) ü (=FC) and so on will be terrible for reading after decryption.

The first step to get rid of this is to convert the quoted printable stuff into a more human friendly format - luckily Perl can do this for us. Afterwards it is nice to convert the resulting string into UTF-8 - e.g. with iconv. This all can be assembled into a pretty simple shell script:


# Convert Apple Mail gpg into nice format.

gpg --decrypt $1 | perl -pe 'use MIME::QuotedPrint; $_=MIME::QuotedPrint::decode($_);' | iconv -f WINDOWS-1252 -t UTF-8 >> $1

Great! You just throw the file with the PGP blob into the script and it appends it in a human readable text - even if it came from Apple Mail...