diff options
author | yvesf <yvesf@aurora.xapek.org> | 2010-02-20 20:29:37 +0100 |
---|---|---|
committer | yvesf <yvesf@aurora.xapek.org> | 2010-02-20 20:29:37 +0100 |
commit | e163ae33ce7979988beed1098368b656ef4f7fe1 (patch) | |
tree | 9698e2de38542eb70931765c95eb0861685f5184 | |
parent | df5b30b3820d927cc761782f8d6edf5795e89e3d (diff) | |
download | fakesmtp-e163ae33ce7979988beed1098368b656ef4f7fe1.tar.gz fakesmtp-e163ae33ce7979988beed1098368b656ef4f7fe1.zip |
cleanup
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | Maildir/_dummy (renamed from logs/_dummy) | 0 | ||||
-rw-r--r-- | log/_dummy | 0 | ||||
-rw-r--r-- | smtp.py | 21 |
4 files changed, 15 insertions, 9 deletions
@@ -1 +1,2 @@ -/Maildir +Maildir/* +log/* diff --git a/logs/_dummy b/Maildir/_dummy index e69de29..e69de29 100644 --- a/logs/_dummy +++ b/Maildir/_dummy diff --git a/log/_dummy b/log/_dummy new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/log/_dummy @@ -1,7 +1,6 @@ import asynchat, asyncore, socket -import pwd, os, sys -import email -from mailbox import Maildir,MaildirMessage +import pwd, os, sys, logging, logging.handlers +import mailbox, email class SMTPChannel(asynchat.async_chat): def __init__(self, server, sock, addr): @@ -12,23 +11,23 @@ class SMTPChannel(asynchat.async_chat): self.read_data = False def collect_incoming_data(self, data): - if len(self.data) > 0: - self.data += "\n" self.data += data if self.data.__len__() > 16384: print "too much data, shutdown" self.close_when_done() def found_terminator(self): - print self.data if self.read_data: if self.data.endswith("\n."): self.push("250 Ok: queued as 12345\n") self.read_data = False mail = email.message_from_string(self.data) - self.server.maildir.add(mail) + key=self.server.maildir.add(mail) + self.server.logger.info("New Mail: %s" % key) self.server.maildir.flush() self.data = "" + else: + self.data += "\n" elif self.data.startswith("EHLO") \ or self.data.startswith("HELO"): @@ -55,10 +54,16 @@ class SMTPServer(asyncore.dispatcher): self.set_reuse_addr() self.bind(("", self.port)) self.listen(5) - self.maildir = Maildir("Maildir", create=True) + self.maildir = mailbox.Maildir("Maildir", create=True) + self.logger = logging.getLogger('MyLogger') + self.logger.setLevel(logging.DEBUG) + handler = logging.handlers.TimedRotatingFileHandler("log/smtp.log", "D", 1) + self.logger.addHandler(handler) + self.logger.info("Startup; pid=%s" % os.getpid()) def handle_accept(self): conn, addr = self.accept() + self.logger.info("New Client %s" % addr) SMTPChannel(self, conn, addr) |