diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2013-02-19 10:11:11 +0000 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2013-02-19 10:11:11 +0000 |
commit | ae4a4b28c2f461219344c2b8503dab2a9a8c1d3b (patch) | |
tree | eb2c19eaf288c6812158610ee496db0c0e1e8d39 /alot/db/envelope.py | |
parent | 17ac6c9539986f3a8e3c079e7cfe56812d7da384 (diff) | |
parent | 15cd4894ed3ad9a9b16484ea0b1dc58e6975040f (diff) |
Merge branch '0.3.3-feature-cryptomails-543'
Diffstat (limited to 'alot/db/envelope.py')
-rw-r--r-- | alot/db/envelope.py | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/alot/db/envelope.py b/alot/db/envelope.py index 96abbd40..2e8f0366 100644 --- a/alot/db/envelope.py +++ b/alot/db/envelope.py @@ -58,6 +58,7 @@ class Envelope(object): self.sign = sign self.sign_key = sign_key self.encrypt = encrypt + self.encrypt_keys = {} self.tags = tags # tags to add after successful sendout self.sent_time = None self.modified_since_sent = False @@ -188,8 +189,9 @@ class Envelope(object): raise GPGProblem(str(e)) micalg = crypto.RFC3156_micalg_from_algo(signatures[0].hash_algo) - outer_msg = MIMEMultipart('signed', micalg=micalg, - protocol='application/pgp-signature') + unencrypted_msg = MIMEMultipart('signed', micalg=micalg, + protocol= + 'application/pgp-signature') # wrap signature in MIMEcontainter stype = 'pgp-signature; name="signature.asc"' @@ -200,11 +202,40 @@ 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) + + try: + encrypted_str = crypto.encrypt(plaintext, + self.encrypt_keys.values()) + 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 |