pallets-eco / flask-security-3.0

Quick and simple security for Flask applications
MIT License
1.63k stars 512 forks source link

Problem with LocalProxy for EMAIL_SENDER #782

Open fmerges opened 6 years ago

fmerges commented 6 years ago

Flask-Security 3.0.0 Flask-Mail==0.9.1

The extension uses the attribute 'email_sender' for the mail sending operations, but the attribute is not a string, its a LocalProxy object:

>>> current_app.extensions['security'].email_sender
'no-reply@localhost'
>>> type(current_app.extensions['security'].email_sender)
<class 'werkzeug.local.LocalProxy'>

In core.py:

'EMAIL_SENDER': LocalProxy(lambda: current_app.config.get(
    'MAIL_DEFAULT_SENDER', 'no-reply@localhost'
)),

Which causes the call to 'send_mail' in utils.py (line 403) to fail because Flask-Mail calls 'sanitize_address' function as part of sending the msg:

# flask_mail.py line 105
def sanitize_address(addr, encoding='utf-8'):
    if isinstance(addr, string_types):
        addr = parseaddr(force_text(addr))
    nm, addr = addr

ValueError: too many values to unpack
fmerges commented 6 years ago

https://github.com/fmerges/flask-security/commit/596a69e2762ae74c1428c42b8bf68c1ee4c5dad1

jirikuncar commented 6 years ago

@fmerges can you please send a PR with the change?