#12422 closed Bug (fixed)
Django overrides the default email charset behaviour for utf-8
Reported by: | Simon Blanchard | Owned by: | Ramiro Morales |
---|---|---|---|
Component: | Core (Mail) | Version: | dev |
Severity: | Normal | Keywords: | charset utf-8 |
Cc: | bnomis@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
# Don't BASE64-encode UTF-8 messages so that we avoid unwanted attention from # some spam filters. Charset.add_charset('utf-8', Charset.SHORTEST, Charset.QP, 'utf-8')
The above bit of code in django.core.mail overrides the standard Python behaviour for utf-8 in the Python email module. It would be better to set the charset by calling set_charset() on the Message before sending if needed rather than a global override. This behaviour and assumption is not documented anywhere in Django as far as I can tell. I think this is a case of the framework being a bit too clever. Not everyone using Django is using the django email sending methods nor wants Django to (silently) change the system defaults.
For example, I use the standard Python email sending methods and was expecting the Python lib to behave as advertised but the encoding of my utf-8 messages kept coming out quoted-printable because of the override above.
Attachments (1)
Change History (16)
comment:1 by , 15 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 15 years ago
Cc: | added |
---|
comment:3 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
comment:4 by , 13 years ago
UI/UX: | unset |
---|
comment:6 by , 12 years ago
Description: | modified (diff) |
---|
comment:7 by , 12 years ago
This also caused me a lot of trouble when I was writing a patch for #18916.
comment:8 by , 12 years ago
Has patch: | set |
---|
Patch attached. Tests changes are only the different order of headers, nothing significant.
comment:9 by , 11 years ago
Tests pass. I made a PR to make it easier to merge into master. https://github.com/django/django/pull/1376/files
comment:10 by , 11 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:11 by , 11 years ago
Patch needs improvement: | set |
---|---|
Version: | 1.1 → master |
Unfortunately the email tests have multiple failures under Python3 with this patch applied - I did not investigate the causes.
comment:12 by , 11 years ago
Owner: | changed from | to
---|
Actually, the proposed patch tests fail with Python 3.3. They pass for 3.2.x (and 2.7..x).
The pre-3.3.0 Python commit where things break is:
changeset: 75893:9ceac471bd8c user: R David Murray <rdmurray@bitdance.com> date: Thu Mar 22 22:40:44 2012 -0400 summary: #14380: Make actual default match docs, fix __init__ order.
See:
Thank you very much to all individuals that have worked on this so far. I have a fix ready, will open a new PR soon and post a link here so you can review it.
comment:14 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Change UI/UX from NULL to False.