Description

(!) PATCH is available, it applies to 1.5.8 and 1.8.2.

The From: and other headers are malformatted in notification email when, in mail_from, there is a phrase before the angle address that gets encoded. The result is an invalid header that confuses some clients, for instance, Opera 9.64.

Steps to reproduce

  1. configure a mail_from variable such as

    mail_from = u"Ex-Ample-Wiki <root@my.example.org>"
    note that the exact formatting outside the angle brackets matters, we have only ASCII in our setup
  2. subscribe to a page (for instance, a sandbox page), configure your email address properly, and change the page you've just subscribed to, so that you get a notification
  3. wait until you receive the email triggered in the previous step, and inspect the headers manually

Example

The resulting header is:

From: =?UTF-8?Q?Ex-Ample-Wiki_?=<root@my.example.org>

when it should be:

From: =?UTF-8?Q?Ex-Ample-Wiki?= <root@my.example.org>

Component selection

The bug is in the encodeAddress method in (for version 1.8.2:) MoinMoin/mail/sendmail.py or in (for version 1.5.8:) MoinMoin/util/mail.py

Details

MoinMoin Version

1.8.2 (official tarball), 1.5.8 (packaged by Ubuntu for 8.04 LTS Server)

OS and Version

irrelevant, but Ubuntu Linux 8.04 LTS (long-term support) Server

Python Version

irreelvant, but 2.5.2

Server Setup

wiki farming

Server Details

Language you are using the wiki in (set in the browser/UserPreferences)

German, English

Downstream references:

Fix

Apply this patch (downloadable version below to maintain spacing) - you'll need to tell the patch utility which file to modify (See Component selection above) and you may perhaps need to fix indentation, I faked the filename:

diff -u -r1.1 MoinMoin_util_mail.py
--- MoinMoin_util_mail.py       2009/03/26 12:27:40     1.1
+++ MoinMoin_util_mail.py       2009/03/26 12:29:13
@@ -27,14 +27,14 @@
     @rtype: string
     @return: encoded address
     """
-    composite = re.compile(r'(?P<phrase>.+)(?P<angle_addr>\<.*\>)',
+    composite = re.compile(r'(?P<phrase>.+\S+)(?P<blanks>\s*)(?P<angle_addr>\<.*\>)',
                            re.UNICODE)
     match = composite.match(address)
     if match:
         phrase = match.group('phrase').encode(config.charset)
         phrase = str(Header(phrase, charset))
         angle_addr = match.group('angle_addr').encode(config.charset)
-        return phrase + angle_addr
+        return phrase + match.group('blanks') + angle_addr
     else:
         return address.encode(config.charset)

Downloadable version: encodeAddress-fix-MIME-spacing.patch

Downloadable version including Thomas's suggestion: encodeAddress-fix-MIME-spacing-v2.patch

Workaround

remove anything outside angle brackets from mail_from

Discussion

+    composite = re.compile(r'(?P<phrase>.+\S+)(?P<blanks>\s*)(?P<angle_addr>\<.*\>)',

I see your point, but that doesn't look correct either, as it requires at least 2 non-blank chars in the phrase part.

Did you maybe mean:

+    composite = re.compile(r'(?P<phrase>.*?)(?P<blanks>\s*)(?P<angle_addr>\<.*\>)',

Can you test that please? -- ThomasWaldmann


Your suggestion makes sense to me. I've tested it and it works for me. Thanks for the improvement. -- MatthiasAndree

One more concern though: We're unconditionally encoding mail_from if it doesn't meet the phrase*LWSP*<angle-addr> syntax (in the else branch shown in the "Fix" box above), however, if it happened to be just a bare address, we definitely would NOT want to MIME-encode things then! Arguably it's the users fault then though... -- MatthiasAndree

Well (sorry - I'm short on time, this is off the top of my head) - apparently it does MIME encoding according to RFC2047 - we're invoking a Header method here, after all. But probably not worth further thought, the local MTA will then reject things... -- MatthiasAndree 2009-03-31 15:42:05

Opera 9.64 displays the sender address as <""Ex-Ample-Wiki.
NOTE: Please always record your name next to comments you add.

ReimarBauer: seems I don't know opera well enough. - sorry - I never have seen a sender address on a browser only the receiver address. Currently I edit this page with opera, let's see what happens. ReimarBauer/Photo/img.png -- ReimarBauer 2009-04-25 20:23:58

ReimarBauer: The message I see is Notifications sent to: MatthiasAndree, RobArseneault, MarianNeagul ReimarBauer/Photo/img.png -- ReimarBauer 2009-04-25 20:25:08


Plan


CategoryMoinMoinBugFixed

MoinMoin: MoinMoinBugs/EmailShouldNotMIMEEncodeBlanks (last edited 2009-04-25 20:25:08 by ReimarBauer)