Skip to content

Instantly share code, notes, and snippets.

@MarkusH
Created May 23, 2015 13:47
Show Gist options
  • Save MarkusH/ad955fb094007cc9be24 to your computer and use it in GitHub Desktop.
Save MarkusH/ad955fb094007cc9be24 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import print_function
from smtpd import SMTPServer
import asyncore
import quopri
class DebuggingServer(SMTPServer):
def process_message(self, peer, mailfrom, rcpttos, data):
inheaders = 1
lines = data.split('\n')
print('---------- MESSAGE FOLLOWS ----------')
for line in lines:
if inheaders and not line:
print('X-Peer: %s' % peer[0])
inheaders = 0
if line.endswith('='):
print(quopri.decodestring(line[:-1]), end='')
else:
print(quopri.decodestring(line))
print('------------ END MESSAGE ------------')
if __name__ == '__main__':
server = DebuggingServer(('127.0.0.1', 1025), None)
print('Listening on 127.0.0.1:1025')
asyncore.loop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment