On 07/18/2014 12:10 AM, Peter Knowles wrote:
> 
> The only error that remains when applying the "mhonarc" patch is:
> 
> Hulk #2 FAILED at 106.
> 1 out of 2 hulks FAILED -- saving rejects to file Mailman/Mailbox.py.rej


The problem with the patch is that the file it is based on ended at the
point where the last hunk was applied, and a new method was subsequently
added to Mailbox.py which wasn't taken into account in the patch.

The attached Mailbox.py.patch should work with possible line number
shifts. It is intended to be applied to your previously patched
Mailbox.py with the first hunk of the patch already applied.

-- 
Mark Sapiro <m...@msapiro.net>        The highway is for gamblers,
San Francisco Bay Area, California    better use your sense - B. Dylan
--- Mailbox.py	2013-12-13 16:25:41.417368781 -0800
+++ Mailbox.py.new	2014-07-18 10:11:48.645854753 -0700
@@ -107,7 +107,7 @@
         else:
             self._scrubber = None
         self._mlist = mlist
-        mailbox.PortableUnixMailbox.__init__(self, fp, _archfactory(self))
+        mailbox.UnixMailbox.__init__(self, fp, _archfactory(self))
 
     def scrub(self, msg):
         if self._scrubber:
@@ -115,6 +115,131 @@
         else:
             return msg
 
+import tempfile
+from Mailman.i18n import _
+from Mailman import Errors
+from Mailman.Logging.Syslog import syslog
+
+class mhonarcArchiverMailbox(ArchiverMailbox):
+    # This class is a hack to support integrated use of MHonArc for generating
+    # the archive content. 
+    # Primary purpose is to return either a single message object or a path
+    # to a file containing a sequence of messages if thos messages should
+    # all go into the same archive.
+    # Value returned is a triple  of:
+    #    type of info returned; 1: single message, 2: multiple messages
+    #    a list of archives the message(s) should go in
+    #    a single message object or the path to a temporary mbox file containing
+    #    multiple messages
+
+    def __init__(self, archiver, fp, mlist, start, end):
+        ArchiverMailbox.__init__(self, fp, mlist)
+        self._archiver = archiver
+        self._input = fp
+        self._mlist = mlist
+        if start is None:
+            start = 0
+        self._start = start
+        self._end = end
+        self._heldover = []
+        self._counter = 0
+        self._finished = 0
+        # Skip over initial, unwanted messages
+        while self._counter < start:
+            try:
+                msg = ArchiverMailbox.next(self)
+            except Errors.DiscardMessage:
+                continue
+            if msg is None:
+                self._finished = 1
+                break
+            self._counter += 1
+    
+    # Leave scrubbing to MHonArc
+    def scrub(self, msg):
+        return msg
+    
+    def next(self):
+        mbox_path = mbox_fp = None
+        result = None
+        try:
+            while 1:
+                if self._end is not None and self._counter >= self._end:
+                    # Processed as many messages as required
+                    self._finished = 1
+                if self._finished:
+                    # No more messages to be processed
+                    if self._heldover:
+                        # Want to return final tranche of messages
+                        result = self._heldover
+                        self._heldover = []
+                    else:
+                        # No more messages to return
+                        result = None
+                    break
+                try:
+                    pos = self._input.tell()
+                    msg = ArchiverMailbox.next(self)
+                except Errors.DiscardMessage:
+                    continue
+                except Exception:
+                    syslog('error', 'uncaught archiver exception at filepos: %s',
+                           pos)
+                    if mbox_fp:
+                        mbox_fp.close()
+                        os.unlink(mbox_path)
+                    self._heldover = []
+                    self._finished = 1
+                    raise
+                self._counter += 1
+                if msg is None:
+                    # No messages left
+                    self._finished = 1
+                    continue
+                if msg == '':
+                    # It was an unparseable message
+                    continue
+                # We have a message 
+                msgid = msg.get('message-id', 'n/a')
+                counter = self._counter
+                self._archiver.message(_('#%(counter)05d %(msgid)s'))
+                article = self._archiver._makeMhonarcArticle(msg)
+                # Determine which archive(s) the message should be archived to
+                this_archive = self._archiver.get_archives(article)
+                if type(this_archive) == type(''):
+                    this_archive = [this_archive]
+                # Now depends on if we are holding message(s) already
+                if not self._heldover:
+                    # Not holding message(s) so hold this one
+                    self._heldover = [1, this_archive, msg]
+                    continue
+                else:
+                    # We are holding a message
+                    if this_archive != self._heldover[1]:
+                        # New messge is not for the same archive(s)
+                        result = self._heldover
+                        # Hold over the new message
+                        self._heldover = [1, this_archive, msg]
+                        # Exit to the return what was held over
+                        break
+                    else:
+                        # New message for same archive(s) as held over
+                        if self._heldover[0] == 1:
+                            # Just holding a single message so insert it into a
+                            # temporary mbox file
+                            mbox_path = tempfile.mktemp('.mbox')
+                            mbox_fp = open(mbox_path, 'w')
+                            mbox_fp.write(self._heldover[2].as_string(True) + '\n')
+                            self._heldover[2] = mbox_path
+                            self._heldover[0] = 2
+                        # Add new message to the held over temporary mbox file
+                        mbox_fp.write(msg.as_string(True) + '\n')
+        finally:
+            # Always close the temporary mbox file on the way out
+            if mbox_fp:
+                mbox_fp.close()
+        return result
+
     def skipping(self, flag):
         """ This method allows the archiver to skip over messages without
         scrubbing attachments into the attachments directory."""
------------------------------------------------------
Mailman-Users mailing list Mailman-Users@python.org
https://mail.python.org/mailman/listinfo/mailman-users
Mailman FAQ: http://wiki.list.org/x/AgA3
Security Policy: http://wiki.list.org/x/QIA9
Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/
Unsubscribe: 
https://mail.python.org/mailman/options/mailman-users/archive%40jab.org

Reply via email to