diff options
author | Ruben Pollan <meskio@sindominio.net> | 2016-07-04 20:20:11 +0200 |
---|---|---|
committer | Ruben Pollan <meskio@sindominio.net> | 2017-01-01 11:09:38 +0100 |
commit | 7fd9c2f09bb3425ad1af39470698a5622f6085a9 (patch) | |
tree | 071944910f12de471f76a3163b919fe1f7561e22 /alot/commands/utils.py | |
parent | f1631cf288cbcd2d513a93348e28cea41fd92913 (diff) |
Encrypt for the CC addresses too
Diffstat (limited to 'alot/commands/utils.py')
-rw-r--r-- | alot/commands/utils.py | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/alot/commands/utils.py b/alot/commands/utils.py index 7249b9ee..3239f865 100644 --- a/alot/commands/utils.py +++ b/alot/commands/utils.py @@ -1,6 +1,8 @@ # Copyright (C) 2015 Patrick Totzke <patricktotzke@gmail.com> # This file is released under the GNU GPL, version 3 or a later revision. # For further details see the COPYING file +import re +import logging from twisted.internet.defer import inlineCallbacks, returnValue from ..errors import GPGProblem, GPGCode @@ -8,7 +10,45 @@ from .. import crypto @inlineCallbacks -def get_keys(ui, encrypt_keyids, block_error=False, signed_only=False): +def set_encrypt(ui, envelope, block_error=False, signed_only=False): + """Find and set the encryption keys in an envolope. + + :param ui: the main user interface object + :type ui: alot.ui.UI + :param envolope: the envolope buffer object + :type envolope: alot.buffers.EnvelopeBuffer + :param block_error: wether error messages for the user should expire + automatically or block the ui + :type block_error: bool + :param signed_only: only use keys whose uid is signed (trusted to belong + to the key) + :type signed_only: bool + """ + encrypt_keys = [] + for header in ('To', 'Cc'): + if header not in envelope.headers: + continue + + for recipient in envelope.headers[header][0].split(','): + if not recipient: + continue + match = re.search("<(.*@.*)>", recipient) + if match: + recipient = match.group(1) + encrypt_keys.append(recipient) + + logging.debug("encryption keys: " + str(encrypt_keys)) + keys = yield _get_keys(ui, encrypt_keys, block_error=block_error, + signed_only=signed_only) + if keys: + envelope.encrypt_keys.update(keys) + envelope.encrypt = True + else: + envelope.encrypt = False + + +@inlineCallbacks +def _get_keys(ui, encrypt_keyids, block_error=False, signed_only=False): """Get several keys from the GPG keyring. The keys are selected by keyid and are checked if they can be used for encryption. |