Some new stuff

This commit is contained in:
root 2010-01-21 09:50:51 -05:00
parent 93556ed3bf
commit 05ecc05b34
1 changed files with 13 additions and 9 deletions

View File

@ -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 )