Unverified Commit 5c1c88c6 authored by Damian Johnson's avatar Damian Johnson Committed by Philipp Winter
Browse files

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@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)
parent 82f4566f
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -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.