[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [bridgedb/master] Refactor b.e.server.MailMessage class.



commit 9a1dbf55924ad71c1257d86caf6ad6cc65c78510
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date:   Mon Jun 2 20:58:23 2014 +0000

    Refactor b.e.server.MailMessage class.
    
     * ADD attributes so that the information about the incoming SMTP
       message is still accessible to the autoresponder while we're creating
       the reply.
     * FIXUP docstrings.
---
 lib/bridgedb/email/server.py |   49 ++++++++++++++++++++++++++++++------------
 1 file changed, 35 insertions(+), 14 deletions(-)

diff --git a/lib/bridgedb/email/server.py b/lib/bridgedb/email/server.py
index 249b7c7..a493be0 100644
--- a/lib/bridgedb/email/server.py
+++ b/lib/bridgedb/email/server.py
@@ -122,34 +122,54 @@ class MailServerContext(object):
         return canon
 
 
-class MailMessage(object):
+class SMTPMessage(object):
     """Plugs into the Twisted Mail and receives an incoming message.
 
     :ivar list lines: A list of lines from an incoming email message.
     :ivar int nBytes: The number of bytes received thus far.
     :ivar bool ignoring: If ``True``, we're ignoring the rest of this message
-        because it exceeded :ivar:`MailContext.maximumSize`.
+        because it exceeded :ivar:`MailServerContext.maximumSize`.
+    :ivar canonicalFromSMTP: See :meth:`SMTPAutoresponder.runChecks`.
+    :ivar canonicalFromEmail: See :meth:`SMTPAutoresponder.runChecks`.
+    :ivar canonicalDomainRules: See :meth:`SMTPAutoresponder.runChecks`.
+    :type message: :api:`twisted.mail.smtp.rfc822.Message` or ``None``
+    :ivar message: The incoming email message.
+    :type responder: :class:`autoresponder.SMTPAutoresponder`
+    :ivar responder: A parser and checker for the incoming :ivar:`message`. If
+        it decides to do so, it will build a
+        :meth:`~autoresponder.SMTPAutoresponder.reply` email and
+        :meth:`~autoresponder.SMTPAutoresponder.send` it.
     """
     implements(smtp.IMessage)
 
-    def __init__(self, context, fromCanonical=None):
-        """Create a new MailMessage from a MailContext.
+    def __init__(self, context, canonicalFromSMTP=None):
+        """Create a new SMTPMessage.
 
-        :type context: :class:`MailContext`
-        :param context: The configured context for the email server.
-        :type canonicalFrom: str or None
-        :param canonicalFrom: The canonical domain which this message was
+        These are created automatically via
+        :class:`SMTPIncomingDelivery`.
+
+        :param context: The configured :class:`MailServerContext`.
+        :type canonicalFromSMTP: str or None
+        :param canonicalFromSMTP: The canonical domain which this message was
             received from. For example, if ``'gmail.com'`` is the configured
             canonical domain for ``'googlemail.com'`` and a message is
             received from the latter domain, then this would be set to the
             former.
         """
         self.context = context
-        self.fromCanonical = fromCanonical
+        self.canon = context.canon
+        self.canonicalFromSMTP = canonicalFromSMTP
+        self.canonicalFromEmail = None
+        self.canonicalDomainRules = None
+
         self.lines = []
         self.nBytes = 0
         self.ignoring = False
 
+        self.message = None
+        self.responder = autoresponder.SMTPAutoresponder()
+        self.responder.incoming = self
+
     def lineReceived(self, line):
         """Called when we get another line of an incoming message."""
         self.nBytes += len(line)
@@ -161,9 +181,10 @@ class MailMessage(object):
             logging.debug("> %s", line.rstrip("\r\n"))
 
     def eomReceived(self):
-        """Called when we receive the end of a message."""
+        """Tell the :ivar:`responder` to reply when we receive an EOM."""
         if not self.ignoring:
-            self.reply()
+            self.message = self.getIncomingMessage()
+            self.responder.reply()
         return defer.succeed(None)
 
     def connectionLost(self):
@@ -171,15 +192,15 @@ class MailMessage(object):
         pass
 
     def getIncomingMessage(self):
-        """Create and parse an :rfc:`2822` message object for all ``lines``
+        """Create and parse an :rfc:`2822` message object for all :ivar:`lines`
         received thus far.
 
         :rtype: :api:`twisted.mail.smtp.rfc822.Message`
         :returns: A ``Message`` comprised of all lines received thus far.
         """
         rawMessage = io.StringIO()
-        for ln in self.lines:
-            rawMessage.writelines(unicode(ln) + unicode('\n'))
+        for line in self.lines:
+            rawMessage.writelines(unicode(line) + unicode('\n'))
         rawMessage.seek(0)
         return smtp.rfc822.Message(rawMessage)
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits