diff options
author | Johannes Kulick <kulick@hildensia.de> | 2012-12-11 18:26:06 +0100 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2013-02-19 10:10:07 +0000 |
commit | 79796e8ae9c21561be8571d4a1c6324555022387 (patch) | |
tree | c3c366ac1a639f0d3cdc069cb3cb86d6b2162e2b /alot/db | |
parent | 3e1cc0427aee38ad7fdcff64d6346016fd53d5c8 (diff) |
create PGP/MIME mail, if encrypt flag is set
If the envelope has the encrypt flag set we encrypt the (signed if available)
mail and create a PGP/MIME compliant mail
TODOs:
a) create a 'This is a PGP/MIME encrypted mail...' warning on top of all
multipart parts
b) find the correct key for encryption
c) find a way to handle multiple recipients
Diffstat (limited to 'alot/db')
-rw-r--r-- | alot/db/envelope.py | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/alot/db/envelope.py b/alot/db/envelope.py index 96abbd40..7c3668cc 100644 --- a/alot/db/envelope.py +++ b/alot/db/envelope.py @@ -188,7 +188,7 @@ class Envelope(object): raise GPGProblem(str(e)) micalg = crypto.RFC3156_micalg_from_algo(signatures[0].hash_algo) - outer_msg = MIMEMultipart('signed', micalg=micalg, + unencrypted_msg = MIMEMultipart('signed', micalg=micalg, protocol='application/pgp-signature') # wrap signature in MIMEcontainter @@ -200,11 +200,42 @@ class Envelope(object): signature_mime.set_charset('us-ascii') # add signed message and signature to outer message - outer_msg.attach(inner_msg) - outer_msg.attach(signature_mime) - outer_msg['Content-Disposition'] = 'inline' + unencrypted_msg.attach(inner_msg) + unencrypted_msg.attach(signature_mime) + unencrypted_msg['Content-Disposition'] = 'inline' else: - outer_msg = inner_msg + unencrypted_msg = inner_msg + + if self.encrypt: + plaintext = crypto.email_as_string(unencrypted_msg) + logging.debug('encrypting plaintext: ' + plaintext) + + # TODO: find the correct key, or ask user + key = crypto.get_key('recipient') + + try: + encrypted_str = crypto.encrypt(plaintext, key) + except gpgme.GpgmeError as e: + raise GPGProblem(str(e)) + + outer_msg = MIMEMultipart('encrypted', + protocol='application/pgp-encrypted') + + version_str = 'Version: 1' + encryption_mime = MIMEApplication(_data=version_str, + _subtype='pgp-encrypted', + _encoder=encode_7or8bit) + encryption_mime.set_charset('us-ascii') + + encrypted_mime = MIMEApplication(_data=encrypted_str, + _subtype='octet-stream', + _encoder=encode_7or8bit) + encrypted_mime.set_charset('us-ascii') + outer_msg.attach(encryption_mime) + outer_msg.attach(encrypted_mime) + + else: + outer_msg = unencrypted_msg headers = self.headers.copy() # add Message-ID |