#7747 closed (fixed)
Long email subject headers have tab character inserted
Reported by: | Owned by: | Rami Kassab | |
---|---|---|---|
Component: | Core (Mail) | Version: | dev |
Severity: | Keywords: | aug22sprint | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When sending email from Django long subject headers have tab characters inserted. This is a problem with the underlying email stdlib which has had recent discussion at
http://bugs.python.org/issue1974
and been moved to
http://www.mail-archive.com/email-sig@python.org/msg00198.html
Attachments (3)
Change History (14)
by , 16 years ago
Attachment: | tabs_in_subject_line_fix.diff added |
---|
comment:1 by , 16 years ago
Has patch: | set |
---|---|
milestone: | → 1.0 beta |
Triage Stage: | Unreviewed → Accepted |
Perhaps adding some comments about the workaround might help. :)
by , 16 years ago
Attachment: | tabs_in_subject_line_fix.2.diff added |
---|
Updated, slightly cleaner, workaround for tabs in email subject headers
comment:2 by , 16 years ago
The workaround is to always use the email Header class to create the subject header for an email. The current code only does this if the header is non-ascii, otherwise, a string is used. The patch addresses this case.
When using a string a long subject line is folded with tabs. In (recent versions?) of Outlook the tabs are removed resulting in abutted words. In (recent versions?) of Tbird the tabs are rendered giving "wide" spaces between words. When using the header class, however, folding is done with a space and you seem to get the subject line looking as you'd expect.
If you read the discussions referenced above it seems the email stdlib is a bit broken. This patch just takes advantage of, what I think is, the happy accident that using the Header class seems to give the expected results (or, at least, better results than having tabs inserted in your subject line).
comment:4 by , 16 years ago
Needs tests: | set |
---|---|
Patch needs improvement: | set |
I'm afraid I don't see how this patch helps. forbid_multi_line_headers() is only invoked as part of SafeMIMEText and SafeMIMEMultipart. SafeMIMEText is used on the message and on each attachment; SafeMIMEMultipart is used on the message of a multipart email. The subject of an email is assigned to the EmailMessage verbatim on line 219, and then put in the to message header verbatim on line 244. As far as I can make out, neither of these wrappers are used during subject handling.
A regression test case would be very helpful (regressiontests/mail would be the obvious location).
by , 16 years ago
Attachment: | long_email_subject_wrapping_fix_and_test.diff added |
---|
updated patch for compatibility with latest code and added test
comment:5 by , 16 years ago
Needs tests: | unset |
---|
I updated that patch and added a test to regressionstest/mail to show the problem.
The message method of EmailMessage creates an instance of SafeMIMEText which overrides the default setitem of MIMEText to always invoke forbid_multi_line_headers on header assignment. So, at line 244 (247 patched), the assignment of the subject will cause forbid_multi_line_headers() to be called and the patch will ensure that an ascii subject header is returned as an instance of the Header class instead of a unicode string. This, in turn, ensures that a space, not a tab, is used as the continuation character if the subject line is long and has to be folded over several lines (this is what the added test checks for).
Prefering a space over a tab means that Outlook and Thunderbird will show a long email subject correctly.
comment:6 by , 16 years ago
Owner: | changed from | to
---|
comment:7 by , 16 years ago
Keywords: | aug22sprint added |
---|---|
Patch needs improvement: | unset |
Triage Stage: | Accepted → Ready for checkin |
Wrote a quick test app to confirm this issue. Raw email headers were as follows:
Before Patch:
... Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: This is a really long subject and I just wanted to test to see how this turned out in my email application. For some reason, tabs are inserted to fold the subject but we want spaces instead.... don't we now?! ...
After Patch:
... Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: This is a really long subject and I just wanted to test to see how this turned out in my email application. For some reason, tabs are inserted to fold the subject but we want spaces instead.... don't we now?! ...
Also ran the regression test in the patch, which function as expected. I think this is ready for checkin
comment:8 by , 16 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
comment:9 by , 16 years ago
Resolution: | worksforme |
---|---|
Status: | closed → reopened |
comment:10 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
Workaround for tab insertion in long email subject lines