summaryrefslogtreecommitdiff
path: root/alot
diff options
context:
space:
mode:
authorDylan Baker <baker.dylan.c@gmail.com>2017-01-12 09:21:51 -0800
committerGitHub <noreply@github.com>2017-01-12 09:21:51 -0800
commit82e8cea7a99ffef14a0717715d32b8bf20a31957 (patch)
treeae2fc9d35b1c6eb74f7a91e758ec01fe4fa024fc /alot
parent5d2dad9c8e22ab6d40c6dd72e082bd50b17e85b7 (diff)
parent7fd9c2f09bb3425ad1af39470698a5622f6085a9 (diff)
Merge pull request #878 from meskio/encrypt_cc
Encrypt for the CC addresses too
Diffstat (limited to 'alot')
-rw-r--r--alot/commands/envelope.py24
-rw-r--r--alot/commands/globals.py39
-rw-r--r--alot/commands/utils.py42
3 files changed, 47 insertions, 58 deletions
diff --git a/alot/commands/envelope.py b/alot/commands/envelope.py
index 7ce553b6..d293a616 100644
--- a/alot/commands/envelope.py
+++ b/alot/commands/envelope.py
@@ -14,7 +14,7 @@ from twisted.internet.defer import inlineCallbacks
from . import Command, registerCommand
from . import globals
-from .utils import get_keys
+from .utils import set_encrypt
from .. import buffers
from .. import commands
from .. import crypto
@@ -563,27 +563,9 @@ class EncryptCommand(Command):
encrypt = False
elif self.action == 'toggleencrypt':
encrypt = not envelope.encrypt
- envelope.encrypt = encrypt
if encrypt:
- if not self.encrypt_keys:
- for recipient in envelope.headers['To'][0].split(','):
- if not recipient:
- continue
- match = re.search("<(.*@.*)>", recipient)
- if match:
- recipient = match.group(1)
- self.encrypt_keys.append(recipient)
-
- logging.debug("encryption keys: %s", self.encrypt_keys)
- keys = yield get_keys(ui, self.encrypt_keys,
- signed_only=self.trusted)
- if self.trusted:
- logging.debug("filtered encrytion keys: " +
- " ".join(x.uids[0].uid for x in keys.itervalues()))
- if keys:
- envelope.encrypt_keys.update(keys)
- else:
- envelope.encrypt = False
+ yield set_encrypt(ui, envelope, signed_only=self.trusted)
+ envelope.encrypt = encrypt
if not envelope.encrypt:
# This is an extra conditional as it can even happen if encrypt is
# True.
diff --git a/alot/commands/globals.py b/alot/commands/globals.py
index a9a85cba..498e78b5 100644
--- a/alot/commands/globals.py
+++ b/alot/commands/globals.py
@@ -7,7 +7,6 @@ import email
import glob
import logging
import os
-import re
import subprocess
from StringIO import StringIO
@@ -17,7 +16,7 @@ from twisted.internet import threads
from . import Command, registerCommand
from . import CommandCanceled
-from .utils import get_keys
+from .utils import set_encrypt
from .. import commands
from .. import buffers
@@ -873,12 +872,12 @@ class ComposeCommand(Command):
logging.debug("Trying to encrypt message because encrypt=%s and "
"encrypt_by_default=%s", self.encrypt,
account.encrypt_by_default)
- yield self._set_encrypt(ui, self.envelope)
+ yield set_encrypt(ui, self.envelope, block_error=self.encrypt)
elif account.encrypt_by_default == u"trusted":
logging.debug("Trying to encrypt message because "
"account.encrypt_by_default=%s",
account.encrypt_by_default)
- yield self._set_encrypt(ui, self.envelope, trusted_only=True)
+ yield set_encrypt(ui, self.envelope, block_error=self.encrypt, signed_only=True)
else:
logging.debug("No encryption by default, encrypt_by_default=%s",
account.encrypt_by_default)
@@ -888,38 +887,6 @@ class ComposeCommand(Command):
refocus=False)
ui.apply_command(cmd)
- @inlineCallbacks
- def _set_encrypt(self, ui, envelope, trusted_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 trusted_only: only add keys to the list of encryption
- keys whose uid is signed (trusted to belong to the key)
- :type trusted_only: bool
-
- """
- encrypt_keys = []
- for recipient in envelope.headers['To'][0].split(','):
- recipient = recipient.strip()
- if not recipient:
- continue
- match = re.search("<(.*@.*)>", recipient)
- if match:
- recipient = match.group(1)
- encrypt_keys.append(recipient)
-
- logging.debug("encryption keys: %s", encrypt_keys)
- keys = yield get_keys(ui, encrypt_keys, block_error=self.encrypt,
- signed_only=trusted_only)
- if keys:
- envelope.encrypt_keys.update(keys)
- envelope.encrypt = True
- else:
- envelope.encrypt = False
-
@registerCommand(
MODE, 'move', help='move focus in current buffer',
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.