flask-mail icon indicating copy to clipboard operation
flask-mail copied to clipboard

werkzeug.local.LocalProxy object passed to sanitize_address method

Open cisko3000 opened this issue 8 years ago • 2 comments

Hi, sanitize_address is receiving a LocalProxy object instead of an str or basestring. I am using Python 2.7.

File "/home/abc/sites/hempafy1/env/local/lib/python2.7/site-packages/flask_security/registerable.py", line 41, in register_user
    'welcome', user=user, confirmation_link=confirmation_link)
  File "/home/abc/sites/hempafy1/env/local/lib/python2.7/site-packages/flask_security/utils.py", line 401, in send_mail
    mail.send(msg)
  File "/home/abc/sites/hempafy1/env/local/lib/python2.7/site-packages/flask_mail.py", line 496, in send
    message.send(connection)
  File "/home/abc/sites/hempafy1/env/local/lib/python2.7/site-packages/flask_mail.py", line 431, in send
    connection.send(self)
  File "/home/abc/sites/hempafy1/env/local/lib/python2.7/site-packages/flask_mail.py", line 192, in send
    self.host.sendmail(sanitize_address(envelope_from or message.sender),
  File "/home/abc/sites/hempafy1/env/local/lib/python2.7/site-packages/flask_mail.py", line 109, in sanitize_address
    nm, addr = addr
ValueError: too many values to unpack

I put the following in the flask_mail.py

def sanitize_address(addr, encoding='utf-8'):
    if isinstance(addr, string_types):
        addr = parseaddr(force_text(addr))
    elif isinstance(addr, LocalProxy):
        addr = parseaddr(force_text(addr))
    nm, addr = addr

Checking to see if object is LocalProxy. Is this a good way to solve the issue? or is it something that must be changed in flask_security?

Thanks.

cisko3000 avatar Jun 17 '17 20:06 cisko3000

Yes, I'm about to use your fix, but I'd like to see this either formally accepted or something. What's going on with this?

acbart avatar Jul 26 '17 17:07 acbart

You're probably passing Flask-Login's current_user as the sender. This doesn't make sense, not does converting it to a string, which wouldn't be a valid email anyway. Pass user.email (or whatever the email is) as the sender.

This code should not be merged, you should fix the data you're passing.

davidism avatar Jul 26 '17 17:07 davidism