diff options
-rwxr-xr-x[-rw-r--r--] | Maildir/_dummy | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | log/_dummy | 0 | ||||
-rw-r--r-- | smtp.py | 72 |
3 files changed, 41 insertions, 31 deletions
diff --git a/Maildir/_dummy b/Maildir/_dummy index e69de29..e69de29 100644..100755 --- a/Maildir/_dummy +++ b/Maildir/_dummy diff --git a/log/_dummy b/log/_dummy index e69de29..e69de29 100644..100755 --- a/log/_dummy +++ b/log/_dummy @@ -9,41 +9,52 @@ class SMTPChannel(asynchat.async_chat): self.set_terminator("\n") self.data = "" self.read_data = False + self.push("220 Mailserver terrorist.at. Nutzung ohne vorige Erlaubnis verboten!\n") def collect_incoming_data(self, data): + if len(self.data) > 0: + self.data += "\n" self.data += data + self.server.logger.debug("Read: " + data.strip()) if self.data.__len__() > 16384: - print "too much data, shutdown" + self.server.logger.error("too much data, shutdown") self.close_when_done() + def push(self,data): + self.server.logger.debug("Write: " + data) + synchat.async_chat.push(self,data) + def found_terminator(self): - 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) - key=self.server.maildir.add(mail) - self.server.logger.info("New Mail: %s" % key) - self.server.maildir.flush() + try: + if self.read_data: + if self.data.endswith(".") or self.data.endswith(".\r"): + self.read_data = False + self.push("250 Ok: queued as 12345\n") + mail = email.message_from_string(self.data) + key=self.server.maildir.add(mail) + self.server.logger.info("New Mail: %s" % key) + self.server.maildir.flush() + self.data = "" + else: + pass + + elif self.data.startswith("EHLO") \ + or self.data.startswith("HELO"): + self.push("250 Mailserver terrorist.at. Nutzung ohne vorige Erlaubnis verboten!\n") + self.data = "" + elif self.data.startswith("DATA"): + self.push("354 End data with <CR><LF>.<CR><LF>\n") + self.read_data = True + self.data="" + elif self.data.startswith("QUIT"): self.data = "" + self.push("221 Bye\n") + self.close_when_done() else: - self.data += "\n" - - elif self.data.startswith("EHLO") \ - or self.data.startswith("HELO"): - self.push("HELO there\n") - self.data = "" - elif self.data.startswith("DATA"): - self.push("354 End data with <CR><LF>.<CR><LF>\n") - self.read_data = True - self.data="" - elif self.data.startswith("QUIT"): - self.data = "" - self.push("221 Bye\n") - self.close_when_done() - else: - self.push("250 OK\n") - self.data = "" + self.push("250 OK\n") + self.data = "" + except Exception,e: + self.server.logger.error(str(e)) class SMTPServer(asyncore.dispatcher): @@ -59,7 +70,6 @@ class SMTPServer(asyncore.dispatcher): 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() @@ -82,9 +92,7 @@ if __name__ == '__main__': #"Robustly turn into a UNIX daemon, running in our_home_dir." # First fork try: - pid = os.fork() - if pid > 0: - print "PID: %s" % pid + if os.fork() > 0: sys.exit(0) # kill off parent except OSError, e: sys.stderr.write("fork #1 failed: (%d) %s\n" % (e.errno, e.strerror)) @@ -95,7 +103,8 @@ if __name__ == '__main__': # Second fork try: - if os.fork() > 0: + pid = os.fork() + if pid > 0: os._exit(0) except OSError, e: sys.stderr.write("fork #2 failed: (%d) %s\n" % (e.errno, e.strerror)) @@ -111,4 +120,5 @@ if __name__ == '__main__': sys.stdout, sys.stderr = so, se #""" + s.logger.info("Startup; pid=%s" % os.getpid()) asyncore.loop() |