Update of /cvsroot/tmda/tmda/contrib/cgi
In directory sc8-pr-cvs1:/tmp/cvs-serv23891
Added Files:
Pending.py
Log Message:
Code for generating a list of pending e-mails on a web page. Pager
functionality and navigation bars are included.
--- NEW FILE ---
#!/usr/bin/env python
#
# Copyright (C) 2002 Gre7g Luterman <[EMAIL PROTECTED]>
#
# This file is part of TMDA.
#
# TMDA is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. A copy of this license should
# be included in the file COPYING.
#
# TMDA is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with TMDA; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"Pending page for tmda-cgi."
import email
import os
import pwd
import re
import Session
import string
import time
import CgiUtil
from TMDA import Defaults
def Show():
"Show all pending e-mail in an HTML form."
print """Expires: Mon, 26 Jul 1997 05:00:00 GMT
Last-Modified: %s GMT
Cache-Control: no-cache, must-revalidate
Pragma: no-cache
Content-type: text/html
""" % time.strftime("%a, %d %b %Y %H:%M:%S")
if Form.has_key("subcmd"):
# Change sorting direction?
if Form["subcmd"].value == "desc": PVars["SortDir"] = "desc"
elif Form["subcmd"].value == "asc": PVars["SortDir"] = "asc"
# 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])
# Locate messages in pending dir
Msgs = CgiUtil.GetPendingList()
# Find the message numbers we'll display
FirstMsg = PVars["Pager"]
if Form.has_key("subcmd"):
if Form["subcmd"].value == "first": FirstMsg = 0
elif Form["subcmd"].value == "prev": FirstMsg -= Defaults.CGI_PAGER_SIZE
elif Form["subcmd"].value == "next": FirstMsg += Defaults.CGI_PAGER_SIZE
elif Form["subcmd"].value == "last": FirstMsg = len(Msgs)
if FirstMsg >= len(Msgs): FirstMsg = len(Msgs) - Defaults.CGI_PAGER_SIZE
if FirstMsg < 0: FirstMsg = 0
LastMsg = FirstMsg + Defaults.CGI_PAGER_SIZE
if LastMsg > len(Msgs): LastMsg = len(Msgs)
if len(Msgs):
DisplayRange = "%d-%d of %d" % (FirstMsg + 1, LastMsg, len(Msgs))
else:
DisplayRange = ""
# Update session
PVars["Pager"] = FirstMsg
PVars.Save()
# Any extra icons?
IconWidth = 70
ExtraIcons = ""
if Defaults.PENDING_WHITELIST_APPEND:
IconWidth += 24
ExtraIcons += "<img src=display/smwhite.gif width=24 height=19 align=baseline
alt='/white'>"
if Defaults.PENDING_BLACKLIST_APPEND:
IconWidth += 24
ExtraIcons += "<img src=display/smblack.gif width=24 height=19 align=baseline
alt='/black'>"
# Sort direction?
if PVars["SortDir"] == "asc":
SortIcon = "<img src=display/up.gif width=11 height=13 alt='Sorted Ascending'>"
ToggleSort = "desc"
else:
SortIcon = "<img src=display/down.gif width=11 height=13 alt='Sorted
Descending'>"
ToggleSort = "asc"
# 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"
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"
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"
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"
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)
print """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Pending E-mails for %s</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="display/styles.css" rel="stylesheet" type="text/css">
</head>
<body class="PendingPage">
<table>""" % Defaults.FULLNAME
if len(Msgs): print """%s
<tr>
<td colspan="4">
<hr class=NavDiv>
</td>
</tr>""" % NavBarHTML
print """ <tr class="Heading">
<td colspan="3">Incoming e-mails still pending delivery:</td>
<td align="right">%s</td>
</tr>""" % DisplayRange
if len(Msgs):
# Display pending messages if there are any
print """ <form method="post" action="%s" name="actions">
<tr>
<td colspan="4">
<table class="MailList">
<tr>
<td width="%d"><img src="display/actions.gif" width="66" height="19"
align="baseline" alt="leave/release/delete">%s</td>
<th width="150"><a href="#">Sender</a></th>
<th width="250"><a href="#">Subject</a></th>
<th width="80"><a href="%s?cmd=list&subcmd=%s&SID=%s">Date</a> %s</th>
<th width="50"><a href="#">Size</a></th>
</tr>
<tr bgcolor="#CCCCCC">
<td colspan="5" class="Spacer"></td>
</tr>
""" % (os.environ["SCRIPT_NAME"], IconWidth, ExtraIcons,
os.environ["SCRIPT_NAME"], ToggleSort, PVars.SID, SortIcon)
Count = 0
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"))
except:
pass
# Message size
MsgSize = CgiUtil.Size(MsgObj)
# Find preferred date
try:
Temp = \
re.compile("\d+ [a-zA-Z]+ \d{4} \d+:\d\d:\d\d").search(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"]
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)
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)
print """ </td>
<td>%s</td>
<td><a href="%s?cmd=view&msgid=%s&SID=%s">%s</a></td>
<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)
# (end of) Print a single message record inside list loop
print """ <tr>
<td colspan="5"><input type="submit" class="gobutton" value="Go">
</td>
</tr>
</table>
<hr class=NavDiv>
</td>
<input type="hidden" name="cmd" value="list">
<input type="hidden" name="subcmd" value="batch">
<input type="hidden" name="SID" value="%s">
</tr>
</form>
%s
""" % (PVars.SID, NavBarHTML)
# (end of) Display pending messages if there are any
# No messages to display
else:
print "<tr><td colspan=4><i>None.</i></td></tr>"
print """</table>
</body>
</html>"""
_______________________________________
tmda-cvs mailing list
http://tmda.net/lists/listinfo/tmda-cvs