[Mailman-Developers] Patch #102268

Erik Forsberg forsberg@lysator.liu.se
Sun, 12 Nov 2000 02:29:24 +0100 (CET)


Barry A. Warsaw writes:
>You did, I just had to do it differently. :)  

But of course :-)

>See the updated patch on, or grab the CVS snapshot.

I would do it a bit different, for two reasons.

1) What happends if there is no Content-Transfer-Encoding header in
the mail? Well.. cenc will get the "value" None. What happends if you
do a string.lower on None?

>>> string.lower(None)
Traceback (innermost last):
  File "<stdin>", line 1, in ?
TypeError: read-only character buffer, None

So guess why my 'if' where there.. And yes, I had a mail where there
were no such header.

Later in the code, there is a check whether self.cenc is None, so it
should hold that value.

2) There is a perhaps more readable way of setting ctype to
'text/plain' if there were no such header:

`getheader(name[, default])'
     Like `getrawheader(NAME)', but strip leading and trailing
     whitespace.  Internal whitespace is not stripped.  The optional
     DEFAULT argument can be used to specify a different default to be

Mostly a cosmetic change, though. The current code looks a bit too
much like Perl to me ;).

Revised patch follows (Note: I edited the patch by hand. Will verify
and upload to sourceforge sometime tomorrow^H^H^H^H^H^Hday (when it's
not 02:27 in the morning..)):

Index: HyperArch.py
===================================================================
RCS file: /cvsroot/mailman/mailman/Mailman/Archiver/HyperArch.py,v
retrieving revision 1.44
diff -u -r1.44 HyperArch.py
--- HyperArch.py        2000/11/10 15:24:53     1.44
+++ HyperArch.py        2000/11/10 23:44:17
@@ -216,9 +216,12 @@
         if mm_cfg.ARCHIVER_OBSCURES_EMAILADDRS:
             self.email = re.sub('@', ' at ', self.email)
 
-        # snag the content-type
-        self.ctype = message.getheader('Content-Type') or "text/plain"
-        self.cenc = message.getheader('Content-Transfer-Encoding')
+        # Snag the content-* headers.  RFC 1521 states that their values are
+        # case insensitive.
+        ctype = message.getheader('Content-Type', "text/plain")
+        self.cenc = message.getheader('Content-Transfer-Encoding')
+        self.ctype = string.lower(ctype)
+	 if None != self.cenc:
+	    self.cenc = string.lower(self.cenc)
         self.decoded = {}
         mo = rx_charset.search(self.ctype)
         if mo:

\EF
-- 
Erik Forsberg                 http://www.lysator.liu.se/~forsberg/
PGP fingerprint = 37 1B D7 9E 97 8C EF 39  0E DE 08 E8 99 0C 5E A9