diff options
author | Ruben Pollan <meskio@sindominio.net> | 2017-09-25 20:22:30 +0200 |
---|---|---|
committer | Ruben Pollan <meskio@sindominio.net> | 2017-09-26 08:49:16 +0200 |
commit | 7cd3cff8d858e411f8d84361d5a4bc6133c86d0e (patch) | |
tree | 61a9af9ac906185aa61581f0919c830dc87730d7 | |
parent | 5904b86d09edb888c80f8f8ba7f1b2e18baf456a (diff) |
commands/util: encrypt to self
Add account configuration variable 'encrypt_to_self' that if true when
encrypting a message it will also be encrypted with the key defined for
this account.
Fixes #1140
-rw-r--r-- | alot/account.py | 7 | ||||
-rw-r--r-- | alot/commands/utils.py | 15 |
2 files changed, 20 insertions, 2 deletions
diff --git a/alot/account.py b/alot/account.py index b1223902..a4ce439a 100644 --- a/alot/account.py +++ b/alot/account.py @@ -190,6 +190,8 @@ class Account(object): """regex matching alternative addresses""" realname = None """real name used to format from-headers""" + encrypt_to_self = None + """encrypt outgoing encrypted emails to this account's private key""" gpg_key = None """gpg fingerprint for this account's private key""" signature = None @@ -207,8 +209,8 @@ class Account(object): signature_filename=None, signature_as_attachment=False, sent_box=None, sent_tags=None, draft_box=None, draft_tags=None, abook=None, sign_by_default=False, - encrypt_by_default=u"none", case_sensitive_username=False, - **_): + encrypt_by_default=u"none", encrypt_to_self=None, + case_sensitive_username=False, **_): sent_tags = sent_tags or [] if 'sent' not in sent_tags: sent_tags.append('sent') @@ -221,6 +223,7 @@ class Account(object): for a in (aliases or [])] self.alias_regexp = alias_regexp self.realname = realname + self.encrypt_to_self = encrypt_to_self self.gpg_key = gpg_key self.signature = signature self.signature_filename = signature_filename diff --git a/alot/commands/utils.py b/alot/commands/utils.py index 1bf64cbb..7e4e0307 100644 --- a/alot/commands/utils.py +++ b/alot/commands/utils.py @@ -9,6 +9,8 @@ import logging from twisted.internet.defer import inlineCallbacks, returnValue from ..errors import GPGProblem, GPGCode +from ..settings.const import settings +from ..settings.errors import NoMatchingAccount from .. import crypto @@ -46,6 +48,19 @@ def set_encrypt(ui, envelope, block_error=False, signed_only=False): if keys: envelope.encrypt_keys.update(keys) envelope.encrypt = True + + if 'From' in envelope.headers: + try: + acc = settings.get_account_by_address(envelope['From']) + if acc.encrypt_to_self: + if acc.gpg_key: + logging.debug('encrypt to self: %s', acc.gpg_key.fpr) + envelope.encrypt_keys[acc.gpg_key.fpr] = acc.gpg_key + else: + logging.debug('encrypt to self: no gpg_key in account') + except NoMatchingAccount: + logging.debug('encrypt to self: no account found') + else: envelope.encrypt = False |