# HG changeset patch
# User Thomas Arendsen Hein <thomas@intevation.de>
# Date 1153404270 -7200
# Node ID 29fb44b4d581753fb4ea7240d5f33b7dc9cf006d
# Parent  48776e1e3ea410dd3358ef4bf832108403b63f86
fix double quoted-printable encoding in forgotten password email.
Double encoding was introduced by 50c7a0cc1791.
Discussed on MoinMoinBugs/ResetPasswordEmailImproperlyEncoded.

The problem was caused by a bug in python 2.4.3 and above, which doesn't
QP-encode the message as previous versions do it.

diff -r 48776e1e3ea4 -r 29fb44b4d581 MoinMoin/util/mail.py
--- a/MoinMoin/util/mail.py	Thu Jul 20 12:02:01 2006 +0200
+++ b/MoinMoin/util/mail.py	Thu Jul 20 16:04:30 2006 +0200
@@ -74,8 +74,14 @@ def sendmail(request, to, subject, text,
     charset = Charset(config.charset)
     charset.header_encoding = QP
     charset.body_encoding = QP
-    msg.set_charset(charset)    
-    msg.set_payload(charset.body_encode(text))
+    msg.set_charset(charset)
+
+    # work around a bug in python 2.4.3 and above:
+    msg.set_payload('=')
+    if msg.as_string().endswith('='):
+        text = charset.body_encode(text)
+
+    msg.set_payload(text)
     
     # Create message headers
     # Don't expose emails addreses of the other subscribers, instead we
