From 4283c7ef4dad8f73c41ba06773fc5263a9816c97 Mon Sep 17 00:00:00 2001 From: fkrone Date: Sun, 29 Mar 2015 18:16:58 +0200 Subject: [PATCH] Prefere keys in keymap over keys in keyring. Could be useful if you have a recipient with two keys. --- gpg-mailgate.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/gpg-mailgate.py b/gpg-mailgate.py index 766d473..a8738bf 100755 --- a/gpg-mailgate.py +++ b/gpg-mailgate.py @@ -79,16 +79,18 @@ def gpg_encrypt( raw_message, recipients ): for to in recipients: + # Check if recipient is in keymap + if get_bool_from_cfg('keymap', to): + log("Keymap has key '%s'" % cfg['keymap'][to]) + # Check we've got a matching key! + if cfg['keymap'][to] in keys: + gpg_to.append( (to, cfg['keymap'][to]) ) + continue + else: + log("Key '%s' in keymap not found in keyring for email address '%s'." % (cfg['keymap'][to], to)) + if to in keys.values() and not get_bool_from_cfg('default', 'keymap_only', 'yes'): gpg_to.append( (to, to) ) - elif get_bool_from_cfg('keymap') and to in cfg['keymap']: - log("Keymap has key '%s'" % cfg['keymap'][to] ) - # Check we've got a matching key! If not, decline to attempt encryption. - if not cfg['keymap'][to] in keys: - log("Key '%s' in keymap not found in keyring for email address '%s'. Won't encrypt." % (cfg['keymap'][to], to)) - ungpg_to.append(to) - else: - gpg_to.append( (to, cfg['keymap'][to]) ) else: if verbose: log("Recipient (%s) not in PGP domain list." % to)