2
# Twisted, the Framework of Your Internet
3
# Copyright (C) 2001 Matthew W. Lefkowitz
5
# This library is free software; you can redistribute it and/or
6
# modify it under the terms of version 2.1 of the GNU Lesser General Public
7
# License as published by the Free Software Foundation.
9
# This library is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
# Lesser General Public License for more details.
14
# You should have received a copy of the GNU Lesser General Public
15
# License along with this library; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
from twisted.internet import defer
23
from twisted.protocols import smtp
25
class ConsoleMessageDelivery:
26
__implements__ = (smtp.IMessageDelivery,)
28
def receivedHeader(self, helo, origin, recipients):
29
return "Received: ConsoleMessageDelivery"
31
def validateFrom(self, helo, origin):
32
# All addresses are accepted
35
def validateTo(self, user):
36
# Only messages directed to the "console" user are accepted.
37
if user.dest.local == "console":
38
return lambda: ConsoleMessage()
39
raise smtp.SMTPBadRcpt(user)
42
__implements__ = (smtp.IMessage,)
47
def lineReceived(self, line):
48
self.lines.append(line)
50
def eomReceived(self):
51
print "New message received:"
52
print "\n".join(self.lines)
54
return defer.succeed(None)
56
def connectionLost(self):
57
# There was an error, throw away the stored lines
60
class ConsoleSMTPFactory(smtp.SMTPFactory):
61
def __init__(self, *a, **kw):
62
smtp.SMTPFactory.__init__(self, *a, **kw)
63
self.delivery = ConsoleMessageDelivery()
65
def buildProtocol(self, addr):
66
p = smtp.SMTPFactory.buildProtocol(self, addr)
67
p.delivery = self.delivery
71
from twisted.application import internet
72
from twisted.application import service
74
a = service.Application("Console SMTP Server")
75
internet.TCPServer(2500, ConsoleSMTPFactory()).setServiceParent(a)