Code

Ticket #3472: email-as-qp.patch

File email-as-qp.patch, 1.9 KB (added by Matthias Urlichs <smurf@…>, 7 years ago)

Use quoted-printable, not base64, when mailing

  • django/core/mail.py

    diff --git a/django/core/mail.py b/django/core/mail.py
    index a5af6e6..7b09e47 100644
    a b  
    11# Use this module for e-mailing. 
    22 
    33from django.conf import settings 
    4 from email.MIMEText import MIMEText 
     4from email.MIMENonMultipart import MIMENonMultipart 
    55from email.Header import Header 
    66import smtplib, rfc822 
    77import socket 
    DNS_NAME = socket.getfqdn() # Cache the hostname 
    1313class BadHeaderError(ValueError): 
    1414    pass 
    1515 
    16 class SafeMIMEText(MIMEText): 
     16class SafeMIMEText(MIMENonMultipart): 
     17    """Class for generating non-quoted text/* type MIME documents.""" 
     18 
     19    def __init__(self, _text, _subtype='plain', _charset='us-ascii'): 
     20        """Create a text/* type MIME document. 
     21 
     22        _text is the string for this message object. 
     23 
     24        _subtype is the MIME sub content type, defaulting to "plain". 
     25 
     26        _charset is the character set parameter added to the Content-Type 
     27        header.  This defaults to "us-ascii".  Note that as a side-effect, the 
     28        Content-Transfer-Encoding header will also be set. 
     29        """ 
     30        MIMENonMultipart.__init__(self, 'text', _subtype, 
     31                                  **{'charset': _charset}) 
     32        self.add_header('Content-Transfer-Encoding', 'quoted-printable') 
     33        self.set_payload(_text, _charset) 
     34 
    1735    def __setitem__(self, name, val): 
    1836        "Forbids multi-line headers, to prevent header injection." 
    1937        if '\n' in val or '\r' in val: 
    2038            raise BadHeaderError, "Header values can't contain newlines (got %r for header %r)" % (val, name) 
    2139        if name == "Subject": 
    2240            val = Header(val, settings.DEFAULT_CHARSET) 
    23         MIMEText.__setitem__(self, name, val) 
     41        MIMENonMultipart.__setitem__(self, name, val) 
    2442 
    2543def send_mail(subject, message, from_email, recipient_list, fail_silently=False, auth_user=settings.EMAIL_HOST_USER, auth_password=settings.EMAIL_HOST_PASSWORD): 
    2644    """