Opened 9 years ago
Closed 8 years ago
#26572 closed Bug (fixed)
Remove email subject length truncation in AdminEmailHandler
Reported by: | Peter De Wachter | Owned by: | nobody |
---|---|---|---|
Component: | Core (Mail) | Version: | 1.9 |
Severity: | Normal | Keywords: | |
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
AdminEmailHandler.format_subject() is careful to stay under the 998 character limit of RFC 2822:
Escape CR and LF characters, and limit length.
RFC 2822's hard limit is 998 characters per line. So, minus "Subject: "
the actual subject must be no longer than 989 characters.
However, it forgets that the mail_admins function will prepend EMAIL_SUBJECT_PREFIX. After that's done, the subject line will again exceed to RFC limit.
Either the truncation needs to be moved to a lower level in the mail system, or format_subject needs to be adjusted to account for EMAIL_SUBJECT_PREFIX.
Change History (10)
comment:1 by , 9 years ago
Component: | Uncategorized → Core (Mail) |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
comment:2 by , 9 years ago
Has patch: | set |
---|
comment:3 by , 9 years ago
Patch needs improvement: | set |
---|
After some more consideration, I discovered that headers are not limited in total length by the spec, only individual lines are. Read https://tools.ietf.org/html/rfc5322#section-2.1.3: An unfolded header field has no length restriction and therefore may be indeterminately long.
.
Then Python is automatically folding headers when sending messages, by default to 78 characters. So now I think that the subject line truncation is simply wrong. Of course, it's not nice to receive very long headers, but we have no reason to truncate subject or any other header.
We might even question the refusal to accept newlines in headers, but that would be the subject of a separate ticket.
comment:4 by , 9 years ago
Patch needs improvement: | unset |
---|
The new PR.
pdewacht, what was your issue with subject line length?
comment:5 by , 9 years ago
We're using django-post-office as email backend. It stores the messages in a database table and tries to put the subject in a varchar(989). That blew up when we had a log message that was unexpectedly long.
Personally I prefer truncating over line wrapping -- multiline subject headers seem esoteric even if it's true that it's technically allowed. I fear it will cause interoperability problems (see e.g. django-post-office breaking).
comment:6 by , 9 years ago
An alternative would be to truncate at a much shorter length, 120 chars comes to mind. Would that risk of stripping valuable data? Should we then repeat the record message in the body of the message?
comment:7 by , 9 years ago
I'm inclined to say that applications like django-post-office should take care of truncating data as they see fit rather than Django making some arbitrary choice about it.
comment:8 by , 8 years ago
Summary: | AdminEmailHandler fails to honor subject length limit → Remove email subject length truncation in AdminEmailHandler |
---|---|
Triage Stage: | Accepted → Ready for checkin |
comment:10 by , 8 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I tried the "lower level" technique in that PR.