[tor-commits] [bridgedb/develop] Refactor bridgedb.email.server.MailMessage.getRecipient().

isis at torproject.org isis at torproject.org
Fri Jun 6 20:40:38 UTC 2014


commit 1c8c02eac6449100ebee951d31c21268538e8951
Author: Isis Lovecruft <isis at torproject.org>
Date:   Wed May 21 03:08:47 2014 +0000

    Refactor bridgedb.email.server.MailMessage.getRecipient().
    
     * CHANGE to using only one try/except block for
       `smtp.AddressError`s. We should probably assume that our
       EMAIL_SMTP_FROM_ADDR in the config file is correctly formed, and not
       bother logging the special case if it is not. Instead, just log all
       `smtp.AddressError`s in the same manner.
     * CHANGE variable names to make code clearer.
---
 lib/bridgedb/email/server.py |   27 +++++++++++----------------
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/lib/bridgedb/email/server.py b/lib/bridgedb/email/server.py
index 03643dc..09df526 100644
--- a/lib/bridgedb/email/server.py
+++ b/lib/bridgedb/email/server.py
@@ -570,26 +570,21 @@ class MailMessage(object):
         :return: Our address from the recipients list. If we can't find it
             return our default ``SMTP_FROM_ADDRESS`` from the config file.
         """
-        address = self.context.fromAddr
-        addressList = incoming.getaddrlist("To")
+        ourAddress = self.context.fromAddr
 
         try:
-            ours = smtp.Address(address)
+            ourAddress = smtp.Address(ourAddress)
+            allRecipients = incoming.getaddrlist("To")
+            for _, addr in allRecipients:
+                recipient = smtp.Address(addr)
+                # See if the user looks familiar. We do a 'find' instead of
+                # compare because we might have a '+' address here.
+                if recipient.local.find(ourAddress.local) != -1:
+                    return '@'.join([recipient.local, recipient.domain])
         except smtp.AddressError as error:
-            logging.warn("Our address seems invalid: %r" % address)
             logging.warn(error)
-        else:
-            for _, addr in addressList:
-                try:
-                    maybeOurs = smtp.Address(addr)
-                except smtp.AddressError:
-                    pass
-                else:
-                    # See if the user looks familiar. We do a 'find' instead of
-                    # compare because we might have a '+' address here.
-                    if maybeOurs.local.find(ours.local) != -1:
-                        return '@'.join([maybeOurs.local, maybeOurs.domain])
-        return address
+
+        return ourAddress
 
     def getCanonicalDomain(self, domain):
         try:





More information about the tor-commits mailing list