Last active
June 13, 2016 10:02
-
-
Save tachesimazzoca/8330625 to your computer and use it in GitHub Desktop.
Python SMTP Debugging Server #python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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