CVS: tmda-cgi CgiUtil.py,1.24,1.25 View.py,1.22,1.23

Jim Ramsay <[email protected]> Wed, 18 Feb 2004 09:10:04 -0800
Newsgroups gmane.mail.spam.tmda.cvs
Message-ID <[email protected]>
Update of /cvsroot/tmda/tmda-cgi
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24010

Modified Files:
	CgiUtil.py View.py 
Log Message:
Fixed a bug with Charset processing as reported by Brian Ipsen.

Basicly, the Email classes do NOT return sane data if the Content-type is text/html AND includes a boundary descriptor.  I hope I didn't break regular charset handling... but then that's what CVS versions are for :)


Index: CgiUtil.py
===================================================================
RCS file: /cvsroot/tmda/tmda-cgi/CgiUtil.py,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- CgiUtil.py	4 Feb 2004 20:56:23 -0000	1.24
+++ CgiUtil.py	18 Feb 2004 17:09:50 -0000	1.25
@@ -168,7 +168,7 @@
   RetVal = None
   for Part in MsgObj.msgobj.walk():
     CS = Part.get_content_charset()
-    if CS: RetVal = CS
+    if CS: RetVal = CS.split()[0]
   return RetVal
 
 def getFilterOptions():

Index: View.py
===================================================================
RCS file: /cvsroot/tmda/tmda-cgi/View.py,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- View.py	5 Dec 2003 18:44:23 -0000	1.22
+++ View.py	18 Feb 2004 17:09:50 -0000	1.23
@@ -226,7 +226,8 @@
       for decoded in email.Header.decode_header( Line ):
         Headers += decoded[0] + " "
         if decoded[1]:
-          T["CharSet"] = email.Charset.Charset(decoded[1]).input_charset
+          cset = email.Charset.Charset(decoded[1]).input_charset.split()
+          T["CharSet"] = cset[0]
       Headers += "\n"
     T["Headers"] = '<pre class="Headers">%s</pre>' % Headers
   else:
@@ -241,7 +242,8 @@
       for decoded in email.Header.decode_header( MsgObj.msgobj[Header] ):
         value += decoded[0] + " "
         if decoded[1]:
-          T["CharSet"] = email.Charset.Charset(decoded[1]).input_charset
+          cset = email.Charset.Charset(decoded[1]).input_charset.split()
+          T["CharSet"] = cset[0]
       T["Value"] = CgiUtil.Escape(value)
       HeaderRow.Add()
 
@@ -351,8 +353,8 @@
     if Type == "text/plain":
       # Check if there's a character set for this part.
       if Part.get_content_charset():
-        T["CharSet"] = \
-          email.Charset.Charset(Part.get_content_charset()).input_charset
+        cset = email.Charset.Charset(Part.get_content_charset()).input_charset.split()
+        T["CharSet"] = cset[0]
       # Escape & display
       try:
         Str = Part.get_payload(decode=1).strip()
@@ -366,8 +368,8 @@
       # Sterilize & display
       # Check if there's a character set for this part.
       if Part.get_content_charset():
-        T["CharSet"] = \
-          email.Charset.Charset(Part.get_content_charset()).input_charset
+        cset = email.Charset.Charset(Part.get_content_charset()).input_charset.split()
+        T["CharSet"] = cset[0]
       try:
         T["Content"] = \
           CgiUtil.Sterilize(Part.get_payload(decode=1), Allow, Remove)