[Mailman-Users] Re: editing pending messages

tneff at bigfoot.com tneff at bigfoot.com
Tue Apr 9 21:02:32 CEST 2002


You can edit pending messages in Mailman 2.0.8 with the following patch.  I
have not tested it on 2.0.9 yet.  This method will probably never make the
official FAQ, but it will always be online in gzipped form at

	http://www.panix.com/~tneff/mailman20_edit_patch.gz

First, increase ADMINDB_PAGE_TEXT_LIMIT in Mailman/Defaults.py from the
default of 4096 to something bigger like 32768 or -1 for unlimited (a huge
submission may render slowly in the browser!).  Then apply this two-part
patch.

*** Mailman/Cgi/admindb.py.orig	Wed Oct 10 13:31:46 2001
--- Mailman/Cgi/admindb.py	Wed Oct 10 18:30:25 2001
***************
*** 270,275 ****
--- 270,277 ----
              continue
          # get the action comment and reasons if present
          commentkey = 'comment-%d' % request_id
+         headerskey = 'headers-%d' % request_id
+         contentskey = 'fulltext-%d' % request_id
          preservekey = 'preserve-%d' % request_id
          forwardkey = 'forward-%d' % request_id
          forwardaddrkey = 'forward-addr-%d' % request_id
***************
*** 278,285 ****
--- 280,293 ----
          preserve = 0
          forward = 0
          forwardaddr = ''
+         headers = ''
+         contents = ''
          if cgidata.has_key(commentkey):
              comment = cgidata[commentkey].value
+         if cgidata.has_key(headerskey):
+             headers = cgidata[headerskey].value
+         if cgidata.has_key(contentskey):
+             contents = cgidata[contentskey].value
          if cgidata.has_key(preservekey):
              preserve = cgidata[preservekey].value
          if cgidata.has_key(forwardkey):
***************
*** 290,296 ****
          # handle the request id
          try:
              mlist.HandleRequest(request_id, v, comment,
!                                 preserve, forward, forwardaddr)
          except (KeyError, Errors.LostHeldMessage):
              # that's okay, it just means someone else has already updated 
the
              # database, so just ignore this id
--- 298,304 ----
          # handle the request id
          try:
              mlist.HandleRequest(request_id, v, comment,
!                                 preserve, forward, forwardaddr, headers, 
contents)
          except (KeyError, Errors.LostHeldMessage):
              # that's okay, it just means someone else has already updated 
the
              # database, so just ignore this id

*** Mailman/ListAdmin.py.orig	Wed Oct 10 13:31:46 2001
--- Mailman/ListAdmin.py	Wed Oct 10 18:40:27 2001
***************
*** 122,133 ****
          return type

      def HandleRequest(self, id, value, comment=None, preserve=None,
!                       forward=None, addr=None):
          self.__opendb()
          rtype, data = self.__db[id]
          if rtype == HELDMSG:
              status = self.__handlepost(data, value, comment, preserve,
!                                        forward, addr)
          else:
              assert rtype == SUBSCRIPTION
              status = self.__handlesubscription(data, value, comment)
--- 122,133 ----
          return type

      def HandleRequest(self, id, value, comment=None, preserve=None,
!                       forward=None, addr=None, headers=None, 
contents=None):
          self.__opendb()
          rtype, data = self.__db[id]
          if rtype == HELDMSG:
              status = self.__handlepost(data, value, comment, preserve,
!                                        forward, addr, headers, contents)
          else:
              assert rtype == SUBSCRIPTION
              status = self.__handlesubscription(data, value, comment)
***************
*** 172,178 ****
          data = time.time(), sender, msgsubject, reason, filename, msgdata
          self.__db[id] = (HELDMSG, data)

!     def __handlepost(self, record, value, comment, preserve, forward, 
addr):
          # For backwards compatibility with pre 2.0beta3
          if len(record) == 5:
              ptime, sender, subject, reason, filename = record
--- 172,178 ----
          data = time.time(), sender, msgsubject, reason, filename, msgdata
          self.__db[id] = (HELDMSG, data)

!     def __handlepost(self, record, value, comment, preserve, forward, 
addr, headers, contents):
          # For backwards compatibility with pre 2.0beta3
          if len(record) == 5:
              ptime, sender, subject, reason, filename = record
***************
*** 181,186 ****
--- 181,202 ----
              # New format of record
              ptime, sender, subject, reason, filename, msgdata = record
          path = os.path.join(mm_cfg.DATA_DIR, filename)
+         # Handle editing
+         if len(headers)+len(contents):
+            fp = open(path)
+            unixfrom = fp.readline()
+            rest = fp.read()
+            # Parse headers and body
+            parts = string.split(rest,'\n\n')
+            if len(headers) == 0:
+                headers = parts[0]
+            if len(contents) == 0:
+                contents = parts[1]
+            fp.close
+            # Now write the changed result
+            fp = open(path,'w')
+            fp.write(unixfrom + headers + '\n\n' + contents)
+            fp.close
          # Handle message preservation
          if preserve:
              parts = string.split(os.path.split(path)[1], '-')






More information about the Mailman-Users mailing list