#26496 closed Bug (fixed)
AdminEmailHandler can produce mails violating RFC2822
Reported by: | Michal Čihař | Owned by: | Pyie Zone |
---|---|---|---|
Component: | Error reporting | Version: | 1.9 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
The RFC2822 specifies maximal length of line in a message to 998 characters (see also https://code.djangoproject.com/ticket/22561). However with AdminEmailHandler it's quite easy to reach it once settings contains some more complex dictionary, which is always printed on single line.
The problematic template is TECHNICAL_500_TEXT_TEMPLATE in django/views/debug.py:
https://github.com/django/django/blob/master/django/views/debug.py#L1121
Specially this code:
Using settings module {{ settings.SETTINGS_MODULE }}{% for k, v in settings.items|dictsort:0 %} {{ k }} = {{ v|stringformat:"r" }}{% endfor %}
I think best approach would be to use pformat for formatting those entries same as is used for request parameters.
Change History (9)
comment:1 by , 9 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 9 years ago
Easy pickings: | set |
---|
comment:3 by , 9 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:4 by , 9 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:5 by , 9 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:6 by , 8 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:7 by , 8 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:8 by , 8 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
It looks like this is fixed by #22561. I modified the test like below and it passed for the use case.
def test_send_long_lines(self): email = EmailMessage('Subject', "Commentçava},{'this': {'another': {'more': 'nested'}, 'inner': 'myinner'}, 'that': 'hi'}" * 100, 'from@example.com', ['to@example.com']) email.send() message = self.get_the_message() message_content = message.get_payload() has_long_lines = any(len(l) > 998 for l in message_content.splitlines()) self.assertFalse(has_long_lines)
comment:9 by , 8 years ago
More friendly formatting of dictionaries may still be useful if someone is so inclined to reopen the ticket and make that change.
Since there hasn't been progress in the 5 weeks since this ticket was assigned, I'm de-assigning it to free it up for a PyCon sprinter.