From cd1ce28639d45952eb8123abde6034c3e9b4a492 Mon Sep 17 00:00:00 2001 From: mdipierro Date: Thu, 28 Mar 2013 14:59:06 -0500 Subject: [PATCH] encoding in mail.send, thanks Jonathan --- VERSION | 2 +- gluon/tools.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/VERSION b/VERSION index 649273f9..cc7a7841 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.4.5-stable+timestamp.2013.03.28.14.45.53 +Version 2.4.5-stable+timestamp.2013.03.28.14.58.27 diff --git a/gluon/tools.py b/gluon/tools.py index 2e9de72f..29c5580e 100644 --- a/gluon/tools.py +++ b/gluon/tools.py @@ -374,10 +374,14 @@ class Mail(object): payload_in = MIMEMultipart.MIMEMultipart('mixed') else: # no encoding configuration for raw messages - if isinstance(message, basestring): + if not isinstance(message, basestring): + message = message.read() + if isinstance(message, unicode): + text = message.encode('utf-8') + elif not encoding=='utf-8': text = message.decode(encoding).encode('utf-8') else: - text = message.read().decode(encoding).encode('utf-8') + text = message # No charset passed to avoid transport encoding # NOTE: some unicode encoded strings will produce # unreadable mail contents. @@ -397,7 +401,8 @@ class Mail(object): text = html = None elif isinstance(message, (list, tuple)): text, html = message - elif message.strip().startswith(''): + elif message.strip().startswith(''): text = self.settings.server == 'gae' and message or None html = message else: