and if remoteport is not given, then 25 is used.
"""
-\f
+
# Overview:
#
# This file implements the minimal SMTP protocol as defined in RFC 821. It
COMMASPACE = ', '
-\f
+
def usage(code, msg=''):
print >> sys.stderr, __doc__ % globals()
if msg:
sys.exit(code)
-\f
+
class SMTPChannel(asynchat.async_chat):
COMMAND = 0
DATA = 1
if not address:
self.push('501 Syntax: RCPT TO: <address>')
return
- if address.lower().startswith('stimpy'):
- self.push('503 You suck %s' % address)
- return
self.__rcpttos.append(address)
print >> DEBUGSTREAM, 'recips:', self.__rcpttos
self.push('250 Ok')
self.push('354 End data with <CR><LF>.<CR><LF>')
-\f
+
class SMTPServer(asyncore.dispatcher):
def __init__(self, localaddr, remoteaddr):
self._localaddr = localaddr
raise NotImplementedError
-\f
+
class DebuggingServer(SMTPServer):
# Do something with the gathered message
def process_message(self, peer, mailfrom, rcpttos, data):
print '------------ END MESSAGE ------------'
-\f
+
class PureProxy(SMTPServer):
def process_message(self, peer, mailfrom, rcpttos, data):
lines = data.split('\n')
data = NEWLINE.join(lines)
refused = self._deliver(mailfrom, rcpttos, data)
# TBD: what to do with refused addresses?
- print >> DEBUGSTREAM, 'we got some refusals'
+ print >> DEBUGSTREAM, 'we got some refusals:', refused
def _deliver(self, mailfrom, rcpttos, data):
import smtplib
return refused
-\f
+
class MailmanProxy(PureProxy):
def process_message(self, peer, mailfrom, rcpttos, data):
from cStringIO import StringIO
if rcpttos:
refused = self._deliver(mailfrom, rcpttos, data)
# TBD: what to do with refused addresses?
- print >> DEBUGSTREAM, 'we got refusals'
+ print >> DEBUGSTREAM, 'we got refusals:', refused
# Now deliver directly to the list commands
mlists = {}
s = StringIO(data)
msg.Enqueue(mlist, torequest=1)
-\f
+
class Options:
setuid = 1
classname = 'PureProxy'
-\f
+
def parseargs():
global DEBUGSTREAM
try:
return options
-\f
+
if __name__ == '__main__':
options = parseargs()
# Become nobody