Update of /cvsroot/tmda/tmda/contrib/cgi
In directory sc8-pr-cvs1:/tmp/cvs-serv21015

Modified Files:
        Pending.py 
Log Message:
Switched from using tmda-pending to using the TMDA/Pending.py module.

Messages which have been released but still show up as pending are now marked 
and commented so the user will understand why they are still around.

If there are not enough messages to list on multiple pages, the list will now 
always begin the first message.

Now tests for valid message numbers coming from browser.


Index: Pending.py
===================================================================
RCS file: /cvsroot/tmda/tmda/contrib/cgi/Pending.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Pending.py  25 Nov 2002 17:09:32 -0000      1.1
+++ Pending.py  26 Nov 2002 19:42:20 -0000      1.2
@@ -21,6 +21,7 @@
 
 "Pending page for tmda-cgi."
 
+import cgi
 import email
 import os
 import pwd
@@ -30,6 +31,10 @@
 import time
 import CgiUtil
 from TMDA import Defaults
+from TMDA import Pending
+
+# Pre-calc the regular expressions
+GoodFN = re.compile("^\d+\.\d+\.msg$")
 
 def Show():
   "Show all pending e-mail in an HTML form."
@@ -49,17 +54,40 @@
     
     # Batch operation
     elif Form["subcmd"].value == "batch":
-      Actions = {"X": [], "d": [], "r": [], "B": [], "W": []}
       for Count in range(Defaults.CGI_PAGER_SIZE):
         if Form.has_key("a%d" % Count):
-          Actions[Form["a%d" % Count].value].append(Form["m%d" % Count].value)
-      for Key in Actions.keys():
-        if (Key != "X") and len(Actions[Key]):
-          Actions[Key][:0] = [Defaults.CGI_PATH_TO_PENDING, "-q%sb" % Key]
-          os.spawnv(os.P_WAIT, Defaults.CGI_PATH_TO_PENDING, Actions[Key])
+          # Check to make sure they're not trying to access anything other than 
+          # email
+          if not GoodFN.search(Form["m%d" % Count].value):
+            raise IOError, "Bad e-mail filename"
+          
+          if Form["a%d" % Count].value == "pass": continue
+          try:
+            MsgObj = Pending.Message(Form["m%d" % Count].value)
+            if Form["a%d" % Count].value == "release":
+              MsgObj.release()
+              PVars["InProcess"][Form["m%d" % Count].value] = 1
+            elif Form["a%d" % Count].value == "delete":
+              MsgObj.delete()
+            elif Form["a%d" % Count].value == "whitelist":
+              MsgObj.whitelist()
+              MsgObj.release()
+              PVars["InProcess"][Form["m%d" % Count].value] = 1
+            elif Form["a%d" % Count].value == "blacklist":
+              MsgObj.blacklist()
+              MsgObj.delete()
+          except: pass
 
   # Locate messages in pending dir
-  Msgs = CgiUtil.GetPendingList()
+  Queue = Pending.Queue(descending = (PVars["SortDir"] == "desc"))
+  Queue.initQueue()
+  Msgs = Queue.listPendingIds()
+  
+  # Any messages no longer "in process"?
+  for PMsg in PVars["InProcess"].keys()[:]:
+    try:
+      Msgs.index(PMsg)
+    except: del PVars["InProcess"][PMsg]
 
   # Find the message numbers we'll display
   FirstMsg = PVars["Pager"]
@@ -70,6 +98,7 @@
     elif Form["subcmd"].value == "last": FirstMsg = len(Msgs)
   if FirstMsg >= len(Msgs): FirstMsg = len(Msgs) - Defaults.CGI_PAGER_SIZE
   if FirstMsg < 0: FirstMsg = 0
+  if len(Msgs) <= Defaults.CGI_PAGER_SIZE: FirstMsg = 0
   LastMsg = FirstMsg + Defaults.CGI_PAGER_SIZE
   if LastMsg > len(Msgs): LastMsg = len(Msgs)
   if len(Msgs):
@@ -157,59 +186,79 @@
       os.environ["SCRIPT_NAME"], ToggleSort, PVars.SID, SortIcon)
 
     Count = 0
+    InProcMsg = ""
     for Msg in Msgs[FirstMsg:LastMsg]:
       # Print a single message record inside list loop
       Count = Count + 1
       try:
-        MsgObj = email.message_from_file(open(Msg, "r"))
+        MsgObj = Pending.Message(Msg)
       except:
         pass
   
       # Message size
