leapcode/leap_mail — pull request #49 by andrejb (2013-10-07 16:11:40+00:00)
Title: Bug/3775 keymanager fails to check signature for an email attachment

The code implements RFC 3156 multipart/encrypted and multipart/signed MIME encapsulation in SMTP relay and IMAP.

As the SMTP relay does not have access to the raw contents of the message before it is sent (i.e. it 'intercepts' the message to encrypt/sign it), I had to devise a way to select specific headers to be kept in the encrypted message, while all other headers are moved to the new multipart/encrypted or multipart/signed message. Selected headers were: 'content-type', 'mime-version', 'content-disposition' and 'content-transfer-encoding'. I found that these are enough to describe the MIME message, but please tell me if there are other headers we should maintain in the original messages.

If an arriving message has been encrypted before being sent, then the MX will encrypt it again, and IMAP has to handle that case. So I also changed IMAP to decrypt incoming multipart/encrypted messages in a second pass.