summaryrefslogtreecommitdiff
path: root/smtp.py
diff options
context:
space:
mode:
Diffstat (limited to 'smtp.py')
-rw-r--r--smtp.py21
1 files changed, 13 insertions, 8 deletions
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)