summaryrefslogtreecommitdiff
path: root/alot/commands/envelope.py
diff options
context:
space:
mode:
authorAndre Bianchi <drebs@riseup.net>2018-10-11 11:18:22 -0300
committerAndre Bianchi <drebs@riseup.net>2018-10-16 22:15:04 -0300
commit6acea172e02f9c30712bbf8ae9a81656c67ff3c5 (patch)
tree596746b2f294df2198ebeb6210ac9ff4bee3e350 /alot/commands/envelope.py
parentac3129c80d72825464eb018c7f9a02f31fc68d98 (diff)
Check set of encryption keys before sending
Closes: #1232
Diffstat (limited to 'alot/commands/envelope.py')
-rw-r--r--alot/commands/envelope.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/alot/commands/envelope.py b/alot/commands/envelope.py
index 90e43e32..c442fbd7 100644
--- a/alot/commands/envelope.py
+++ b/alot/commands/envelope.py
@@ -168,6 +168,23 @@ class SendCommand(Command):
self.envelope = envelope
self.envelope_buffer = None
+ def _get_keys_addresses(self):
+ addresses = set()
+ for key in self.envelope.encrypt_keys.values():
+ for uid in key.uids:
+ addresses.add(uid.email)
+ return addresses
+
+ def _get_recipients_addresses(self):
+ tos = self.envelope.headers.get('To', [])
+ ccs = self.envelope.headers.get('Cc', [])
+ return {a for (_, a) in email.utils.getaddresses(tos + ccs)}
+
+ def _is_encrypted_to_all_recipients(self):
+ recipients_addresses = self._get_recipients_addresses()
+ keys_addresses = self._get_keys_addresses()
+ return recipients_addresses.issubset(keys_addresses)
+
async def apply(self, ui):
if self.mail is None:
if self.envelope is None:
@@ -205,6 +222,18 @@ class SendCommand(Command):
msg_position='left')) == 'no':
return
+ # Check if an encrypted message is indeed encrypted to all its
+ # recipients.
+ if (self.envelope.encrypt
+ and not self._is_encrypted_to_all_recipients()):
+ warning = textwrap.dedent("""\
+ Message is not encrypted to all recipients. This means that
+ not everyone will be able to decode and read this message.
+ Do you want to send anyway?""").replace('\n', ' ')
+ if (await ui.choice(warning, cancel='no',
+ msg_position='left')) == 'no':
+ return
+
clearme = ui.notify(u'constructing mail (GPG, attachments)\u2026',
timeout=-1)