[Mailman-Developers] [PATCH] Fix endless prefix adding with q-p/base64 Subject lines

Ben Gertzfield che@debian.org
Mon, 8 Apr 2002 01:51:00 +0900


--Apple-Mail-1--911129101
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed

On Monday, April 8, 2002, at 01:05 , Fil wrote:

> This is a two-prefix subject line (taken from the mailman .mbox file, in
> order to be sure)
>
>     Subject: [Spip] =?iso-8859-1?Q?Re:_=5BSpip=5D_exclusion_mot_cl=E9s?=
>

Fil,

I just checked CVS and you are indeed right.  I thought I had sent this 
patch in ages ago, but I can't find it in the archives.

Barry, this patch to CookHeaders.py fixes this issue of endless prefix 
string adding if the Subject line gets encoded, by decoding the Subject 
line before searching for the prefix.  It encodes the new prefix if 
needed as a separate chunk in the new Subject header.  This will allow 
for Japanese, French, whatever prefix strings.

I really apologize, I thought it was sent in and applied many moons 
ago.  I need a better brain. :)

I'm attaching the patch, but this is the crazy Mac OS X Mail.app, so who 
knows if it will be readable or not.  In case it's not, here is a URL 
for the patch:

http://people.debian.org/~che/mailman/patches/cook-headers.patch

Ben


--Apple-Mail-1--911129101
Content-Disposition: attachment;
	filename=cook-headers.patch
Content-Transfer-Encoding: quoted-printable
Content-Type: application/octet-stream;
	x-unix-mode=0644;
	name="cook-headers.patch"

