From 05ecc05b34e8e134bf467bf612488b9f2095b36d Mon Sep 17 00:00:00 2001 From: root Date: Thu, 21 Jan 2010 09:50:51 -0500 Subject: [PATCH] Some new stuff --- gpg-mailgate.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/gpg-mailgate.py b/gpg-mailgate.py index 72710b3..dad0a36 100755 --- a/gpg-mailgate.py +++ b/gpg-mailgate.py @@ -32,12 +32,17 @@ def send_msg( message, recipients = None ): recipients = to_addrs if cfg.has_key('logging') and cfg['logging'].has_key('file'): log = open(cfg['logging']['file'], 'a') - log.write("Sending email to: %s\n" % ' '.join( recipients )) + log.write("Sending email to: <%s>\n" % '> <'.join( recipients )) log.close() relay = (cfg['relay']['host'], int(cfg['relay']['port'])) smtp = smtplib.SMTP(relay[0], relay[1]) smtp.sendmail( from_addr, recipients, message.as_string() ) +def get_msg( message ): + if not message.is_multipart(): + return message.get_payload() + return '\n\n'.join( message.get_payload() ) + gpg_to = list() ungpg_to = list() keys = GnuPG.public_keys( cfg['gpg']['keyhome'] ) @@ -55,7 +60,6 @@ if gpg_to == list(): if cfg['default'].has_key('add_header') and cfg['default']['add_header'] == 'yes': raw_message['X-GPG-Mailgate'] = 'Not encrypted, public key not found' send_msg( raw_message ) - sys.exit(0) if ungpg_to != list(): send_msg( raw_message, ungpg_to ) @@ -67,8 +71,13 @@ if raw_message.is_multipart(): payload.append(part) raw_message.set_payload( payload ) +if cfg.has_key('logging') and cfg['logging'].has_key('file'): + log = open(cfg['logging']['file'], 'a') + log.write("Encrypting email to: %s\n" % ' '.join( map(lambda x: x[0], gpg_to) )) + log.close() + if cfg['default'].has_key('add_header') and cfg['default']['add_header'] == 'yes': - raw_message['X-GPG-Mailgate'] = 'Encrypted by GPG Mailgate 0.2' + raw_message['X-GPG-Mailgate'] = 'Encrypted by GPG Mailgate' gpg_to_cmdline = list() gpg_to_smtp = list() @@ -76,12 +85,7 @@ for rcpt in gpg_to: gpg_to_smtp.append(rcpt[0]) gpg_to_cmdline.extend(rcpt[1].split(',')) -if cfg.has_key('logging') and cfg['logging'].has_key('file'): - log = open(cfg['logging']['file'], 'a') - log.write("Encrypting email to: %s\n" % ', '.join( gpg_to_cmdline )) - log.close() - gpg = GnuPG.GPGEncryptor( cfg['gpg']['keyhome'], gpg_to_cmdline ) -gpg.update( raw_message.get_payload() ) +gpg.update( get_msg(raw_message) ) raw_message.set_payload( gpg.encrypt() ) send_msg( raw_message, gpg_to_smtp )