Skip to content

Instantly share code, notes, and snippets.

@gaker
Created May 1, 2012 22:43
Show Gist options
  • Save gaker/2572077 to your computer and use it in GitHub Desktop.
Save gaker/2572077 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""
Like the built-in debugging server, but unwarps long lines for easier
copy/paste of URLs.
# Source: http://djangosnippets.org/snippets/2367/
"""
from __future__ import print_function
import argparse
import os
from smtpd import SMTPServer
class DebuggingServer(SMTPServer):
def process_message(self, peer, mailfrom, rcpttos, data):
inheaders = 1
lines = data.split('\n')
print('---------- MESSAGE FOLLOWS ----------')
for line in lines:
# headers first
if inheaders and not line:
print('X-Peer:', peer[0])
inheaders = 0
if line.endswith('='):
print(line[:-1], end='')
else:
print(line)
print('------------ END MESSAGE ------------')
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Run a debugging SMTP Server')
parser.add_argument('--port', type=str, default="1025", dest='port',
help="Run on a given port. Default is 1025")
args = parser.parse_args()
print('Debugging SMTP Server started on port {0}'.format(
args.port))
print('Quit the server with CONTROL-C.')
os.system("python -m smtpd -n -c DebuggingServer localhost:{0}"\
.format(args.port))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment