From e163ae33ce7979988beed1098368b656ef4f7fe1 Mon Sep 17 00:00:00 2001 From: yvesf Date: Sat, 20 Feb 2010 20:29:37 +0100 Subject: cleanup --- .gitignore | 3 ++- Maildir/_dummy | 0 log/_dummy | 0 logs/_dummy | 0 smtp.py | 21 +++++++++++++-------- 5 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 Maildir/_dummy create mode 100644 log/_dummy delete mode 100644 logs/_dummy diff --git a/.gitignore b/.gitignore index 9424bf4..f8ac0b2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -/Maildir +Maildir/* +log/* diff --git a/Maildir/_dummy b/Maildir/_dummy new file mode 100644 index 0000000..e69de29 diff --git a/log/_dummy b/log/_dummy new file mode 100644 index 0000000..e69de29 diff --git a/logs/_dummy b/logs/_dummy deleted file mode 100644 index e69de29..0000000 diff --git a/smtp.py b/smtp.py index b1b2e67..3be3d63 100644 --- a/smtp.py +++ b/smtp.py @@ -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) -- cgit v1.2.1