- public static MailingList getMailingList(String path) { return getMailingList(new File(path)); }
- public static MailingList getMailingList(File path) {
- if (!path.exists()) path.mkdirs();
- File f = new File(path.getAbsolutePath() + File.separatorChar + ".mailinglist");
- try {
- if (!f.exists()) {
- MailingList ret = new MailingList(path);
- Subscriber s = new Subscriber();
- s.address = Address.parse("adam@megacz.com");
- ret.subscribers.put(s.address, s);
- /*
- Subscriber s = new Subscriber();
- s.address = Address.parse("david@zentus.com");
- ret.subscribers.put(s.address, s);
- Subscriber s = new Subscriber();
- s.address = Address.parse("brian@alliet.com");
- ret.subscribers.put(s.address, s);
- */
- ret.write(f);
- return ret;
+// FEATURE: store interesting/important stuff in sqlite
+public class MailingList extends Mailbox.MailboxWrapper {
+
+ // FIXME
+ public MailingList(File path, FileBasedMailbox fbm) throws IOException {
+ super(fbm);
+ this.path = path;
+ this.mailbox = fbm;
+ properties = new PropertiesFile(new File(path.getCanonicalPath() + File.separatorChar + "properties"));
+ address = new Address(properties.get("address"));
+ homepage = properties.get("homepage");
+ one_line_description = properties.get("description");
+ message_footer = properties.get("footer");
+ }
+
+ public void banner(HttpServletRequest request, HttpServletResponse response) throws IOException {
+ 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, secret, new Date());
+ String email = sub.email;
+ synchronized(this) {
+ 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);
+ new FileOutputStream(path).close();
+ }
+ }
+ pw.println(" <b>successfully "+sub.adj+"d " + email + " to " + properties.get("address"));
+ } else {
+ 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")),
+ secret, new Date());
+ pw.println("a confirmation email has been sent to " + email +
+ "; click the enclosed link to confirm your request to " + action);