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

Modified Files:
        Pending.py View.py 
Log Message:
Added pretty error if message format is bad.

Improved exception handling.

Improved legibility on some large text replacements by indexing them off of a 
dictionary instead of a list.


Index: Pending.py
===================================================================
RCS file: /cvsroot/tmda/tmda/contrib/cgi/Pending.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Pending.py  29 Nov 2002 18:46:00 -0000      1.3
+++ Pending.py  30 Nov 2002 18:21:15 -0000      1.4
@@ -59,7 +59,10 @@
           # 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"
+            CgiUtil.TermError("<tt>%s</tt> is not a valid message ID." %
+              Form["m%d" % Count].value, "Program error / corrupted link.",
+              "retrieve pending e-mail", "",
+              "Recheck link or contact TMDA programmers.")
           
           if Form["a%d" % Count].value == "pass": continue
           try:
@@ -76,7 +79,7 @@
             elif Form["a%d" % Count].value == "blacklist":
               MsgObj.blacklist()
               MsgObj.delete()
-          except: pass
+          except IOError: pass
 
   # Locate messages in pending dir
   Queue = Pending.Queue(descending = (PVars["SortDir"] == "desc"))
@@ -87,7 +90,8 @@
   for PMsg in PVars["InProcess"].keys()[:]:
     try:
       Msgs.index(PMsg)
-    except: del PVars["InProcess"][PMsg]
+    except ValueError:
+      del PVars["InProcess"][PMsg]
 
   # Find the message numbers we'll display
   FirstMsg = PVars["Pager"]
@@ -130,17 +134,15 @@
 
   # NavBar HTML (since it is displayed twice)
   NavBarHTML = """  <tr align="center" class="NavBar">
-    <td width="25%%"><a href="%s?cmd=list&subcmd=first&SID=%s"><img alt="First"
+    <td width="25%%"><a href="%(script)s?cmd=list&subcmd=first&SID=%(SID)s"><img 
+alt="First"
       src="display/first.gif" width="24" height="42" border="0"></a></td>
-    <td width="25%%"><a href="%s?cmd=list&subcmd=prev&SID=%s"><img alt="Prev"
+    <td width="25%%"><a href="%(script)s?cmd=list&subcmd=prev&SID=%(SID)s"><img 
+alt="Prev"
       src="display/prev.gif" width="21" height="42" border="0"></a></td>
-    <td width="25%%"><a href="%s?cmd=list&subcmd=next&SID=%s"><img alt="Next"
+    <td width="25%%"><a href="%(script)s?cmd=list&subcmd=next&SID=%(SID)s"><img 
+alt="Next"
       src="display/next.gif" width="21" height="42" border="0"></a></td>
-    <td width="25%%"><a href="%s?cmd=list&subcmd=last&SID=%s"><img alt="Last"
+    <td width="25%%"><a href="%(script)s?cmd=list&subcmd=last&SID=%(SID)s"><img 
+alt="Last"
       src="display/last.gif" width="24" height="42" border="0"></a></td>
-  </tr>""" % (os.environ["SCRIPT_NAME"], PVars.SID, os.environ["SCRIPT_NAME"], 
-    PVars.SID, os.environ["SCRIPT_NAME"], PVars.SID, os.environ["SCRIPT_NAME"], 
-    PVars.SID)
+  </tr>""" % {"script": os.environ["SCRIPT_NAME"], "SID": PVars.SID}
 
   print """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
@@ -226,7 +228,7 @@
       # Print a single message record inside list loop
       try:
         MsgObj = Pending.Message(Msg)
-      except:
+      except IOError:
         pass
   
       # Message size
@@ -238,7 +240,7 @@
 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:
+      except TypeError:
         Date = "None"
   
       # Subject:

Index: View.py
===================================================================
RCS file: /cvsroot/tmda/tmda/contrib/cgi/View.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- View.py     29 Nov 2002 17:17:32 -0000      1.4
+++ View.py     30 Nov 2002 18:21:15 -0000      1.5
@@ -69,11 +69,13 @@
 </td>""" % (Icon, Filename, CgiUtil.Size(Part))
 
 def Show():
-  "Show a login form in HTML."
+  "Show an e-mail in HTML."
 
   # Check to make sure they're not trying to access anything other than email
   if not re.compile("^\d+\.\d+\.msg$").search(PVars["MsgID"]):
-    raise IOError, "Bad e-mail filename"
+    CgiUtil.TermError("<tt>%s</tt> is not a valid message ID." % PVars["MsgID"],
+      "Program error / corrupted link.", "retrieve pending e-mail", "",
+      "Recheck link or contact TMDA programmers.")
 
   # Any subcommands?
   if Form.has_key("subcmd"):
@@ -83,7 +85,7 @@
     Msgs = Queue.listPendingIds()
     try:
       MsgIdx = Msgs.index(PVars["MsgID"])
-    except: # Oops.  Perhaps they released the message?  Get the list!
+    except ValueError: # Oops.  Perhaps they released the message?  Get the list!
       print "Location: %s?cmd=list&SID=%s\n" % \
         (os.environ["SCRIPT_NAME"], PVars.SID)
       return
@@ -122,7 +124,7 @@
           MsgObj.blacklist()
           MsgObj.delete()
         del Msgs[MsgIdx]
-      except: pass
+      except IOError: pass
       
       # So which message are we on now?
       if len(Msgs) == 0: # Oops! None left!
@@ -187,7 +189,7 @@
         try:
           MsgHTML += "<span class=EmailText>%s</span>" % \
             string.replace(CgiUtil.Escape(string.strip(Part.get_payload(decode=1))), 
"\n", "&nbsp;<br>")
-        except:
+        except AttributeError:
           pass
       else:
         MsgHTML += Part.get_payload(decode=1)
@@ -228,26 +230,23 @@
 
   # Precalculate the navigation bar (since we'll use it twice)
   NavBarHTML = """  <tr align="center" class="NavBar">
