Skip to content
This repository has been archived by the owner on Jul 20, 2020. It is now read-only.

Sender email address as ugettext_lazy object breaks Djrill #87

Closed
wants to merge 2 commits into from

Conversation

spheroid
Copy link

Defining sender email as ugettext_lazy object breaks the Djrill backend:

File "/opt/lib/python2.7/site-packages/djrill/mail/backends/djrill.py", line 68, in send_messages
    sent = self._send(message)
File "/opt/lib/python2.7/site-packages/djrill/mail/backends/djrill.py", line 85, in _send
    msg_dict = self._build_standard_message_dict(message)
File "/opt/lib/python2.7/site-packages/djrill/mail/backends/djrill.py", line 141, in _build_standard_message_dict
    sender = sanitize_address(message.from_email, message.encoding)
File "/opt/lib/python2.7/site-packages/django/core/mail/message.py", line 105, in sanitize_address
    nm, addr = addr
ValueError: too many values to unpack

Forcing the value to be evaluated before it is being broken into pieces seems to fix the issue.

@medmunds
Copy link
Contributor

Could you provide an example where this fails? (This change would need a test case.)

Djrill call's Django's own sanitize_address here, in the same way that Django's smtp.EmailBackend does. So if there's a problem with using a lazy string as the to-address, it probably also exists in Django.

Hmm... It looks like Django's sanitize_address already tries to call force_text on the address (and this code hasn't changed since at least Django 1.3) -- so Djrill shouldn't need to force_text as well. Maybe the test for "is-string-like" in Django's sanitize_address is wrong?

@medmunds
Copy link
Contributor

Yeah, this seems to be a bug in Django core mail. I think it would be better fixed there, rather than working around it in Djrill.

Reported as Django #24416. Patch in django/django#4211.

In the meantime, if this is impacting your use of Djrill, I'd suggest calling force_text on the sender address at the point where you're building the EmailMessage object.

@medmunds medmunds closed this Feb 25, 2015
@spheroid
Copy link
Author

I was looking at that line of code as well, but didn't feel bold enough to blame it on them. :-) I worked around the problem in the meantime by extending the Djrill backend with custom one that does this. I'm unable to control all the places email gets sent (Django error handler for instance) so the code relies on DEFAULT_FROM_EMAIL which needs to be lazy.

Thank you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants