Skip to content

Instantly share code, notes, and snippets.

@yucer
Forked from tachesimazzoca/debug-smtpd
Created February 11, 2016 16:26
Show Gist options
  • Save yucer/e57bf89bebbff76a956c to your computer and use it in GitHub Desktop.
Save yucer/e57bf89bebbff76a956c to your computer and use it in GitHub Desktop.
Python SMTP Debugging Server #python
#!/usr/bin/python
import asyncore
import logging
import smtpd
import sys
log = logging.getLogger('debug-smtpd')
class LoggingSMTPServer(smtpd.SMTPServer):
def process_message(self, peer, mailfrom, rcpttos, data):
inheaders = 1
lines = data.split('\n')
log.info('---------- MESSAGE FOLLOWS ----------')
for line in lines:
if inheaders and not line:
log.info('X-Peer:' + peer[0])
inheaders = 0
log.info(line)
log.info('------------ END MESSAGE ------------')
def main():
try:
opts = dict(format="%(asctime)s %(levelname)s %(message)s",
level=logging.INFO)
logging.basicConfig(**opts)
LoggingSMTPServer(('localhost', 1025), None)
asyncore.loop()
except KeyboardInterrupt:
pass
return 0
if __name__ == '__main__':
sys.exit(main())
#!/bin/bash
#
# chkconfig: 2345 80 30
#
# description: Python smtp.DebuggingServer daemon
# processname: debug-smtpd
#
. /etc/rc.d/init.d/functions
prog="debug-smtpd"
lockfile="/var/lock/subsys/${prog}"
logfile="/var/log/${prog}.log"
RETVAL=0
start() {
echo -n $"Starting ${prog}: "
daemon --check "$prog" "nohup ${prog} >> ${logfile} 2>&1 &"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch ${lockfile}
}
stop() {
echo -n $"Stopping ${prog}: "
killproc ${prog}
echo
[ $RETVAL -eq 0 ] && rm -f ${lockfile}
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|force-reload|reload)
restart
;;
condrestart|try-restart)
[ -f "$lockfile" ] && restart
;;
status)
status "$prog"
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart}"
exit 1
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment