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

Modified Files:
        Archiver.py HyperArch.py pipermail.py 
Log Message:
back porting from 2.1.6


Index: Archiver.py
===================================================================
RCS file: /cvsroot/mailman/mailman/Mailman/Archiver/Archiver.py,v
retrieving revision 2.30
retrieving revision 2.31
diff -u -d -r2.30 -r2.31
--- Archiver.py 27 Aug 2005 01:54:02 -0000      2.30
+++ Archiver.py 28 Aug 2005 05:31:26 -0000      2.31
@@ -25,6 +25,7 @@
 import os
 import errno
 import traceback
+import re
 from cStringIO import StringIO
 
 from Mailman import mm_cfg
@@ -35,22 +36,26 @@
 from Mailman.Logging.Syslog import syslog
 from Mailman.i18n import _
 
+try:
+    True, False
+except NameError:
+    True = 1
+    False = 0
+
 
 
 def makelink(old, new):
     try:
         os.symlink(old, new)
-    except os.error, e:
-        code, msg = e
-        if code <> errno.EEXIST:
+    except OSError, e:
+        if e.errno <> errno.EEXIST:
             raise
 
 def breaklink(link):
     try:
         os.unlink(link)
-    except os.error, e:
-        code, msg = e
-        if code <> errno.ENOENT:
+    except OSError, e:
+        if e.errno <> errno.ENOENT:
             raise
 
 
@@ -107,13 +112,16 @@
                 fp = open(indexfile)
             except IOError, e:
                 if e.errno <> errno.ENOENT: raise
-                else:
+                omask = os.umask(002)
+                try:
                     fp = open(indexfile, 'w')
-                    fp.write(Utils.maketext(
-                        'emptyarchive.html',
-                        {'listname': self.real_name,
-                         'listinfo': self.GetScriptURL('listinfo', absolute=1),
-                         }, mlist=self))
+                finally:
+                    os.umask(omask)
+                fp.write(Utils.maketext(
+                    'emptyarchive.html',
+                    {'listname': self.real_name,
+                     'listinfo': self.GetScriptURL('listinfo', absolute=1),
+                     }, mlist=self))
             if fp:
                 fp.close()
         finally:
@@ -128,15 +136,15 @@
                             self.internal_name() + '.mbox')
 
     def GetBaseArchiveURL(self):
+        url = self.GetScriptURL('private', absolute=1) + '/'
         if self.archive_private:
-            return self.GetScriptURL('private', absolute=1) + '/'
+            return url
         else:
-            inv = {}
-            for k, v in mm_cfg.VIRTUAL_HOSTS.items():
-                inv[v] = k
+            hostname = re.match('[^:]*://([^/]*)/.*', url).group(1)\
+                       or mm_cfg.DEFAULT_URL_HOST
             url = mm_cfg.PUBLIC_ARCHIVE_URL % {
                 'listname': self.internal_name(),
-                'hostname': inv.get(self.host_name, mm_cfg.DEFAULT_URL_HOST),
+                'hostname': hostname
                 }
             if not url.endswith('/'):
                 url += '/'
@@ -220,7 +228,7 @@
         if mm_cfg.ARCHIVE_TO_MBOX == -1:
             # Archiving is completely disabled, don't require the skeleton.
             return
-        pubdir = Site.get_archpath(self.internal_name(), public=1)
+        pubdir = Site.get_archpath(self.internal_name(), public=True)
         privdir = self.archive_dir()
         pubmbox = pubdir + '.mbox'
         privmbox = privdir + '.mbox'
@@ -231,4 +239,6 @@
             # BAW: privdir or privmbox could be nonexistant.  We'd get an
             # OSError, ENOENT which should be caught and reported properly.
             makelink(privdir, pubdir)
-            makelink(privmbox, pubmbox)
+            # Only make this link if the site has enabled public mbox files
+            if mm_cfg.PUBLIC_MBOX:
+                makelink(privmbox, pubmbox)

Index: HyperArch.py
===================================================================
RCS file: /cvsroot/mailman/mailman/Mailman/Archiver/HyperArch.py,v
retrieving revision 2.42
retrieving revision 2.43
diff -u -d -r2.42 -r2.43
--- HyperArch.py        27 Aug 2005 01:54:02 -0000      2.42
+++ HyperArch.py        28 Aug 2005 05:31:26 -0000      2.43
@@ -1,4 +1,4 @@
-# Copyright (C) 1998-2003 by the Free Software Foundation, Inc.
+# Copyright (C) 1998-2005 by the Free Software Foundation, Inc.
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -40,6 +40,8 @@
 import binascii
 
 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
@@ -287,10 +289,9 @@
         self.ctype = ctype.lower()
         self.cenc = cenc.lower()
         self.decoded = {}
-        charset = message.get_param('charset')
-        if isinstance(charset, types.TupleType):
-            # An RFC 2231 charset
-            charset = unicode(charset[2], charset[0])
+        cset = Utils.GetCharSet(mlist.preferred_language)
+        cset_out = Charset(cset).output_charset or cset
+        charset = message.get_content_charset(cset_out)
         if charset:
             charset = charset.lower().strip()
             if charset[0]=='"' and charset[-1]=='"':
@@ -298,7 +299,7 @@
             if charset[0]=="'" and charset[-1]=="'":
                 charset = charset[1:-1]
             try:
-                body = message.get_payload(decode=1)
+                body = message.get_payload(decode=True)
             except binascii.Error:
                 body = None
             if body and charset != Utils.GetCharSet(self._lang):
@@ -402,22 +403,35 @@
                 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.escape(prefix)
+            prefix_pat = '%'.join(prefix_pat.split(r'\%'))
+            prefix_pat = re.sub(r'%\d*d', r'\s*\d+\s*', 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
-        pairs = decode_header(field)
-        # Use __unicode__() until we can guarantee Python 2.2
+        # TK: This function was rewritten for unifying to Unicode.
+        # Convert 'field' into Unicode one line string.
         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])
+            pairs = decode_header(field)
+            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()
@@ -538,7 +552,15 @@
         body = EMPTYSTRING.join(self.body)
         if isinstance(body, types.UnicodeType):
             body = body.encode(Utils.GetCharSet(self._lang), 'replace')
-        return NL.join(headers) % d + '\n\n' + body
+        if mm_cfg.ARCHIVER_OBSCURES_EMAILADDRS:
+            otrans = i18n.get_translation()
+            try:
+                i18n.set_language(self._lang)
+                body = re.sub(r'([-+,.\w]+)@([-+.\w]+)',
+                              '\g<1>' + _(' at ') + '\g<2>', body)
+            finally:
+                i18n.set_translation(otrans)
+        return NL.join(headers) % d + '\n\n' + body + '\n'
 
     def _set_date(self, message):
         self.__super_set_date(message)
@@ -559,6 +581,12 @@
                 break
             self.body.append(line)
 
+    def finished_update_article(self):
+        self.body = []
+        try:
+            del self.html_body
+        except AttributeError:
+            pass
 
 
 class HyperArchive(pipermail.T):
@@ -735,13 +763,14 @@
                 d["archive_listing"] = EMPTYSTRING.join(accum)
         finally:
             i18n.set_translation(otrans)
-
         # The TOC is always in the charset of the list's preferred language
         d['meta'] += html_charset % Utils.GetCharSet(mlist.preferred_language)
-
-        return quick_maketext(
-            'archtoc.html', d,
-            mlist=mlist)
+        # The site can disable public access to the mbox file.
+        if mm_cfg.PUBLIC_MBOX:
+            template = 'archtoc.html'
+        else:
+            template = 'archtocnombox.html'
+        return quick_maketext(template, d, mlist=mlist)
 
     def html_TOC_entry(self, arch):
         # Check to see if the archive is gzip'd or not
@@ -996,7 +1025,11 @@
         subject = self.get_header("subject", article)
         author = self.get_header("author", article)
         if mm_cfg.ARCHIVER_OBSCURES_EMAILADDRS:
-            author = re.sub('@', _(' at '), author)
+            try:
+                author = re.sub('@', _(' at '), author)
+            except UnicodeError:
+                # Non-ASCII author contains '@' ... no valid email anyway
+                pass
         subject = CGIescape(subject, self.lang)
         author = CGIescape(author, self.lang)
 
@@ -1121,6 +1154,10 @@
         # 1. use lines directly, rather than source and dest
         # 2. make it clearer
         # 3. make it faster
+        # TK: Prepare for unicode obscure.
+        atmark = _(' at ')
+        if lines and isinstance(lines[0], types.UnicodeType):
+            atmark = unicode(atmark, Utils.GetCharSet(self.lang), 'replace')
         source = lines[:]
         dest = lines
         last_line_was_quoted = 0
@@ -1161,7 +1198,7 @@
                     text = jr.group(1)
                     length = len(text)
                     if mm_cfg.ARCHIVER_OBSCURES_EMAILADDRS:
-                        text = re.sub('@', _(' at '), text)
+                        text = re.sub('@', atmark, text)
                         URL = self.maillist.GetScriptURL(
                             'listinfo', absolute=1)
                     else:

Index: pipermail.py
===================================================================
RCS file: /cvsroot/mailman/mailman/Mailman/Archiver/pipermail.py,v
retrieving revision 2.24
retrieving revision 2.25
diff -u -d -r2.24 -r2.25
--- pipermail.py        12 May 2003 04:25:49 -0000      2.24
+++ pipermail.py        28 Aug 2005 05:31:26 -0000      2.25
@@ -7,7 +7,7 @@
 import re
 import sys
 import time
-from email.Utils import parseaddr, parsedate_tz, mktime_tz
+from email.Utils import parseaddr, parsedate_tz, mktime_tz, formatdate
 import cPickle as pickle
 from cStringIO import StringIO
 from string import lowercase
@@ -126,9 +126,13 @@
         """Store article without message body to save space"""
         # TBD this is not thread safe!
         temp = article.body
+        temp2 = article.html_body
         article.body = []
+        del article.html_body
         self.articleIndex[article.msgid] = pickle.dumps(article)
         article.body = temp
+        article.html_body = temp2
+
 
 # The Article class encapsulates a single posting.  The attributes
 # are:
@@ -213,7 +217,8 @@
                 self.headers[i] = message[i]
 
         # Read the message body
-        s = StringIO(message.get_payload())
+        s = StringIO(message.get_payload(decode=1)\
+                     or message.as_string().split('\n\n',1)[1])
         self.body = s.readlines()
 
     def _set_date(self, message):
@@ -235,10 +240,16 @@
             date = self._last_article_time + 1
         self._last_article_time = date
         self.date = '%011i' % date
+        self.datestr = message.get('date') \
+                       or message.get('x-list-received-date') \
+                       or formatdate(date)
 
     def __repr__(self):
         return '<Article ID = '+repr(self.msgid)+'>'
 
+    def finished_update_article(self):
+        pass    
+
 # Pipermail formatter class
 
 class T:
@@ -486,6 +497,8 @@
                             self.update_article(arcdir, a1, L[0], L[2])
                         else:
                             del self.database.changed[key]
+            if L[0]:
+                L[0].finished_update_article()
             L = L[1:]                   # Rotate the list
             if msgid is None:
                 L.append(msgid)
@@ -600,8 +613,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