Opened 9 years ago

Closed 8 years ago

Last modified 8 years ago

#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 Tim Graham, 9 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Claude Paroz, 9 years ago

Easy pickings: set

comment:3 by Filipa Andrade, 9 years ago

Owner: set to Filipa Andrade
Status: newassigned

comment:4 by Filipa Andrade, 9 years ago

Owner: Filipa Andrade removed
Status: assignednew

comment:5 by sachitmnayak, 9 years ago

Owner: set to sachitmnayak
Status: newassigned

comment:6 by Carl Meyer, 8 years ago

Owner: sachitmnayak removed
Status: assignednew

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.

comment:7 by Pyie Zone, 8 years ago

Owner: set to Pyie Zone
Status: newassigned

comment:8 by Pyie Zone, 8 years ago

Resolution: fixed
Status: assignedclosed

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 Tim Graham, 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.

Note: See TracTickets for help on using tickets.
Back to Top