mailing list improvements (and nntp)
[org.ibex.mail.git] / src / org / ibex / mail / MailingList.java
index 90f2487..4eca2c1 100644 (file)
@@ -10,8 +10,6 @@ import org.ibex.mail.protocol.*;
 import java.util.*;
 import java.io.*;
 import java.net.*;
-//import org.prevayler.*;
-//import org.prevayler.Query;
 import javax.servlet.*;
 import javax.servlet.http.*;
 
@@ -29,16 +27,27 @@ public class MailingList implements Target, Iterable<MailingList.Subscriber> {
     }
 
     public void banner(HttpServletRequest request, HttpServletResponse response) throws IOException {
-        String basename = request.getServletPath();
+        String basename = request.getRequestURL()+"";
         PrintWriter pw = new PrintWriter(response.getWriter());
+        /*
         pw.println("<html>");
+        pw.println("  <head>");
+        pw.println("   <style>");
+        pw.println("     TH, TD, P, LI, BODY {");
+        pw.println("         font-family: helvetica, verdana, arial, sans-serif;");
+        pw.println("         font-size: 12px;  ");
+        pw.println("         text-decoration:none; ");
+        pw.println("     }");
+        pw.println("   </style>");
+        pw.println("  </head>");
         pw.println("  <body>");
+        */
         String confirm = request.getParameter("confirm");
         if (confirm != null) {
-            Subscribe sub = (Subscribe)Confirmation.decode(confirm, Long.parseLong(properties.get("secret")), new Date());
+            Subscribe sub = (Subscribe)Confirmation.decode(confirm, secret, new Date());
             String email = sub.email;
             synchronized(this) {
-                String path = this.path.getAbsolutePath() + File.separatorChar + "subscribers" + File.separatorChar + sub.email;
+                String path = this.path.getAbsolutePath() + File.separatorChar + "subscribers" + File.separatorChar+sub.email;
                 if (sub.un) new File(path).delete();
                 else {
                     Log.warn(null, "creating " + path);
@@ -47,30 +56,42 @@ public class MailingList implements Target, Iterable<MailingList.Subscriber> {
             }
             pw.println("    <b>successfully "+sub.adj+"d " + email + " to " + properties.get("address"));
         } else {
-            pw.println("    <b>"+properties.get("address")+"</b><br>");
-            pw.println("    <tt><a href="+properties.get("nntp")+">"+properties.get("nntp")+"</a></tt><br>");
             String action = request.getParameter("action");
             String email = request.getParameter("email");
             if (action != null) {
                 Subscribe sub = new Subscribe(email, request.getRequestURL().toString(), action.equals("unsubscribe"));
-                sub.signAndSend(new Address(properties.get("owner")), Long.parseLong(properties.get("secret")), new Date());
-                pw.println("a confirmation email has been sent to " + email + "; click the enclosed link to confirm your request to " + action);
+                sub.signAndSend(new Address(properties.get("owner")),
+                                secret, new Date());
+                pw.println("a confirmation email has been sent to " + email +
+                          "; click the enclosed link to confirm your request to " + action);
             } else {
-                pw.println("    <form action='"+basename+"' method=post name=form1>");
+                pw.println("<table width=100% border=0 cellpadding=0 cellspacing=0><tr><td>");
+                pw.println("    <b>"+properties.get("address")+"</b><br> ");
+                pw.println("    <i>"+properties.get("description")+"</i> ");
+                pw.println("</td><td align=right>");
+                pw.println("<i>access via:</i> ");
+                if (path.getAbsolutePath().startsWith("/afs/"))
+                    pw.println("<a target=_top href='file:" + path.getAbsolutePath() +"'>[AFS]</a> ");
+                pw.println("<a target=_top href="+properties.get("nntp")+">[NNTP]</a></tt>");
+                pw.println("<a target=_top href='mailto:"+properties.get("address")+"'>[SMTP]</a></tt>");
+                pw.println("<a target=_top href='"+request.getRequestURL()+"'>[HTTP]</a></tt>");
+                pw.println("</td></tr><tr><td colspan=2 align=right>");
+                pw.println("    <form action='"+basename+"' method=post name=form1 target=_top>");
                 pw.println("       <input type=text width=100 value='your@email.com' name=email>");
                 pw.println("       <input type=hidden name=frame value=banner>");
                 pw.println("       <select name=action onchange='form1.submit()'>");
                 pw.println("          <option>--choose action--</option>");
                 pw.println("          <option>subscribe</option>");
                 pw.println("          <option>unsubscribe</option>");
+                pw.println("          <option>preferences</option>");
                 pw.println("       </select>");
                 pw.println("    </form>");
+                pw.println("</td></tr></table>");
             }
         }
-        pw.println("  </body>");
-        pw.println("</html>");
+        //pw.println("  </body>");
+        //pw.println("</html>");
         pw.flush();
-        pw.close();
     }
 
     public class Subscribe extends Confirmation {