Ticket #1235: django-mail-charset-support.2.diff

File django-mail-charset-support.2.diff, 1.1 KB (added by Antti Kaihola, 19 years ago)

magic-removalized version of the patch, with Header() import

  • django/core/mail.py

     
    22
    33from django.conf import settings
    44from email.MIMEText import MIMEText
     5from email.Header import Header
    56import smtplib
    67
    78class BadHeaderError(ValueError):
     
    1213        "Forbids multi-line headers, to prevent header injection."
    1314        if '\n' in val or '\r' in val:
    1415            raise BadHeaderError, "Header values can't contain newlines (got %r for header %r)" % (val, name)
     16        if name == 'Subject':
     17            val = Header(val, settings.DEFAULT_CHARSET)
    1518        MIMEText.__setitem__(self, name, val)
    1619
    1720def send_mail(subject, message, from_email, recipient_list, fail_silently=False):
     
    3942        if not recipient_list:
    4043            continue
    4144        from_email = from_email or settings.DEFAULT_FROM_EMAIL
    42         msg = SafeMIMEText(message)
     45        msg = SafeMIMEText(message, 'plain', settings.DEFAULT_CHARSET)
    4346        msg['Subject'] = subject
    4447        msg['From'] = from_email
    4548        msg['To'] = ', '.join(recipient_list)
Back to Top