Update of /cvsroot/mailman/mailman/Mailman/Handlers
In directory sc8-pr-cvs1:/tmp/cvs-serv18484/Mailman/Handlers

Modified Files:
      Tag: Release_2_1-maint
        Scrubber.py 
Log Message:
True/False where appropriate.

process(): When we encode the text, catch ValueError along with UnicodeError
and LookupError.  The ValueError can be raised if the charset is the empty
string.  Closes SF bug # 834486.


Index: Scrubber.py
===================================================================
RCS file: /cvsroot/mailman/mailman/Mailman/Handlers/Scrubber.py,v
retrieving revision 2.18.2.4
retrieving revision 2.18.2.5
diff -u -d -r2.18.2.4 -r2.18.2.5
--- Scrubber.py 22 Sep 2003 02:37:51 -0000      2.18.2.4
+++ Scrubber.py 1 Dec 2003 01:41:05 -0000       2.18.2.5
@@ -53,10 +53,17 @@
 SPACE = ' '
 
 try:
+    True, False
+except NameError:
+    True = 1
+    False = 0
+
+
+try:
     from mimetypes import guess_all_extensions
 except ImportError:
     import mimetypes
-    def guess_all_extensions(ctype, strict=1):
+    def guess_all_extensions(ctype, strict=True):
         # BAW: sigh, guess_all_extensions() is new in Python 2.3
         all = []
         def check(map):
@@ -76,7 +83,7 @@
     # and .wiz are all mapped to application/msword.  This sucks for finding
     # the best reverse mapping.  If the extension is one of the giving
     # mappings, we'll trust that, otherwise we'll just guess. :/
-    all = guess_all_extensions(ctype, strict=0)
+    all = guess_all_extensions(ctype, strict=False)
     if ext in all:
         return ext
     return all and all[0]
@@ -93,8 +100,9 @@
 # This isn't perfect because we still get stuff like the multipart boundaries,
 # but see below for how we corrupt that to our nefarious goals.
 class ScrubberGenerator(Generator):
-    def __init__(self, outfp, mangle_from_=1, maxheaderlen=78, skipheaders=1):
-        Generator.__init__(self, outfp, mangle_from_=0)
+    def __init__(self, outfp, mangle_from_=True,
+                 maxheaderlen=78, skipheaders=True):
+        Generator.__init__(self, outfp, mangle_from_=False)
         self.__skipheaders = skipheaders
 
     def _write_headers(self, msg):
@@ -156,7 +164,7 @@
 
 def process(mlist, msg, msgdata=None):
     sanitize = mm_cfg.ARCHIVE_HTML_SANITIZER
-    outer = 1
+    outer = True
     if msgdata is None:
         msgdata = {}
     dir = calculate_attachments_dir(mlist, msg, msgdata)
@@ -190,7 +198,7 @@
                 # lists.
                 omask = os.umask(002)
                 try:
-                    url = save_attachment(mlist, part, dir, filter_html=0)
+                    url = save_attachment(mlist, part, dir, filter_html=False)
                 finally:
                     os.umask(omask)
                 del part['content-type']
@@ -201,7 +209,7 @@
             else:
                 # HTML-escape it and store it as an attachment, but make it
                 # look a /little/ bit prettier. :(
-                payload = Utils.websafe(part.get_payload(decode=1))
+                payload = Utils.websafe(part.get_payload(decode=True))
                 # For whitespace in the margin, change spaces into
                 # non-breaking spaces, and tabs into 8 of those.  Then use a
                 # mono-space font.  Still looks hideous to me, but then I'd
@@ -216,7 +224,7 @@
                 del part['content-transfer-encoding']
                 omask = os.umask(002)
                 try:
-                    url = save_attachment(mlist, part, dir, filter_html=0)
+                    url = save_attachment(mlist, part, dir, filter_html=False)
                 finally:
                     os.umask(omask)
                 del part['content-type']
@@ -249,7 +257,7 @@
         # attachment that would have to be separately downloaded.  Pipermail
         # will transform the url into a hyperlink.
         elif not part.is_multipart():
-            payload = part.get_payload(decode=1)
+            payload = part.get_payload(decode=True)
             ctype = part.get_type()
             size = len(payload)
             omask = os.umask(002)
@@ -269,7 +277,7 @@
 Desc: %(desc)s
 Url : %(url)s
 """), lcset)
-        outer = 0
+        outer = False
     # We still have to sanitize multipart messages to flat text because
     # Pipermail can't handle messages with list payloads.  This is a kludge;
     # def (n) clever hack ;).
@@ -293,7 +301,7 @@
                 text.append(_('Skipped content of type %(partctype)s'))
                 continue
             try:
-                t = part.get_payload(decode=1)
+                t = part.get_payload(decode=True)
             except binascii.Error:
                 t = part.get_payload()
             partcharset = part.get_content_charset()
@@ -309,7 +317,7 @@
                 try:
                     # Should use HTML-Escape, or try generalizing to UTF-8
                     t = t.encode(charset, 'replace')
-                except (UnicodeError, LookupError):
+                except (UnicodeError, LookupError, ValueError):
                     t = t.encode(lcset, 'replace')
             # Separation is useful
             if not t.endswith('\n'):
@@ -339,11 +347,11 @@
 
 
 
-def save_attachment(mlist, msg, dir, filter_html=1):
+def save_attachment(mlist, msg, dir, filter_html=True):
     fsdir = os.path.join(mlist.archive_dir(), dir)
     makedirs(fsdir)
     # Figure out the attachment type and get the decoded data
-    decodedpayload = msg.get_payload(decode=1)
+    decodedpayload = msg.get_payload(decode=True)
     # BAW: mimetypes ought to handle non-standard, but commonly found types,
     # e.g. image/jpg (should be image/jpeg).  For now we just store such
     # things as application/octet-streams since that seems the safest.
@@ -388,7 +396,7 @@
         # after filebase, e.g. msgdir/filebase-cnt.ext
         counter = 0
         extra = ''
-        while 1:
+        while True:
             path = os.path.join(fsdir, filebase + extra + ext)
             # Generally it is not a good idea to test for file existance
             # before just trying to create it, but the alternatives aren't



_______________________________________________
Mailman-checkins mailing list
[EMAIL PROTECTED]
Unsubscribe: http://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to