-    <td width="%s"><a href="%s?cmd=view&subcmd=first&SID=%s"><img alt="First"
+    <td width="%(width)s"><a href="%(script)s?cmd=view&subcmd=first&SID=%(SID)s"><img 
+alt="First"
       src="display/first.gif" width="24" height="42" border="0"></a></td>
-    <td width="%s"><a href="%s?cmd=view&subcmd=prev&SID=%s"><img alt="Prev"
+    <td width="%(width)s"><a href="%(script)s?cmd=view&subcmd=prev&SID=%(SID)s"><img 
+alt="Prev"
       src="display/prev.gif" width="21" height="42" border="0"></a></td>
-    <td width="%s"><a href="%s"><img alt="Delete" src="display/kill.gif" 
-      width="30" height="42" border="0"></a></td>%s
-    <td width="%s"><a href="%s?cmd=list&SID=%s"><img alt="Entire List"
+    <td width="%(width)s"><a href="%(delete)s"><img alt="Delete" 
+src="display/kill.gif" 
+      width="30" height="42" border="0"></a></td>%(icon1)s
+    <td width="%(width)s"><a href="%(script)s?cmd=list&SID=%(SID)s"><img alt="Entire 
+List"
       src="display/all.gif" width="45" height="42" border="0"></a></td>
-    <td width="%s"><a href="%s?cmd=view&subcmd=release&msgid=%s&SID=%s"><img 
alt="Release"
-      src="display/accept.gif" width="38" height="42" border="0"></a></td>%s
-    <td width="%s"><a href="%s?cmd=view&subcmd=next&SID=%s"><img alt="Next"
+    <td width="%(width)s"><a 
+href="%(script)s?cmd=view&subcmd=release&msgid=%(msgid)s&SID=%(SID)s"><img 
+alt="Release"
+      src="display/accept.gif" width="38" height="42" border="0"></a></td>%(icon2)s
+    <td width="%(width)s"><a href="%(script)s?cmd=view&subcmd=next&SID=%(SID)s"><img 
+alt="Next"
       src="display/next.gif" width="21" height="42" border="0"></a></td>
-    <td width="%s"><a href="%s?cmd=view&subcmd=last&SID=%s"><img alt="Last"
+    <td width="%(width)s"><a href="%(script)s?cmd=view&subcmd=last&SID=%(SID)s"><img 
+alt="Last"
       src="display/last.gif" width="24" height="42" border="0"></a></td>
-  </tr>""" % (ColWidth, os.environ["SCRIPT_NAME"], PVars.SID, ColWidth, 
-    os.environ["SCRIPT_NAME"], PVars.SID, ColWidth, DeleteLink, ExtraIcon1, 
-    ColWidth, os.environ["SCRIPT_NAME"], PVars.SID, ColWidth, 
-    os.environ["SCRIPT_NAME"], PVars["MsgID"], PVars.SID, ExtraIcon2, ColWidth, 
-    os.environ["SCRIPT_NAME"], PVars.SID, ColWidth, os.environ["SCRIPT_NAME"], 
-    PVars.SID)
+  </tr>""" % {"width": ColWidth, "script": os.environ["SCRIPT_NAME"], "SID": 
+PVars.SID,
+    "delete": DeleteLink, "icon1": ExtraIcon1, "msgid": PVars["MsgID"],
+    "icon2": ExtraIcon2}
 
 
   # Display HTML page with email included.
@@ -280,15 +279,15 @@
 function ConfirmDelete()
 {
   if (confirm("Permanently delete this pending message?\\nAny confirmation that 
follows will fail."))
-    document.location.href = "%s?cmd=view&subcmd=delete&msgid=%s&SID=%s"
+    document.location.href = 
+"%(script)s?cmd=view&subcmd=delete&msgid=%(msgid)s&SID=%(SID)s"
 }
 function ConfirmBlacklist()
 {
   if (confirm("Blacklist sender and permanently delete this pending message?"))
-    document.location.href = "%s?cmd=view&subcmd=black&msgid=%s&SID=%s"
+    document.location.href = 
+"%(script)s?cmd=view&subcmd=black&msgid=%(msgid)s&SID=%(SID)s"
 }
-</script>""" % (os.environ["SCRIPT_NAME"], PVars["MsgID"], PVars.SID, 
-    os.environ["SCRIPT_NAME"], PVars["MsgID"], PVars.SID)
+</script>""" % {"script": os.environ["SCRIPT_NAME"], "msgid": PVars["MsgID"],
+    "SID": PVars.SID}
 
   print """</body>
 </html>"""

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

Reply via email to