+ public static class Servlet extends HttpServlet {
+ public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { doGet(request, response); }
+ private void frames(HttpServletRequest request, HttpServletResponse response, boolean top) throws IOException {
+ String basename = request.getRequestURI();
+ PrintWriter pw = new PrintWriter(response.getWriter());
+ pw.println("<html>");
+ if (top) {
+ pw.println(" <frameset rows='30%,*'>");
+ //pw.println(" <frame src='"+basename+"?frame=banner' marginwidth=0 marginheight=0 name=banner/>");
+ //pw.println(" <frame src='"+basename+"?frame=top' marginwidth=0 marginheight=0 name=top/>");
+ pw.println(" <frame src='"+basename+"?frame=topright' marginwidth=0 marginheight=0 name=topright/>");
+ pw.println(" <frame src='"+basename+"?frame=bottom' marginwidth=0 marginheight=0 name='bottom'/>");
+ } else {
+ pw.println(" <frameset cols='150,*'>");
+ pw.println(" <frame src='"+basename+"?frame=topleft' marginwidth=0 marginheight=0 name=topleft/>");
+ pw.println(" <frame src='"+basename+"?frame=topright' marginwidth=0 marginheight=0 name=topright/>");
+ }
+ pw.println(" </frameset>");
+ pw.println("</html>");
+ pw.flush();
+ }
+
+ public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
+ String frame = request.getParameter("frame");
+ String basename = request.getRequestURI();
+
+ if (frame == null) { frames(request, response, true); return; }
+ if (frame.equals("top")) { frames(request, response, false); return; }
+ if (frame.equals("banner")) { banner(request, response); return; }
+ if (frame.equals("topleft")) { return; }
+
+ if (request.getServletPath().indexOf("..") != -1) throw new IOException(".. not allowed in image paths");
+ ServletContext cx = getServletContext();
+ String path = cx.getRealPath(request.getServletPath());
+ Mailbox mbox = FileBasedMailbox.getFileBasedMailbox(path, false);
+ if (mbox == null) throw new IOException("no such mailbox: " + path);
+
+ Vec msgs = new Vec();
+ for(Mailbox.Iterator it = mbox.iterator(); it.next();) {
+ String[] s = new String[4];
+ Message m = it.cur();
+ s[0] = (m.from==null?"":m.from.toString(true));
+ s[1] = m.subject;
+ s[2] = (m.date + "").trim().replaceAll(" "," ");
+ s[3] = it.num() + "";
+ msgs.addElement(s);
+ }
+ String[][] messages;
+ msgs.copyInto(messages = new String[msgs.size()][]);
+
+ if ("bottom".equals(frame)) { bottom(request, response, messages, mbox); return; }
+ if ("topright".equals(frame)) { topright(request, response, messages); return; }
+ }
+
+ private void bottom(HttpServletRequest request, HttpServletResponse response, String[][] messages, Mailbox mbox)
+ throws IOException {
+ PrintWriter pw = new PrintWriter(response.getWriter());
+ pw.println("<html>");
+ pw.println(" <head>");
+ pw.println(" <style>");
+ pw.println(" body { margin: 10px; }");
+ pw.println(" pre {");
+ pw.println(" font-family: monospace;");
+ pw.println(" background-color: #F0F0E0;");
+ pw.println(" color: rgb(0, 0, 0);");
+ pw.println(" padding: 5px;");
+ pw.println(" margin: 0px;");
+ pw.println(" overflow: auto;");
+ //pw.println(" width: 80%;");
+ //pw.println(" border-style: solid;");
+ //pw.println(" border-width: 1px;");
+ pw.println(" }");
+ pw.println(" </style>");
+ pw.println(" </head>");
+ pw.println(" <body>");
+ if (request.getParameter("msgnum") != null) {
+ int target = Integer.parseInt(request.getParameter("msgnum"));
+ Mailbox.Iterator it = mbox.iterator();
+ while(it.next())
+ if (it.num() == target)
+ break;
+ if (it.cur() != null) {
+ pw.println(" <table width=100% border=0 cellspacing=0 style='border: 1px black solid; background-color:#F0F0E0;'>");
+ pw.println(" <tr style='border: 1px black solid; font-family: monospace'><td style='padding: 5px'>");
+ Headers h = it.cur().headers;
+ pw.println(" Subject: " + it.cur().subject +"<br>");
+ pw.println(" From: " + it.cur().from +"<br>");
+ pw.println(" Date: " + it.cur().date +"<br>");
+ /*
+ for(java.util.Enumeration e = h.names(); e.hasMoreElements();) {
+ String key = (String)e.nextElement();
+ if (key==null || key.length()==0 || key.equals("from") ||
+ key.equals("to") || key.equals("subject") || key.equals("date")) continue;
+ key = Character.toUpperCase(key.charAt(0)) + key.substring(1);
+ String val = h.get(key);
+ for(int i=key.length(); i<15; i++)pw.print(" ");
+ pw.print(key+": ");
+ pw.println(val);
+ }
+ */
+ pw.print("</td></tr><tr><td style='border-top: 1px black; border-top-style: dotted;'><pre>");
+ StringBuffer tgt = new StringBuffer();
+ it.cur().getBody().getStream().transcribe(tgt);
+ pw.println(tgt.toString());
+ pw.println(" </pre></td></tr></table>");
+ }
+ }
+ pw.println(" </body>");
+ pw.println("</html>");
+ pw.flush();
+ pw.close();
+ }
+
+ private void banner(HttpServletRequest request, HttpServletResponse response) throws IOException {
+ String basename = request.getServletPath();
+ String realpath = getServletContext().getRealPath(basename);
+ /*
+ MailingList list = MailingList.getMailingList(realpath);
+ list.banner(request, response);
+ */
+ banner(request, response);
+ }
+
+ private void topright(HttpServletRequest request, HttpServletResponse response, String[][] messages) throws IOException {
+ PrintWriter pw = new PrintWriter(response.getWriter());
+ String basename = request.getRequestURI();
+ pw.println("<html>");
+ pw.println(" <head>");
+ pw.println(" <style>");
+ pw.println(" TH, TD, P, LI {");
+ pw.println(" font-family: helvetica, verdana, arial, sans-serif;");
+ pw.println(" font-size: 12px; ");
+ pw.println(" text-decoration:none; ");
+ pw.println(" }");
+ pw.println(" body { margin: 10px; }");
+ pw.println(" a:link { color: #000; text-decoration: none; }");
+ pw.println(" a:active { color: #f00; text-decoration: none; }");
+ pw.println(" a:visited { color: #777; text-decoration: none; }");
+ pw.println(" a:hover { color: #000; text-decoration: none; }");
+ pw.println(" /* a:hover { color: #00f; text-decoration: none; border-bottom: 1px dotted; } */");
+ pw.println(" </style>");
+ pw.println(" </head>");
+ pw.println(" <body onKeyPress='doKey(event.keyCode)'>");
+ pw.println(" <script>");
+ pw.println(" var chosen = null;");
+ pw.println(" var all = [];");
+ pw.println(" function doKey(x) {");
+ pw.println(" if (chosen == null) { choose(all[0]); return; }");
+ pw.println(" switch(x) {");
+ pw.println(" case 112: if (chosen.id > 0) choose(all[chosen.id-1]); break;");
+ pw.println(" case 110: if (chosen.id < (all.length-1)) choose(all[1+(1*chosen.id)]); break;");
+ pw.println(" }");
+ pw.println(" }");
+ pw.println(" function choose(who) {");
+ pw.println(" who.style.background = '#ffc';");
+ pw.println(" if (chosen != null) chosen.style.background = '#ccc';");
+ pw.println(" parent.parent.bottom.location='"+basename+"?frame=bottom&msgnum='+who.id;");
+ pw.println(" chosen = who;");
+ pw.println(" }");
+ pw.println(" </script>");
+ pw.println(" <div style='border: 1px black solid;'><table width=100% border=0 cellpadding=0 cellspacing=0>");
+ pw.println(" <tr><td style='padding: 4px' bgcolor=#eff7ff>");
+ pw.flush();
+ banner(request, response);
+ pw.println(" </td></tr>");
+ pw.println(" <tr><td>");
+ pw.println(" <table width=100% cellpadding=0 cellspacing=0 style='border-top: 1px black solid; cursor:pointer;'>");
+ boolean odd=true;
+ for(int i=0; i<messages.length; i++) {
+ odd = !odd;
+ String[] m = messages[i];
+ pw.println(" <tr style='cursor:pointer; background: "+(odd?"#e8eef7":"white")+"' id='"+m[3]+"' "+
+ "onmouseover='this.style.color=\"blue\"' "+
+ "onmouseout='this.style.color=\"black\"' "+
+ "onclick='choose(this);'>");
+ pw.println("<td style='cursor:pointer; padding:5px; padding-bottom:2px'>"+m[0]+"</td>");
+ pw.println("<td style='cursor:pointer; padding:5px; padding-bottom:2px'>"+m[1]+"</td>");
+ pw.println("<td style='cursor:pointer; padding:5px; padding-bottom:2px'>"+m[2]+"</td>");
+ pw.println("</tr>");
+ pw.println("<script> all["+i+"] = document.getElementById('"+i+"'); </script>");
+ }
+ pw.println(" </table>");
+ pw.println(" </td></tr>");
+ pw.println(" </table></div>");
+ pw.println(" </body>");
+ pw.println("</html>");
+ pw.flush();
+ pw.close();
+ }
+ }