Opened 17 years ago

Closed 16 years ago

#7574 closed (fixed)

EmailMultiAlternatives and send_email do not handle ugettext_lazy translated strings correctly

Reported by: gary.hutspot@… Owned by: Matthias Kestenholz
Component: Core (Mail) Version: dev
Severity: Keywords:
Cc: gary.hutspot@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When trying to send email with a subject that is lazily translated, the following TypeError is thrown:

argument of type 'proxy' is not iterable

Cut and paste compatible example:

from django.utils.translation import ugettext_lazy as _
from django.core.mail import send_mail
from django.conf import settings

# If you do not have smtp running on your local system, specify your smtp server here
settings.configure(EMAIL_HOST='your.smtp.server')

send_mail(_('Subject here'), 'Here is the message.', 'from@example.com', ['to@example.com'], fail_silently=False)

Produces:

$ python proof.py 
Traceback (most recent call last):
  File "proof.py", line 8, in <module>
    fail_silently=False)
  File "/usr/lib/python2.5/site-packages/django/core/mail.py", line 333, in send_mail
    connection=connection).send()
  File "/usr/lib/python2.5/site-packages/django/core/mail.py", line 259, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/usr/lib/python2.5/site-packages/django/core/mail.py", line 168, in send_messages
    sent = self._send(message)
  File "/usr/lib/python2.5/site-packages/django/core/mail.py", line 182, in _send
    email_message.message().as_string())
  File "/usr/lib/python2.5/site-packages/django/core/mail.py", line 241, in message
    msg['Subject'] = self.subject
  File "/usr/lib/python2.5/site-packages/django/core/mail.py", line 92, in __setitem__
    name, val = forbid_multi_line_headers(name, val)
  File "/usr/lib/python2.5/site-packages/django/core/mail.py", line 74, in forbid_multi_line_headers
    if '\n' in val or '\r' in val:
TypeError: argument of type '__proxy__' is not iterable

Attachments (1)

7574.patch (919 bytes ) - added by Matthias Kestenholz 16 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 by Muriel Bowie, 16 years ago

I am having the same problem. Currently I use ugettext instead of ugettext_lazy as a workaround.

by Matthias Kestenholz, 16 years ago

Attachment: 7574.patch added

comment:2 by Matthias Kestenholz, 16 years ago

Has patch: set
Triage Stage: UnreviewedReady for checkin

Just changing the order of the force_unicode block and the \n/\r detection block is enough.

comment:3 by Matthias Kestenholz, 16 years ago

Owner: changed from nobody to Matthias Kestenholz
Status: newassigned

comment:4 by Malcolm Tredinnick, 16 years ago

Since Header instances don't act as containers or sequences (they don't support in tests), this patch cannot work. Writing as test for the failing case might have helped detect that.

(Thanks for taking the time to write a patch, but please let somebody else triage it to "ready for checkin" so that we get another set of eyes on that patch for review.)

comment:5 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: assignedclosed

(In [8083]) Fixed #7574 -- Fixed the handling of lazy translation in email headers.

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