Merge lp:~james-page/ubuntu/hardy/mailman/fix-659975 into lp:ubuntu/hardy/mailman

Proposed by James Page
Status: Merged
Merge reported by: Mathias Gug
Merged at revision: not available
Proposed branch: lp:~james-page/ubuntu/hardy/mailman/fix-659975
Merge into: lp:ubuntu/hardy/mailman
Diff against target: 513 lines (+488/-0)
3 files modified
debian/changelog (+7/-0)
debian/email-2.5.8-patches/email/_parseaddr.py (+478/-0)
debian/rules (+3/-0)
To merge this branch: bzr merge lp:~james-page/ubuntu/hardy/mailman/fix-659975
Reviewer Review Type Date Requested Status
Mathias Gug Approve
Chuck Short Pending
Ubuntu Development Team Pending
Review via email: mp+38709@code.launchpad.net

Description of the change

This branch fixes a minor email parsing issue in mailman 2.1.9 which actually resides in the bundled version of the Python email package distributed with this release.

The patched file is overlaid ontop of the extracted .tar.gz during the package build process.

Later versions of Ubuntu do not have this issue as the bundling was removed in later versions.

To post a comment you must log in.
Revision history for this message
Mathias Gug (mathiaz) wrote :

Looks good to me. Uploaded to hardy-proposed.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2008-03-07 02:55:22 +0000
3+++ debian/changelog 2010-10-18 11:31:08 +0000
4@@ -1,3 +1,10 @@
5+mailman (1:2.1.9-9ubuntu1.1) hardy-proposed; urgency=low
6+
7+ * Patched bundled python-2.5.8 email package to correctly parse
8+ email addresses (LP: #659975)
9+
10+ -- James Page <james.page@canonical.com> Thu, 14 Oct 2010 15:43:11 +0100
11+
12 mailman (1:2.1.9-9ubuntu1) hardy; urgency=low
13
14 * debian/control:
15
16=== added directory 'debian/email-2.5.8-patches'
17=== added directory 'debian/email-2.5.8-patches/email'
18=== added file 'debian/email-2.5.8-patches/email/_parseaddr.py'
19--- debian/email-2.5.8-patches/email/_parseaddr.py 1970-01-01 00:00:00 +0000
20+++ debian/email-2.5.8-patches/email/_parseaddr.py 2010-10-18 11:31:08 +0000
21@@ -0,0 +1,478 @@
22+# Copyright (C) 2002-2006 Python Software Foundation
23+
24+"""Email address parsing code.
25+
26+Lifted directly from rfc822.py. This should eventually be rewritten.
27+"""
28+
29+import time
30+from types import TupleType
31+
32+try:
33+ True, False
34+except NameError:
35+ True = 1
36+ False = 0
37+
38+SPACE = ' '
39+EMPTYSTRING = ''
40+COMMASPACE = ', '
41+
42+# Parse a date field
43+_monthnames = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul',
44+ 'aug', 'sep', 'oct', 'nov', 'dec',
45+ 'january', 'february', 'march', 'april', 'may', 'june', 'july',
46+ 'august', 'september', 'october', 'november', 'december']
47+
48+_daynames = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']
49+
50+# The timezone table does not include the military time zones defined
51+# in RFC822, other than Z. According to RFC1123, the description in
52+# RFC822 gets the signs wrong, so we can't rely on any such time
53+# zones. RFC1123 recommends that numeric timezone indicators be used
54+# instead of timezone names.
55+
56+_timezones = {'UT':0, 'UTC':0, 'GMT':0, 'Z':0,
57+ 'AST': -400, 'ADT': -300, # Atlantic (used in Canada)
58+ 'EST': -500, 'EDT': -400, # Eastern
59+ 'CST': -600, 'CDT': -500, # Central
60+ 'MST': -700, 'MDT': -600, # Mountain
61+ 'PST': -800, 'PDT': -700 # Pacific
62+ }
63+
64+
65+def parsedate_tz(data):
66+ """Convert a date string to a time tuple.
67+
68+ Accounts for military timezones.
69+ """
70+ data = data.split()
71+ # The FWS after the comma after the day-of-week is optional, so search and
72+ # adjust for this.
73+ if data[0].endswith(',') or data[0].lower() in _daynames:
74+ # There's a dayname here. Skip it
75+ del data[0]
76+ else:
77+ i = data[0].rfind(',')
78+ if i >= 0:
79+ data[0] = data[0][i+1:]
80+ if len(data) == 3: # RFC 850 date, deprecated
81+ stuff = data[0].split('-')
82+ if len(stuff) == 3:
83+ data = stuff + data[1:]
84+ if len(data) == 4:
85+ s = data[3]
86+ i = s.find('+')
87+ if i > 0:
88+ data[3:] = [s[:i], s[i+1:]]
89+ else:
90+ data.append('') # Dummy tz
91+ if len(data) < 5:
92+ return None
93+ data = data[:5]
94+ [dd, mm, yy, tm, tz] = data
95+ mm = mm.lower()
96+ if mm not in _monthnames:
97+ dd, mm = mm, dd.lower()
98+ if mm not in _monthnames:
99+ return None
100+ mm = _monthnames.index(mm) + 1
101+ if mm > 12:
102+ mm -= 12
103+ if dd[-1] == ',':
104+ dd = dd[:-1]
105+ i = yy.find(':')
106+ if i > 0:
107+ yy, tm = tm, yy
108+ if yy[-1] == ',':
109+ yy = yy[:-1]
110+ if not yy[0].isdigit():
111+ yy, tz = tz, yy
112+ if tm[-1] == ',':
113+ tm = tm[:-1]
114+ tm = tm.split(':')
115+ if len(tm) == 2:
116+ [thh, tmm] = tm
117+ tss = '0'
118+ elif len(tm) == 3:
119+ [thh, tmm, tss] = tm
120+ else:
121+ return None
122+ try:
123+ yy = int(yy)
124+ dd = int(dd)
125+ thh = int(thh)
126+ tmm = int(tmm)
127+ tss = int(tss)
128+ except ValueError:
129+ return None
130+ tzoffset = None
131+ tz = tz.upper()
132+ if _timezones.has_key(tz):
133+ tzoffset = _timezones[tz]
134+ else:
135+ try:
136+ tzoffset = int(tz)
137+ except ValueError:
138+ pass
139+ # Convert a timezone offset into seconds ; -0500 -> -18000
140+ if tzoffset:
141+ if tzoffset < 0:
142+ tzsign = -1
143+ tzoffset = -tzoffset
144+ else:
145+ tzsign = 1
146+ tzoffset = tzsign * ( (tzoffset/100)*3600 + (tzoffset % 100)*60)
147+ return yy, mm, dd, thh, tmm, tss, 0, 1, 0, tzoffset
148+
149+
150+def parsedate(data):
151+ """Convert a time string to a time tuple."""
152+ t = parsedate_tz(data)
153+ if isinstance(t, TupleType):
154+ return t[:9]
155+ else:
156+ return t
157+
158+
159+def mktime_tz(data):
160+ """Turn a 10-tuple as returned by parsedate_tz() into a UTC timestamp."""
161+ if data[9] is None:
162+ # No zone info, so localtime is better assumption than GMT
163+ return time.mktime(data[:8] + (-1,))
164+ else:
165+ t = time.mktime(data[:8] + (0,))
166+ return t - data[9] - time.timezone
167+
168+
169+def quote(str):
170+ """Add quotes around a string."""
171+ return str.replace('\\', '\\\\').replace('"', '\\"')
172+
173+
174+class AddrlistClass:
175+ """Address parser class by Ben Escoto.
176+
177+ To understand what this class does, it helps to have a copy of RFC 2822 in
178+ front of you.
179+
180+ Note: this class interface is deprecated and may be removed in the future.
181+ Use rfc822.AddressList instead.
182+ """
183+
184+ def __init__(self, field):
185+ """Initialize a new instance.
186+
187+ `field' is an unparsed address header field, containing
188+ one or more addresses.
189+ """
190+ self.specials = '()<>@,:;.\"[]'
191+ self.pos = 0
192+ self.LWS = ' \t'
193+ self.CR = '\r\n'
194+ self.FWS = self.LWS + self.CR
195+ self.atomends = self.specials + self.LWS + self.CR
196+ # Note that RFC 2822 now specifies `.' as obs-phrase, meaning that it
197+ # is obsolete syntax. RFC 2822 requires that we recognize obsolete
198+ # syntax, so allow dots in phrases.
199+ self.phraseends = self.atomends.replace('.', '')
200+ self.field = field
201+ self.commentlist = []
202+
203+ def gotonext(self):
204+ """Parse up to the start of the next address."""
205+ while self.pos < len(self.field):
206+ if self.field[self.pos] in self.LWS + '\n\r':
207+ self.pos += 1
208+ elif self.field[self.pos] == '(':
209+ self.commentlist.append(self.getcomment())
210+ else:
211+ break
212+
213+ def getaddrlist(self):
214+ """Parse all addresses.
215+
216+ Returns a list containing all of the addresses.
217+ """
218+ result = []
219+ while self.pos < len(self.field):
220+ ad = self.getaddress()
221+ if ad:
222+ result += ad
223+ else:
224+ result.append(('', ''))
225+ return result
226+
227+ def getaddress(self):
228+ """Parse the next address."""
229+ self.commentlist = []
230+ self.gotonext()
231+
232+ oldpos = self.pos
233+ oldcl = self.commentlist
234+ plist = self.getphraselist()
235+
236+ self.gotonext()
237+ returnlist = []
238+
239+ if self.pos >= len(self.field):
240+ # Bad email address technically, no domain.
241+ if plist:
242+ returnlist = [(SPACE.join(self.commentlist), plist[0])]
243+
244+ elif self.field[self.pos] in '.@':
245+ # email address is just an addrspec
246+ # this isn't very efficient since we start over
247+ self.pos = oldpos
248+ self.commentlist = oldcl
249+ addrspec = self.getaddrspec()
250+ returnlist = [(SPACE.join(self.commentlist), addrspec)]
251+
252+ elif self.field[self.pos] == ':':
253+ # address is a group
254+ returnlist = []
255+
256+ fieldlen = len(self.field)
257+ self.pos += 1
258+ while self.pos < len(self.field):
259+ self.gotonext()
260+ if self.pos < fieldlen and self.field[self.pos] == ';':
261+ self.pos += 1
262+ break
263+ returnlist = returnlist + self.getaddress()
264+
265+ elif self.field[self.pos] == '<':
266+ # Address is a phrase then a route addr
267+ routeaddr = self.getrouteaddr()
268+
269+ if self.commentlist:
270+ returnlist = [(SPACE.join(plist) + ' (' +
271+ ' '.join(self.commentlist) + ')', routeaddr)]
272+ else:
273+ returnlist = [(SPACE.join(plist), routeaddr)]
274+
275+ else:
276+ if plist:
277+ returnlist = [(SPACE.join(self.commentlist), plist[0])]
278+ elif self.field[self.pos] in self.specials:
279+ self.pos += 1
280+
281+ self.gotonext()
282+ if self.pos < len(self.field) and self.field[self.pos] == ',':
283+ self.pos += 1
284+ return returnlist
285+
286+ def getrouteaddr(self):
287+ """Parse a route address (Return-path value).
288+
289+ This method just skips all the route stuff and returns the addrspec.
290+ """
291+ if self.field[self.pos] != '<':
292+ return
293+
294+ expectroute = False
295+ self.pos += 1
296+ self.gotonext()
297+ adlist = ''
298+ while self.pos < len(self.field):
299+ if expectroute:
300+ self.getdomain()
301+ expectroute = False
302+ elif self.field[self.pos] == '>':
303+ self.pos += 1
304+ break
305+ elif self.field[self.pos] == '@':
306+ self.pos += 1
307+ expectroute = True
308+ elif self.field[self.pos] == ':':
309+ self.pos += 1
310+ else:
311+ adlist = self.getaddrspec()
312+ self.pos += 1
313+ break
314+ self.gotonext()
315+
316+ return adlist
317+
318+ def getaddrspec(self):
319+ """Parse an RFC 2822 addr-spec."""
320+ aslist = []
321+
322+ self.gotonext()
323+ while self.pos < len(self.field):
324+ if self.field[self.pos] == '.':
325+ aslist.append('.')
326+ self.pos += 1
327+ elif self.field[self.pos] == '"':
328+ aslist.append('"%s"' % self.getquote())
329+ elif self.field[self.pos] in self.atomends:
330+ break
331+ else:
332+ aslist.append(self.getatom())
333+ self.gotonext()
334+
335+ if self.pos >= len(self.field) or self.field[self.pos] != '@':
336+ return EMPTYSTRING.join(aslist)
337+
338+ aslist.append('@')
339+ self.pos += 1
340+ self.gotonext()
341+ return EMPTYSTRING.join(aslist) + self.getdomain()
342+
343+ def getdomain(self):
344+ """Get the complete domain name from an address."""
345+ sdlist = []
346+ while self.pos < len(self.field):
347+ if self.field[self.pos] in self.LWS:
348+ self.pos += 1
349+ elif self.field[self.pos] == '(':
350+ self.commentlist.append(self.getcomment())
351+ elif self.field[self.pos] == '[':
352+ sdlist.append(self.getdomainliteral())
353+ elif self.field[self.pos] == '.':
354+ self.pos += 1
355+ sdlist.append('.')
356+ elif self.field[self.pos] in self.atomends:
357+ break
358+ else:
359+ sdlist.append(self.getatom())
360+ return EMPTYSTRING.join(sdlist)
361+
362+ def getdelimited(self, beginchar, endchars, allowcomments=True):
363+ """Parse a header fragment delimited by special characters.
364+
365+ `beginchar' is the start character for the fragment.
366+ If self is not looking at an instance of `beginchar' then
367+ getdelimited returns the empty string.
368+
369+ `endchars' is a sequence of allowable end-delimiting characters.
370+ Parsing stops when one of these is encountered.
371+
372+ If `allowcomments' is non-zero, embedded RFC 2822 comments are allowed
373+ within the parsed fragment.
374+ """
375+ if self.field[self.pos] != beginchar:
376+ return ''
377+
378+ slist = ['']
379+ quote = False
380+ self.pos += 1
381+ while self.pos < len(self.field):
382+ if quote:
383+ slist.append(self.field[self.pos])
384+ quote = False
385+ elif self.field[self.pos] in endchars:
386+ self.pos += 1
387+ break
388+ elif allowcomments and self.field[self.pos] == '(':
389+ slist.append(self.getcomment())
390+ continue # have already advanced pos from getcomment
391+ elif self.field[self.pos] == '\\':
392+ quote = True
393+ else:
394+ slist.append(self.field[self.pos])
395+ self.pos += 1
396+
397+ return EMPTYSTRING.join(slist)
398+
399+ def getquote(self):
400+ """Get a quote-delimited fragment from self's field."""
401+ return self.getdelimited('"', '"\r', False)
402+
403+ def getcomment(self):
404+ """Get a parenthesis-delimited fragment from self's field."""
405+ return self.getdelimited('(', ')\r', True)
406+
407+ def getdomainliteral(self):
408+ """Parse an RFC 2822 domain-literal."""
409+ return '[%s]' % self.getdelimited('[', ']\r', False)
410+
411+ def getatom(self, atomends=None):
412+ """Parse an RFC 2822 atom.
413+
414+ Optional atomends specifies a different set of end token delimiters
415+ (the default is to use self.atomends). This is used e.g. in
416+ getphraselist() since phrase endings must not include the `.' (which
417+ is legal in phrases)."""
418+ atomlist = ['']
419+ if atomends is None:
420+ atomends = self.atomends
421+
422+ while self.pos < len(self.field):
423+ if self.field[self.pos] in atomends:
424+ break
425+ else:
426+ atomlist.append(self.field[self.pos])
427+ self.pos += 1
428+
429+ return EMPTYSTRING.join(atomlist)
430+
431+ def getphraselist(self):
432+ """Parse a sequence of RFC 2822 phrases.
433+
434+ A phrase is a sequence of words, which are in turn either RFC 2822
435+ atoms or quoted-strings. Phrases are canonicalized by squeezing all
436+ runs of continuous whitespace into one space.
437+ """
438+ plist = []
439+
440+ while self.pos < len(self.field):
441+ if self.field[self.pos] in self.FWS:
442+ self.pos += 1
443+ elif self.field[self.pos] == '"':
444+ plist.append(self.getquote())
445+ elif self.field[self.pos] == '(':
446+ self.commentlist.append(self.getcomment())
447+ elif self.field[self.pos] in self.phraseends:
448+ break
449+ else:
450+ plist.append(self.getatom(self.phraseends))
451+
452+ return plist
453+
454+class AddressList(AddrlistClass):
455+ """An AddressList encapsulates a list of parsed RFC 2822 addresses."""
456+ def __init__(self, field):
457+ AddrlistClass.__init__(self, field)
458+ if field:
459+ self.addresslist = self.getaddrlist()
460+ else:
461+ self.addresslist = []
462+
463+ def __len__(self):
464+ return len(self.addresslist)
465+
466+ def __add__(self, other):
467+ # Set union
468+ newaddr = AddressList(None)
469+ newaddr.addresslist = self.addresslist[:]
470+ for x in other.addresslist:
471+ if not x in self.addresslist:
472+ newaddr.addresslist.append(x)
473+ return newaddr
474+
475+ def __iadd__(self, other):
476+ # Set union, in-place
477+ for x in other.addresslist:
478+ if not x in self.addresslist:
479+ self.addresslist.append(x)
480+ return self
481+
482+ def __sub__(self, other):
483+ # Set difference
484+ newaddr = AddressList(None)
485+ for x in self.addresslist:
486+ if not x in other.addresslist:
487+ newaddr.addresslist.append(x)
488+ return newaddr
489+
490+ def __isub__(self, other):
491+ # Set difference, in-place
492+ for x in other.addresslist:
493+ if x in self.addresslist:
494+ self.addresslist.remove(x)
495+ return self
496+
497+ def __getitem__(self, index):
498+ # Make indexing, slices, and 'in' work
499+ return self.addresslist[index]
500
501=== modified file 'debian/rules'
502--- debian/rules 2007-12-04 09:12:39 +0000
503+++ debian/rules 2010-10-18 11:31:08 +0000
504@@ -147,6 +147,9 @@
505 # apache default config
506 install -m 0644 debian/contrib/apache.conf debian/mailman/etc/mailman
507
508+# Patch mailman supplied fork of email-2.5.8 to fix bug parsing email addresses
509+ install -m 0644 debian/email-2.5.8-patches/email/_parseaddr.py debian/mailman/usr/lib/mailman/pythonlib/email/_parseaddr.py
510+
511 # Move templates
512 mv `find debian/mailman/etc/mailman -mindepth 1 -maxdepth 1 -type d` debian/mailman/usr/share/mailman
513 cp build/contrib/qmail-to-mailman.py debian/mailman/usr/share/mailman

Subscribers

People subscribed via source and target branches

to all changes: