[tor-commits] [bridgedb/develop] Fix email header encoding

phw at torproject.org phw at torproject.org
Wed Feb 19 18:27:18 UTC 2020


commit 5c1c88c6a7ccad888da7ef49e6b2d0ab909bebf9
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Jan 19 17:59:10 2020 -0800

    Fix email header encoding
    
    Type issues that manifested in the following...
    
      Traceback (most recent call last):
        File "/home/atagar/Desktop/tor/bridgedb/bridgedb/test/test_email_server.py", line 208, in test_SMTPIncomingDelivery_receivedHeader
          self.assertSubstring("Received: from example.com", hdr)
        File "/usr/local/lib/python3.5/dist-packages/twisted/trial/_synctest.py", line 571, in assertSubstring
          return self.failUnlessIn(substring, astring, msg)
        File "/usr/local/lib/python3.5/dist-packages/twisted/trial/_synctest.py", line 492, in assertIn
          % (containee, container))
      twisted.trial.unittest.FailTest: 'Received: from example.com' not in "Received: from b'example.com' ([b'127.0.0.1'] helo=b'example.com')\n\tby b'morrigan' with BridgeDB (0.9.1+61.g862b4bd.dirty)\n\tfor client at example.com; b'Sun, 19 Jan 2020 17:35:00 -0800' "
    
    Test results changed as follows...
    
      before: FAILED (skips=115, failures=21, successes=848)
      after:  FAILED (skips=115, failures=20, successes=849)
---
 bridgedb/distributors/email/server.py | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/bridgedb/distributors/email/server.py b/bridgedb/distributors/email/server.py
index f9590be..38ed988 100644
--- a/bridgedb/distributors/email/server.py
+++ b/bridgedb/distributors/email/server.py
@@ -290,11 +290,11 @@ class SMTPIncomingDelivery(smtp.SMTP):
         :type recipients: list
         :param recipients: A list of :api:`twisted.mail.smtp.User` instances.
         """
-        helo_ = ' helo={0}'.format(helo[0]) if helo[0] else ''
-        from_ = 'from %s ([%s]%s)' % (helo[0], helo[1], helo_)
-        by_ = 'by %s with BridgeDB (%s)' % (smtp.DNSNAME, __version__)
-        for_ = 'for %s; %s ' % (' '.join(map(str, recipients)), rfc822date())
-        return str('Received: %s\n\t%s\n\t%s' % (from_, by_, for_))
+        helo_ = b' helo=%s' % (helo[0] if helo[0] else '')
+        from_ = b'from %s ([%s]%s)' % (helo[0], helo[1], helo_)
+        by_ = b'by %s with BridgeDB (%s)' % (smtp.DNSNAME, __version__.encode('utf-8'))
+        for_ = b'for %s; %s ' % (b' '.join([str(r).encode('utf-8') for r in recipients]), rfc822date())
+        return 'Received: %s\n\t%s\n\t%s' % (from_.decode('utf-8'), by_.decode('utf-8'), for_.decode('utf-8'))
 
     def validateFrom(self, helo, origin):
         """Validate the ``MAIL FROM:`` address on the incoming SMTP connection.





More information about the tor-commits mailing list