Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from twisted.mail import smtp
- from zope.interface import implements
- from twisted.internet import reactor, defer
- class NullMessage(object):
- implements(smtp.IMessage)
- def lineReceived(self, line):
- pass
- def eomReceived(self):
- return defer.succeed(None)
- def connectionLost(self):
- pass
- class FileMessage(object):
- implements(smtp.IMessage)
- def __init__(self, fileObj):
- self.fileObj = fileObj
- self.msg = []
- self.envelope_recipients = []
- def lineReceived(self, line):
- self.fileObj.write(line + '\n')
- self.msg.append(line)
- def eomReceived(self):
- self.fileObj.close()
- print "\n".join(self.msg)
- print self.envelope_recipients
- return defer.succeed(None)
- def connectionLost(self):
- self.fileObj.close()
- os.remove(self.fileObj.name)
- def add_envelope_recipient(self, user):
- self.envelope_recipients.append(user)
- class MUMessageDelivery(object):
- implements(smtp.IMessageDelivery)
- def __init__(self):
- import time
- fileName = 'smtplog.' + str(int(time.time()))
- self.fm = FileMessage(file(fileName, 'w'))
- self.to = []
- def receivedHeader(self, helo, origin, recipients):
- return ''
- def validateFrom(self, helo, origin):
- return origin
- def validateTo(self, user):
- self.fm.add_envelope_recipient(user.dest)
- if self.to:
- self.to.append(user)
- return NullMessage
- else:
- self.to = [user]
- return self.fm
- class MUMessageDeliveryFactory(object):
- implements(smtp.IMessageDeliveryFactory)
- def getMessageDelivery(self):
- return MUMessageDelivery()
- class MU_ESMTPFactory(smtp.SMTPFactory):
- protocol = MU_ESMTP
- def buildProtocol(self, addr):
- proto = smtp.SMTPFactory.buildProtocol(self, addr)
- proto.deliveryFactory = MUMessageDeliveryFactory()
- return proto
- reactor.listenTCP(8123, MU_ESMTPFactory())
- reactor.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement