Opened 8 years ago

Closed 7 years ago

Last modified 7 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


The RFC2822 specifies maximal length of line in a message to 998 characters (see also 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/

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 Changed 8 years ago by Tim Graham

Triage Stage: UnreviewedAccepted

comment:2 Changed 8 years ago by Claude Paroz

Easy pickings: set

comment:3 Changed 8 years ago by Filipa Andrade

Owner: set to Filipa Andrade
Status: newassigned

comment:4 Changed 8 years ago by Filipa Andrade

Owner: Filipa Andrade deleted
Status: assignednew

comment:5 Changed 8 years ago by sachitmnayak

Owner: set to sachitmnayak
Status: newassigned

comment:6 Changed 8 years ago by Carl Meyer

Owner: sachitmnayak deleted
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 Changed 8 years ago by Pyie Zone

Owner: set to Pyie Zone
Status: newassigned

comment:8 Changed 7 years ago by Pyie Zone

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, '', [''])
        message = self.get_the_message()
        message_content = message.get_payload()
        has_long_lines = any(len(l) > 998 for l in message_content.splitlines())

comment:9 Changed 7 years ago by Tim Graham

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