-      MsgSize = CgiUtil.Size(MsgObj)
+      MsgSize = CgiUtil.Size(MsgObj.msgobj)
   
       # Find preferred date
       try:
         Temp = \
-re.compile("\d+ [a-zA-Z]+ \d{4} \d+:\d\d:\d\d").search(MsgObj.get("date"))
+re.compile("\d+ [a-zA-Z]+ \d{4} \d+:\d\d:\d\d").search(MsgObj.msgobj.get("date"))
         Date = time.strptime(Temp.group(), "%d %b %Y %H:%M:%S")
         Date = time.strftime(Defaults.CGI_DATE_FORMAT, Date)
       except:
         Date = "None"
   
       # Subject:
-      if MsgObj["subject"] == "": Subject = "None"
-      else: Subject = MsgObj["subject"]
+      if MsgObj.msgobj["subject"] == "": Subject = "None"
+      else: Subject = MsgObj.msgobj["subject"]
       
-      print """          <tr> 
+      if PVars["InProcess"].has_key(Msg):
+        # Message is "in process"
+        print """          <tr class="InProcess"> 
+            <td></td>
+            <td>%s</td>
+            <td>%s</td>""" % (MsgObj.msgobj["from"], Subject)
+        InProcMsg = """<table>
+  <tr>
+    <td class="Note">Note:</td>
+    <td>
+      <span class="InProcess">Marked</span> messages are being processed by the 
+      mail server.<br>
+      They will be removed from the pending list when released.
+    </td>
+  </tr>
+</table>"""
+      else:
+        # Message is not "in process"
+        print """          <tr> 
             <td>
-              <input name="a%d" type="radio" value="X" checked>
-              <input name="a%d" type="radio" value="r">
-              <input name="a%d" type="radio" value="d">""" % (Count, Count, Count)
+              <input name="a%d" type="radio" value="pass" checked>
+              <input name="a%d" type="radio" value="release">
+              <input name="a%d" type="radio" value="delete">""" % (Count, Count, 
+Count)
     
-      if Defaults.PENDING_WHITELIST_APPEND:
-        print "<input name=a%d type=radio value=W>" % Count
-      if Defaults.PENDING_BLACKLIST_APPEND:
-        print "<input name=a%d type=radio value=B>" % Count
-      
-      print "<input type=hidden name=m%d value='%s'>" % (Count, Msg)
+        if Defaults.PENDING_WHITELIST_APPEND:
+          print "              <input name=a%d type=radio value=whitelist>" % Count
+        if Defaults.PENDING_BLACKLIST_APPEND:
+          print "              <input name=a%d type=radio value=blacklist>" % Count
       
-      print """            </td>
-            <td>%s</td>
-            <td><a href="%s?cmd=view&msgid=%s&SID=%s">%s</a></td>
+        print """              <input type=hidden name=m%d value='%s'>
+            </td>
             <td>%s</td>
+            <td><a href="%s?cmd=view&msgid=%s&SID=%s">%s</a></td>""" % \
+          (Count, Msg, MsgObj.msgobj["from"], os.environ["SCRIPT_NAME"], Msg, 
+          PVars.SID, Subject)
+      
+      # Finish message record regardless of whether it is "in process"
+      print """            <td>%s</td>
             <td>%s</td>
           </tr>
           <tr bgcolor="#CCCCCC"> 
             <td colspan="5" class="Spacer"></td>
-          </tr>
-""" % (MsgObj["from"], os.environ["SCRIPT_NAME"], Msg, PVars.SID, 
-        Subject, Date, MsgSize)
+          </tr>""" % (Date, MsgSize)
       # (end of) Print a single message record inside list loop
 
     print """          <tr> 
-            <td colspan="5"><input type="submit" class="gobutton" value="Go"> 
-            </td>
+            <td valign="top"><input type="submit" class="gobutton" value="Go"></td>
+            <td colspan="4">%s</td>
           </tr>
         </table>
         <hr class=NavDiv>
@@ -219,8 +268,7 @@
       <input type="hidden" name="SID" value="%s">
     </tr>
   </form>
-%s
-""" % (PVars.SID, NavBarHTML)
+%s""" % (InProcMsg, PVars.SID, NavBarHTML)
     # (end of) Display pending messages if there are any
   
   # No messages to display

_______________________________________
tmda-cvs mailing list
http://tmda.net/lists/listinfo/tmda-cvs

Reply via email to