Conflicts:
	INSTALL
	README.md
	gpg-mailgate.conf.sample
	gpg-mailgate.py
This commit is contained in:
perennate 2013-11-03 10:38:04 -05:00
commit 9ac151f438
4 changed files with 34 additions and 12 deletions

View file

@ -25,8 +25,8 @@ import random
import string
def public_keys( keyhome ):
cmd = '/usr/bin/gpg --homedir %s --list-keys --with-colons' % keyhome
p = subprocess.Popen( cmd.split(' '), stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE )
cmd = ['/usr/bin/gpg', '--homedir', keyhome, '--list-keys', '--with-colons']
p = subprocess.Popen( cmd, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE )
p.wait()
keys = list()
for line in p.stdout.readlines():

View file

@ -7,8 +7,19 @@ For installation instructions, please refer to the included INSTALL file.
# Features
- Correctly displays attachments and general email content; currently will only display first part of multipart messages
- Public keys can be stored in a dedicated gpg-home-directory (see Note 1 in INSTALL)
- Encrypts matching incoming and outgoing mode
- Encrypts both matching incoming and outgoing mail (this means gpg-mailgate can be used to encrypt outgoing mail for software that doesn't support PGP)
- Easy installation
- gpg-mailgate-web extension is a web interface allowing any user to upload PGP keys so that emails sent to them from your mail server will be encrypted (see gpg-mailgate-web directory for details)
This is forked from the original project at http://code.google.com/p/gpg-mailgate/
# Authors
This is a combined work of many developers:
* mcmaster <mcmaster@aphrodite.hurricanelabs.rsoc>
* Igor Rzegocki <ajgon@irgon.com> - [GitHub](https://github.com/ajgon/gpg-mailgate)
* perennate <admin@perennate.com> - [GitHub](https://github.com/uakfdotb/gpg-mailgate)
* Colin Moller <colin@unixarmy.com> - [GitHub](https://github.com/LeftyBC/gpg-mailgate)
* Taylor Hornby <havoc@defuse.ca> - [GitHub](https://github.com/defuse/gpg-mailgate)
* Martin (uragit) <uragit@telemage.com> - [GitHub](https://github.com/uragit/gpg-mailgate)

View file

@ -14,8 +14,9 @@ keymap_only = no
keyhome = /var/gpg/.gnupg
[logging]
# file to log to
# For logging to syslog. 'file = syslog', otherwise use path to the file.
file = /tmp/gpg-mailgate.log
#verbose = yes
[relay]
# the relay settings to use for Postfix

View file

@ -27,12 +27,7 @@ import re
import GnuPG
import smtplib
import sys
def appendLog(msg):
if cfg.has_key('logging') and cfg['logging'].has_key('file'):
log = open(cfg['logging']['file'], 'a')
log.write(msg + "\n")
log.close()
import syslog
# Read configuration from /etc/gpg-mailgate.conf
_cfg = RawConfigParser()
@ -43,6 +38,17 @@ for sect in _cfg.sections():
for (name, value) in _cfg.items(sect):
cfg[sect][name] = value
def log(msg):
if cfg.has_key('logging') and cfg['logging'].has_key('file'):
if cfg['logging']['file'] == "syslog":
syslog.syslog(syslog.LOG_INFO | syslog.LOG_MAIL, msg)
else:
logfile = open(cfg['logging']['file'], 'a')
logfile.write(msg + "\n")
logfile.close()
verbose=cfg.has_key('logging') and cfg['logging'].has_key('verbose') and cfg['logging']['verbose'] == 'yes'
# Read e-mail from stdin
raw = sys.stdin.read()
raw_message = email.message_from_string( raw )
@ -52,7 +58,7 @@ to_addrs = sys.argv[1:]
def send_msg( message, recipients = None ):
if recipients == None:
recipients = to_addrs
appendLog("Sending email to: <%s>" % '> <'.join( recipients ))
log("Sending email to: <%s>" % '> <'.join( recipients ))
relay = (cfg['relay']['host'], int(cfg['relay']['port']))
smtp = smtplib.SMTP(relay[0], relay[1])
smtp.sendmail( from_addr, recipients, message.as_string() )
@ -110,18 +116,22 @@ for to in to_addrs:
elif cfg.has_key('keymap') and cfg['keymap'].has_key(to):
gpg_to.append( (to, cfg['keymap'][to]) )
else:
if verbose:
log("Recipient (%s) not in domain list." % to)
ungpg_to.append(to)
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'
if verbose:
log("No encrypted recipients.")
send_msg( raw_message )
exit()
if ungpg_to != list():
send_msg( raw_message, ungpg_to )
appendLog("Encrypting email to: %s" % ' '.join( map(lambda x: x[0], gpg_to) ))
log("Encrypting email to: %s" % ' '.join( map(lambda x: x[0], gpg_to) ))
if cfg['default'].has_key('add_header') and cfg['default']['add_header'] == 'yes':
raw_message['X-GPG-Mailgate'] = 'Encrypted by GPG Mailgate'