2022-07-24 Decrypting MIME multipart messages in Rmail

I should be packing…

I get mail like this, in RMAIL:

Content-Type: multipart/encrypted; protocol="application/pgp-encrypted"; boundary="------3731fd63500a99617c474bca321ff6f77b018f081ec247a77a67f22adcd57eed"; charset=utf-8

[1:application/pgp-encrypted Show Save:noname (11B)]

[2:application/octet-stream Show Save:encrypted.asc (9kB)]

No problem, this is an encrypted email, but with multiple parts.

I run `rmail-epa-decrypt` and “replace the original message” to get the following:

Content-Type: multipart/encrypted; protocol="application/pgp-encrypted"; boundary="------3731fd63500a99617c474bca321ff6f77b018f081ec247a77a67f22adcd57eed"; charset=utf-8

This is an OpenPGP/MIME encrypted message (RFC 4880 and 3156)
--------3731fd63500a99617c474bca321ff6f77b018f081ec247a77a67f22adcd57eed
Content-Type: application/pgp-encrypted
Content-Description: PGP/MIME version identification

Version: 1

--------3731fd63500a99617c474bca321ff6f77b018f081ec247a77a67f22adcd57eed
Content-Type: application/octet-stream; name="encrypted.asc"
Content-Description: OpenPGP encrypted message
Content-Disposition: inline; filename="encrypted.asc"

Content-Type: multipart/mixed;boundary=---------------------6afc1cb4a8cd500fac78c43304496efd

-----------------------6afc1cb4a8cd500fac78c43304496efd
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;charset=utf-8

Hi Alex,
…

Now this is broken! Notice in the middle, there are headers for the part with name=”encrypted.asc”, followed by an empty line, and then different headers: something about multipart/mixed, with a different boundary. And as you can see, the next part uses exactly this boundary.

So what’s actually required is for the first three header lines and the empty line to be removed so that this message is once again a correctly nested MIME message.

I edit the message (`e`) and remove the four lines above “Content-Type: multipart/mixed”:

Content-Type: multipart/encrypted; protocol="application/pgp-encrypted"; boundary="------3731fd63500a99617c474bca321ff6f77b018f081ec247a77a67f22adcd57eed"; charset=utf-8

This is an OpenPGP/MIME encrypted message (RFC 4880 and 3156)
--------3731fd63500a99617c474bca321ff6f77b018f081ec247a77a67f22adcd57eed
Content-Type: application/pgp-encrypted
Content-Description: PGP/MIME version identification

Version: 1

--------3731fd63500a99617c474bca321ff6f77b018f081ec247a77a67f22adcd57eed
Content-Type: multipart/mixed;boundary=---------------------6afc1cb4a8cd500fac78c43304496efd

-----------------------6afc1cb4a8cd500fac78c43304496efd
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;charset=utf-8

Hi Alex,

Save using `C-c C-c` and now I have a readable, decrypted, multipart MIME message where I can navigate between the various parts:

Content-Type: multipart/encrypted; protocol="application/pgp-encrypted"; boundary="------3731fd63500a99617c474bca321ff6f77b018f081ec247a77a67f22adcd57eed"; charset=utf-8

[1:application/pgp-encrypted Show Save:noname (11B)]

[2:multipart/mixed Hide]

[2/1:text/plain Hide]

Hi Alex,
…

Every. Single. Time.

How awkward. 😬

​#Emacs ​#Rmail ​#Cryptography