This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author r.david.murray
Recipients Abridbus, barry, drlazor8, r.david.murray
Date 2021-07-15.12:35:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1626352542.56.0.585927029877.issue44637@roundup.psfhosted.org>
In-reply-to
Content
Forget what I said about my different error, I made a mistake running the test script.

Interesting.  If it is related to the length of the name, then the problem is most likely in the folding algorithm, specifically in what happens when the "display-name" token is wrapped across lines.  And indeed, if we clone the SMTP policy and set the max_line_len to 1000 in your sample script. it renders the header correctly.

The problem here is that the surrounding quotation marks are added by the 'value' property of DisplayName, but that property isn't invoked when handling parts of the display name separately during mulit-line folding.  I was always bothered by the handling of the quotation marks in the part of the parser and folder dealing with quoted strings, but I never hit on a better way to do it.  This, unfortunately, is going to be non-trivial problem to solve.  It is probably going to require an ugly hack in the folding code :(

Really, the handling of quoted strings throughout the _header_value_parser code is...a hack :(  There are probably other places where it breaks down during multi-line folding.  If we are lucky the hack can just add special handling for the quoted-string token type in the folder.  If we aren't it will get messier :(

Glancing at the folder code (it's been a long time since I worked on it), one possible approach (not necessarily the best one) would be to mark the first and last sub-tokens in a quoted-string so that folder knows to put in a leading or trailing quote mark, respectively, during folding.
History
Date User Action Args
2021-07-15 12:35:42r.david.murraysetrecipients: + r.david.murray, barry, drlazor8, Abridbus
2021-07-15 12:35:42r.david.murraysetmessageid: <1626352542.56.0.585927029877.issue44637@roundup.psfhosted.org>
2021-07-15 12:35:42r.david.murraylinkissue44637 messages
2021-07-15 12:35:41r.david.murraycreate