pazz / alot

Terminal-based Mail User Agent
GNU General Public License v3.0
700 stars 163 forks source link

Emails with non-ASCII subjects are bounced by SMTP server without UTF-8 support #1484

Closed milibopp closed 4 years ago

milibopp commented 4 years ago

Describe the bug When sending emails using alot that include non-ASCII characters to a SMTP server that does not support UTF-8 in mail headers, the email is bounced by the server. Likely due to a bug in Python, see issue 40157

Software Versions

To Reproduce

  1. Get a SMTP server, that does not support UTF-8 in headers.
  2. Compose a mail with non-ASCII characters in the subject
  3. Send it via that server under 1.

Error Log What I get from the SMTP server: 550 Subject contains invalid characters. (in reply to end of DATA command)

The bounced message looks like this (somewhat redacted for privacy reasons):

Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Subject: Test üäö
From: one.of.my@mails.com
To: another.mail@of.mine
Message-ID: <redactedmessageid@somecomputer>
User-Agent: alot/0.8
Date: Thu, 02 Apr 2020 12:41:21 +0200

The important aspect is Subject: Test üäö. This has not been encoded. I have traced this down through the source code to alot/commands/envelope.py:245.

It was a bit strange to see this behaviour given the existence of email.policy.SMTPUTF8. But apparently they both encode headers the same way. I have the impression that this is a bug in the Python standard library, so I also opened issue 40157 on the Python bug tracker.

As a workaround, removing the policy parameter and thereby falling back to the default compat32 policy, fixes the problem for me. Does that have any unintended side-effects?

pazz commented 4 years ago

@aepsil0n Could you check if #1485 fixes your issue?

milibopp commented 4 years ago

Thanks for the heads-up. I just checked the issue with the current master (8e96d504) and can confirm that it fixes my issue.

pazz commented 4 years ago

Wait: what? This supposed fix is not yet part of the master branch..

milibopp commented 4 years ago

There are two commits (5855e100 and 3ea84785) by @stregouet on master. You merged them in #1485. That is why I simply pulled in the recent master branch to check. Were you not referring to these commits?

pazz commented 4 years ago

sorry, you are right. These are part of the master branch already. Thanks for confirming the fix!

milibopp commented 4 years ago

No worries. Glad I could help with testing.