From a2e118ec5012cab952dc0a219e0bba32920cf6ac Mon Sep 17 00:00:00 2001 From: mdipierro Date: Fri, 19 Apr 2013 23:46:38 -0500 Subject: [PATCH] fixed Issue 1456:encoding in mail.send, thanks Corne --- VERSION | 2 +- applications/welcome/controllers/default.py | 1 + gluon/cache.py | 2 +- gluon/tools.py | 16 ++++++++++------ 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/VERSION b/VERSION index 4543880b..7458e92d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.4.6-stable+timestamp.2013.04.15.22.57.21 +Version 2.4.6-stable+timestamp.2013.04.19.23.45.56 diff --git a/applications/welcome/controllers/default.py b/applications/welcome/controllers/default.py index 9ac34c21..3da8b325 100644 --- a/applications/welcome/controllers/default.py +++ b/applications/welcome/controllers/default.py @@ -39,6 +39,7 @@ def user(): return dict(form=auth()) +@cache.action() def download(): """ allows downloading of uploaded files diff --git a/gluon/cache.py b/gluon/cache.py index 510a724b..7c4539de 100644 --- a/gluon/cache.py +++ b/gluon/cache.py @@ -437,7 +437,7 @@ class Cache(object): # been accounted for logger.warning('no cache.disk (AttributeError)') - def client(self, time_expire=DEFAULT_TIME_EXPIRE, cache_model=None, + def action(self, time_expire=DEFAULT_TIME_EXPIRE, cache_model=None, prefix=None, session=False, vars=True, lang=True, user_agent=False, public=True, valid_statuses=None, quick=None): diff --git a/gluon/tools.py b/gluon/tools.py index 1128e20a..7aa93b91 100644 --- a/gluon/tools.py +++ b/gluon/tools.py @@ -412,16 +412,20 @@ class Mail(object): if (not text is None or not html is None) and (not raw): attachment = MIMEMultipart.MIMEMultipart('alternative') if not text is None: - if isinstance(text, basestring): + if not isinstance(text, basestring): + text = text.read() + if isinstance(text, unicode): + text = text.encode('utf-8') + elif not encoding=='utf-8': text = text.decode(encoding).encode('utf-8') - else: - text = text.read().decode(encoding).encode('utf-8') attachment.attach(MIMEText.MIMEText(text, _charset='utf-8')) if not html is None: - if isinstance(html, basestring): + if not isinstance(html, basestring): + html = html.read() + if isinstance(html, unicode): + html = html.encode('utf-8') + elif not encoding=='utf-8': html = html.decode(encoding).encode('utf-8') - else: - html = html.read().decode(encoding).encode('utf-8') attachment.attach( MIMEText.MIMEText(html, 'html', _charset='utf-8')) payload_in.attach(attachment)