Update of /cvsroot/mailman/mailman/Mailman/Archiver
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4813/Mailman/Archiver

Modified Files:
      Tag: Release_2_1-maint
        HyperArch.py pipermail.py 
Log Message:
Fix in pipermail to use Unicode for indexing (sort fails for ascii 8bit)
with some code clean up. Also, include SV (danish/swedish) Re: like pattern.


Index: HyperArch.py
===================================================================
RCS file: /cvsroot/mailman/mailman/Mailman/Archiver/HyperArch.py,v
retrieving revision 2.37.2.9
retrieving revision 2.37.2.10
diff -u -d -r2.37.2.9 -r2.37.2.10
--- HyperArch.py        16 Nov 2004 00:16:44 -0000      2.37.2.9
+++ HyperArch.py        25 Jan 2005 07:52:01 -0000      2.37.2.10
@@ -41,6 +41,7 @@
 
 from email.Header import decode_header, make_header
 from email.Errors import HeaderParseError
+from email.Charset import Charset
 
 from Mailman import mm_cfg
 from Mailman import Utils
@@ -288,7 +289,9 @@
         self.ctype = ctype.lower()
         self.cenc = cenc.lower()
         self.decoded = {}
-        charset = message.get_param('charset', 'us-ascii')
+        cset = Utils.GetCharSet(mlist.preferred_language)
+        cset_out = Charset(cset).output_charset or cset
+        charset = message.get_param('charset', cset_out)
         if isinstance(charset, types.TupleType):
             # An RFC 2231 charset
             charset = unicode(charset[2], charset[0])
@@ -403,25 +406,34 @@
                 self.decoded['email'] = email
         if subject:
             self.decoded['subject'] = subject
+        self.decoded['stripped'] = self.strip_subject(subject or self.subject)
+
+    def strip_subject(self, subject):
+        # Strip subject_prefix and Re: for subject sorting
+        # This part was taken from CookHeaders.py (TK)
+        prefix = self._mlist.subject_prefix.strip()
+        if prefix:
+            prefix_pat = re.sub(r'%\d*d', r'\s*\d+\s*', prefix)
+            prefix_pat = re.sub('([\[\(\{\)])', '\\\\\g<1>', prefix_pat)
+            subject = re.sub(prefix_pat, '', subject)
+        subject = subject.lstrip()
+        strip_pat = re.compile('^((RE|AW|SV)(\[\d+\])?:\s*)+', re.I)
+        stripped = strip_pat.sub('', subject)
+        return stripped
 
     def decode_charset(self, field):
-        if field.find("=?") == -1:
-            return None
-        # Get the decoded header as a list of (s, charset) tuples
+        # TK: This function was rewritten for unifying to Unicode.
+        # Convert 'field' into Unicode one line string.
         try:
             pairs = decode_header(field)
-        except HeaderParseError:
-            return None
-        # Use __unicode__() until we can guarantee Python 2.2
-        try:
-            # Use a large number for maxlinelen so it won't get wrapped
-            h = make_header(pairs, 99999)
-            return h.__unicode__()
-        except (UnicodeError, LookupError):
-            # Unknown encoding
-            return None
-        # The last value for c will have the proper charset in it
-        return EMPTYSTRING.join([s for s, c in pairs])
+            ustr = make_header(pairs).__unicode__()
+        except (LookupError, UnicodeError, ValueError, HeaderParseError):
+            # assume list's language
+            cset = Utils.GetCharSet(self._mlist.preferred_language)
+            if cset == 'us-ascii':
+                cset = 'iso-8859-1' # assume this for English list
+            ustr = unicode(field, cset, 'replace')
+        return u''.join(ustr.splitlines())
 
     def as_html(self):
         d = self.__dict__.copy()

Index: pipermail.py
===================================================================
RCS file: /cvsroot/mailman/mailman/Mailman/Archiver/pipermail.py,v
retrieving revision 2.22.2.4
retrieving revision 2.22.2.5
diff -u -d -r2.22.2.4 -r2.22.2.5
--- pipermail.py        14 Oct 2004 08:05:05 -0000      2.22.2.4
+++ pipermail.py        25 Jan 2005 07:52:01 -0000      2.22.2.5
@@ -610,8 +610,14 @@
             self.write_article(arch, temp, os.path.join(archivedir,
                                                         filename))
 
-            author = fixAuthor(article.author)
-            subject = article.subject.lower()
+            if article.decoded.has_key('author'):
+                author = fixAuthor(article.decoded['author'])
+            else:
+                author = fixAuthor(article.author)
+            if article.decoded.has_key('stripped'):
+                subject = article.decoded['stripped'].lower()
+            else:
+                subject = article.subject.lower()
 
             article.parentID = parentID = self.get_parent_info(arch, article)
             if parentID:

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

Reply via email to