#8533 switch python email 'policy' for better line length handling

v1.17.0
closed
None
General
nobody
2024-06-10
2024-01-04
No

If an email has a super long subject header (for example) with no spaces in it, email delivery can fail. For example exim gives message has lines too long for transport

We’ve handled this before:

  • in SMTPClient.sendmail and test_send_email_long_lines_use_quoted_printable but apparently it doesn’t split a header if there’s no spaces or other chars to split on
  • encode_email_part handled it too, and debugging that seems like it works correctly (setting header charsets) but it still ends up rewritten later in sendmail, and causes the error

https://docs.python.org/3/library/email.mime.html for MIMEText and MIMEMultipart extend from Message which has a default policy of compat32 (python 3.2 compatibility, bugs included). Specifying a different policy (or using EmailMessage perhaps) seems to work better, and maybe we can get rid of workarounds within our code. See https://docs.python.org/3/library/email.policy.html in the middle of the page. SMTP seems best. (SMTPUTF8 sound appealing, but not all mail servers support utf8)

Discussion

  • Dave Brondsema

    Dave Brondsema - 2024-01-09
    • status: in-progress --> closed
     
  • Dave Brondsema

    Dave Brondsema - 2024-06-10
    • Milestone: unreleased --> v1.17.0
     

Log in to post a comment.