A workaround for treating long address splitted into lines

Bug #558235 reported by naoki-fukuta
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
GNU Mailman
New
Undecided
Unassigned

Bug Description

---Summary:---
 Following is a workaround for a problem when
processing very long email address field that is
splitted into two or more lines.

I tested it on Mailman 2.1.8.

 Please evaluate this patch and feedback to the latest
build.

I appreciate if this is a duplicate of already reported
one.

---Problem Description:---
 The mail address parser program
(pythonlib/email/_parseaddr.py) has a problem when the
field is splitted into two or more lines by using
continuations(eg. "\r\n " or "\r\n\t").

For example, following "Cc:" field can be splitted into
 lines when the mail is sent to the server.

Cc:
=?ISO-2022-JP?B?IktCU0UbJEI4JjVmMnEbKEIgGyRCNDQ7dkNEGyhC?=
 =?ISO-2022-JP?B?Ig==?= <email address hidden>,
 =?ISO-2022-JP?B?IhskQkVFO1I+cEpzREw/LjNYMnEbKEIgGyRCOCY1ZhsoQg==?=

 =?ISO-2022-JP?B?GyRCMnFIL0k9Pz05fiU3JTklRiVgGyhCIg==?=
<email address hidden>

The main problem is there are no actual email address
at line 1 and 3.

Current code in _parseaddr.py expects there is at least
one valid email address in a line. So what will happen?
See below. When posting the mail to members, two
addresses are newly made, with a default domain name
(@mailman.example3.org).

Cc: =?ISO-2022-JP?B?Ig==?= <email address hidden>,
 =?ISO-2022-JP?B?IktCU0UbJEI4JjVmMnEbKEIgGyRCNDQ7dkNEGyhC?=@mailman.example3.org,
 =?ISO-2022-JP?B?IhskQkVFO1I+cEpzREw/LjNYMnEbKEIgGyRCOCY1ZhsoQg==?=@mailman.example3.org,
 =?ISO-2022-JP?B?GyRCMnFIL0k9Pz05fiU3JTklRiVgGyhCIg==?=
<email address hidden>

---Patch---
I made a workaroud patch by adding a darty code into
getphraselist() method.

----------------------------------------------------
    def getphraselist(self):
        """Parse a sequence of RFC 2822 phrases.

        A phrase is a sequence of words, which are in
turn either RFC 2822
        atoms or quoted-strings. Phrases are
canonicalized by squeezing all
        runs of continuous whitespace into one space.
        """
        plist = []

        while self.pos < len(self.field):
            if self.field[self.pos] in self.LWS:
                self.pos += 1
            elif self.field[self.pos] == '"':
                plist.append(self.getquote())
            elif self.field[self.pos] == '(':
                self.commentlist.append(self.getcomment())
+ elif (self.pos + 4) < len(self.field) and
self.field[self.pos] in '\r' and self.field[self.pos+1]
in '\n' and self.field[self.pos+2] in '\t':
+ self.pos += 3
+ elif (self.pos + 4) < len(self.field) and
self.field[self.pos] in '\r' and self.field[self.pos+1]
in '\n' and self.field[self.pos+2] in ' ':
+ self.pos += 3
+ elif (self.pos + 4) < len(self.field) and
self.field[self.pos] in '\n' and self.field[self.pos+1]
in '\t':
+ self.pos += 2
+ elif (self.pos + 4) < len(self.field) and
self.field[self.pos] in '\n' and self.field[self.pos+1]
in ' ':
+ self.pos += 2
+ elif (self.pos + 4) < len(self.field) and
self.field[self.pos] in '\r' and self.field[self.pos+1]
in '\t':
+ self.pos += 2
            elif self.field[self.pos] in self.phraseends:
                break
            else:
                plist.append(self.getatom(self.phraseends))

        return plist
----------------------------------------

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.