diff --git a/gpg-mailgate.py b/gpg-mailgate.py index 9dcbe59..ada93b0 100755 --- a/gpg-mailgate.py +++ b/gpg-mailgate.py @@ -59,9 +59,15 @@ def gpg_encrypt( raw_message, recipients ): for fingerprint in keys: keys[fingerprint] = sanitize_case_sense(keys[fingerprint]) + # This list will be filled with pairs (M, N), where M is the destination + # address we're going to deliver the message to and N is the identity we're + # going to encrypt it for. gpg_to = list() + ungpg_to = list() + enc_keymap_only = conf.config_item_equals('default', 'enc_keymap_only', 'yes') + for to in recipients: # Check if recipient is in keymap @@ -75,16 +81,23 @@ def gpg_encrypt( raw_message, recipients ): LOG.info("Key '%s' in encrypt keymap not found in keyring for email address '%s'." % (conf.get_item('enc_keymap', to), to)) # Check if key in keychain is present - if to in keys.values() and not conf.config_item_equals('default', 'enc_keymap_only', 'yes'): - gpg_to.append( (to, to) ) - continue + if not enc_keymap_only: + if to in keys.values(): + gpg_to.append( (to, to) ) + continue + + # If this is an address with a delimiter (i.e. "foo+bar@example.com"), + # then strip whatever is found after the delimiter and try this address. + (newto, topic) = text.parse_delimiter(to) + if newto in keys.values(): + gpg_to.append((to, newto)) # Check if there is a default key for the domain splitted_to = to.split('@') if len(splitted_to) > 1: domain = splitted_to[1] if conf.config_item_set('enc_domain_keymap', domain): - LOG.info("Encrypt domain keymap has key '%s'" % conf.get_item('enc_dec_keymap', domain) ) + LOG.info("Encrypt domain keymap has key '%s'" % conf.get_item('enc_domain_keymap', domain) ) # Check we've got a matching key! if conf.get_item('enc_domain_keymap', domain) in keys: LOG.info("Using default domain key for recipient '%s'" % to) diff --git a/test/e2e.ini b/test/e2e.ini index e6ba7c7..9513ad8 100644 --- a/test/e2e.ini +++ b/test/e2e.ini @@ -30,7 +30,7 @@ certs: test/certs [tests] # Number of "test-*" sections in this file, describing test cases. -cases: 7 +cases: 8 e2e_log: test/logs/e2e.log e2e_log_format: %(asctime)s %(pathname)s:%(lineno)d %(levelname)s [%(funcName)s] %(message)s e2e_log_datefmt: %Y-%m-%d %H:%M:%S @@ -78,3 +78,9 @@ descr: Clear text message to a user with an RSA key and PGP/MIME enabled in conf to: evan@disposlab in: test/msgin/clear2rsa2.msg out: -----BEGIN PGP MESSAGE----- + +[case-8] +descr: Clear text message to address with delimiter and a user with an Ed25519 key. +to: bob@disposlab +in: test/msgin/clear2ed-delim.msg +out: -----BEGIN PGP MESSAGE----- diff --git a/test/msgin/clear2ed-delim.msg b/test/msgin/clear2ed-delim.msg new file mode 100644 index 0000000..3fa6a32 --- /dev/null +++ b/test/msgin/clear2ed-delim.msg @@ -0,0 +1,5 @@ +From: Dave +To: Bob +Subject: Test + +Body of the message.