Comment 4 for bug 557972

Revision history for this message
fabiorossetti (fabiorossetti) wrote :

Logged In: YES
user_id=693899

If you need a quick fix to make the patch work with 2.1.1
here's my take (it's the diff file adapted to work with 2.1.1
CookHeaders.py)

17a18
> (sequence version)
221c222,223
< prefix = mlist.subject_prefix
---
> prefix = mlist.subject_prefix.strip();
> if not prefix: return
237,243c239,250
< if prefix and subject:
< pattern = re.escape(prefix.strip())
< for decodedsubj, charset in headerbits:
< if re.search(pattern, decodedsubj,
re.IGNORECASE):
< # The subject's already got the prefix, so don't
change it
< return
< del msg['subject']
---
> headerstring = ''
> fws = ''
> cset = None
> for (s, c) in headerbits:
> headerstring += fws + s
> if c == None or c == 'us-ascii':
> fws = ' '
> cset = Utils.GetCharSet(mlist.preferred_language)
> else:
> fws = ''
> cset = c
> # Note: searching prefix in subject is REMOVED. (seq
version)
245a253,275
> else:
> subject = headerstring
> # If the subject_prefix contains '%d', it is replaced with
the
> # mailing list sequential number. Also, if the prefix is
closed with
> # [],(), or {}, the prefix in the responding post subject will
be cared.
> # sequential number format allows '%05d' like pattern.
> p = re.compile('%\d*d')
> if p.search(prefix,1):
> # prefix have number, so we should search prefix
w/number
> # in subject.
> prefix_pattern = p.sub(r'\s*\d+\s*', prefix)
> else:
> prefix_pattern = prefix
> prefix_pattern = re.sub('([\[\(\{])', '\\\\\g<1>', prefix_pattern)
> subject = re.sub(prefix_pattern, '', subject)
> subject = re.compile('(RE:\s*)+', re.I).sub('Re: ', subject,
1)
> # and substitute %d in prefix with post_id
> try:
> prefix = prefix % mlist.post_id
> except:
> pass
> # Note that trailing space was stripped in seq version
(TK)
> prefix += ' '
248,262c278,288
< for s, c in headerbits:
< # Once again, convert the string to unicode.
< if c is None:
< c = Charset('iso-8859-1')
< if not isinstance(c, Charset):
< c = Charset(c)
< if not _isunicode(s):
< codec = c.input_codec or 'ascii'
< try:
< s = unicode(s, codec, 'replace')
< except LookupError:
< # Unknown codec, is this default reasonable?
< s = unicode(s, Utils.GetCharSet
(mlist.preferred_language),
< 'replace')
< h.append(s, c)
---
> # in seq version, subject header is already concatnated
> if not _isunicode(subject):
> try:
> subject = unicode(subject, cset, 'replace')
> except LookupError:
> # unknown codec
> cset = Utils.GetCharSet(mlist.preferred_language)
> subject = unicode(subject, cset, 'replace')
> subject = subject.encode(cset)
> h.append(subject, cset)
> del msg['subject']