Index:=20CookHeaders.py=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0ARCS=20file:=20=
/cvsroot/mailman/mailman/Mailman/Handlers/CookHeaders.py,v=0Aretrieving=20=
revision=202.9=0Adiff=20-u=20-r2.9=20CookHeaders.py=0A---=20=
CookHeaders.py=092001/12/19=2007:01:49=092.9=0A+++=20CookHeaders.py=09=
2002/02/04=2007:07:38=0A@@=20-19,6=20+19,8=20@@=0A=20=0A=20import=20re=0A=
=20=0A+from=20email.Charset=20import=20Charset=0A+from=20email.Header=20=
import=20Header,=20decode_header=0A=20import=20email.Utils=0A=20=0A=20=
from=20Mailman=20import=20mm_cfg=0A@@=20-28,8=20+30,8=20@@=0A=20=0A=20=
CONTINUATION=20=3D=20',\n\t'=0A=20COMMASPACE=20=3D=20',=20'=0A=
+MAXLINELEN=20=3D=2078=0A=20=0A-=0A=20=0C=0A=20def=20process(mlist,=20=
msg,=20msgdata):=0A=20=20=20=20=20#=20Set=20the=20"X-Ack:=20no"=20header=20=
if=20noack=20flag=20is=20set.=0A@@=20-51,13=20+53,37=20@@=0A=20=20=20=20=20=
=20=20=20=20#=20such=20as=20the=20list=20admin).=20=20We=20assume=20all=20=
digests=20have=20an=20appropriate=0A=20=20=20=20=20=20=20=20=20#=20=
subject=20header=20added=20by=20the=20ToDigest=20module.=0A=20=20=20=20=20=
=20=20=20=20prefix=20=3D=20mlist.subject_prefix=0A+=20=20=20=20=20=20=20=20=
#=20The=20header=20may=20be=20multilingual;=20decode=20it=20from=20=
base64/quopri=20and=0A+=20=20=20=20=20=20=20=20#=20search=20each=20chunk=20=
for=20the=20prefix.=0A+=20=20=20=20=20=20=20=20has_prefix=20=3D=200=0A+=20=
=20=20=20=20=20=20=20if=20prefix=20and=20subject:=0A+=20=20=20=20=20=20=20=
=20=20=20=20=20for=20s,=20e=20in=20decode_header(msg['subject']):=0A+=20=20=
=20=20=20=20=20=20=20=20=20=20=20=20=20=20if=20=
re.search(re.escape(prefix.strip()),=20s,=20re.I):=0A+=20=20=20=20=20=20=20=
=20=20=20=20=20=20=20=20=20=20=20=20=20has_prefix=20=3D=201=0A+=20=20=20=20=
=20=20=20=20cset=20=3D=20=
Charset(Utils.GetCharSet(mlist.preferred_language))=0A=20=20=20=20=20=20=20=
=20=20#=20We=20purposefully=20leave=20no=20space=20b/w=20prefix=20and=20=
subject!=0A=20=20=20=20=20=20=20=20=20if=20not=20subject:=0A=20=20=20=20=20=
=20=20=20=20=20=20=20=20del=20msg['subject']=0A-=20=20=20=20=20=20=20=20=20=
=20=20=20msg['Subject']=20=3D=20prefix=20+=20_('(no=20subject)')=0A-=20=20=
=20=20=20=20=20=20elif=20prefix=20and=20not=20=
re.search(re.escape(prefix),=20subject,=20re.I):=0A+=20=20=20=20=20=20=20=
=20=20=20=20=20new_subject=20=3D=20Header(prefix=20+=20_('(no=20=
subject)'),=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=
=20=20=20=20=20=20=20=20=20=20=20=20=20cset,=20header_name=3D"Subject")=0A=
+=20=20=20=20=20=20=20=20=20=20=20=20msg['Subject']=20=3D=20=
new_subject.encode()=0A+=20=20=20=20=20=20=20=20elif=20prefix=20and=20=
not=20has_prefix:=0A=20=20=20=20=20=20=20=20=20=20=20=20=20del=20=
msg['subject']=0A-=20=20=20=20=20=20=20=20=20=20=20=20msg['Subject']=20=3D=
=20prefix=20+=20subject=0A+=20=20=20=20=20=20=20=20=20=20=20=20#=20We'll=20=
encode=20the=20new=20prefix=20(just=20in=20case)=20but=20leave=20the=20=
old=0A+=20=20=20=20=20=20=20=20=20=20=20=20#=20subject=20alone,=20in=20=
case=20it=20was=20already=20encoded.=0A+=20=20=20=20=20=20=20=20=20=20=20=
=20new_subject=20=3D=20Header(prefix,=20cset,=20=
header_name=3D"Subject").encode()=0A+=20=20=20=20=20=20=20=20=20=20=20=20=
#=20If=20we=20go=20over=2076=20characters=20with=20the=20prefix,=20just=20=
put=20the=0A+=20=20=20=20=20=20=20=20=20=20=20=20#=20old=20subject=20on=20=
its=20own=20line.=0A+=20=20=20=20=20=20=20=20=20=20=20=20first=20=3D=20=
subject.split("\n")[0]=0A+=20=20=20=20=20=20=20=20=20=20=20=20if=20=
len(new_subject=20+=20first)=20+=201=20>=3D=20MAXLINELEN=20-=20=
len("Subject:=20"):=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=
new_subject=20+=3D=20'\n=20'=0A+=20=20=20=20=20=20=20=20=20=20=20=20#=20=
We=20might=20have=20to=20add=20a=20space=20because=20the=20prefix=20and=20=
old=0A+=20=20=20=20=20=20=20=20=20=20=20=20#=20subject=20may=20both=20be=20=
MIME-encoded,=20losing=20the=20space=20at=0A+=20=20=20=20=20=20=20=20=20=20=
=20=20#=20the=20end=20of=20the=20prefix.=0A+=20=20=20=20=20=20=20=20=20=20=
=20=20elif=20new_subject[-1]=20<>=20'=20':=0A+=20=20=20=20=20=20=20=20=20=
=20=20=20=20=20=20=20new_subject=20+=3D=20'=20'=0A+=20=20=20=20=20=20=20=20=
=20=20=20=20new_subject=20+=3D=20subject=0A+=20=20=20=20=20=20=20=20=20=20=
=20=20msg['Subject']=20=3D=20new_subject=0A=20=20=20=20=20#=20get=20rid=20=
of=20duplicate=20headers=0A=20=20=20=20=20del=20msg['sender']=0A=20=20=20=
=20=20del=20msg['errors-to']=0A=

--Apple-Mail-1--911129101--