added Later target
[org.ibex.mail.git] / src / org / ibex / mail / List.jsp
1 <%@ page import = "java.util.*" %>
2 <%@ page import = "javax.servlet.*" %>
3 <%@ page import = "org.ibex.mail.*" %>
4 <%@ page import = "org.prevayler.*" %>
5 <%@ page import = "org.ibex.mail.target.*" %>
6 <%@ page import = "org.ibex.mail.List" %>
7 <html>
8     <title> Mailing Lists </title>
9     <body>
10     <form method=get>
11     <%
12           String action = request.getParameter("action");
13           boolean admin = "true".equals(request.getParameter("admin"));
14
15           // Display //////////////////////////////////////////////////////////////////////////////
16           if (action == null) {
17               %> <table border=1> <tr><td>List Address</td> <td>Description</td></tr> <%
18               List[] all = (List[])List.p.execute(List.all());
19               for(int i=0; i<all.length; i++) {
20                   %>
21                      <tr>
22                           <td> <a href="?action=List&list=<%=all[i].address%>"> <%= all[i].address %> </td>
23                           <td> <%= all[i].one_line_description %> </td>
24                           if (admin) {
25                               <td><input type=submit name=action
26                                          value="Delete <%=all[i].address.user+"@"+all[i].address.host%>"></td>
27                           }
28                      </tr>
29                   <%
30               }
31               if (admin) {
32                   %> <tr>
33                          <td> <input type=text size=20 name=name>        </td>
34                          <td> <input type=text size=40 name=description> </td>
35                          <td> <input type=submit name=action value=Add>  </td>
36                      </tr> </table> <%
37               }
38
39           // Add //////////////////////////////////////////////////////////////////////////////
40           } else if ("Add".equals(action)) {
41               Address a = new Address(request.getParameter("name"));
42               Transaction t =
43                     List.create(a,
44                       FileBasedMailbox.getFileBasedMailbox(List.ROOT + "/" + a.user + "@" + a.host + "/pending", true),
45                       FileBasedMailbox.getFileBasedMailbox(List.ROOT + "/" + a.user + "@" + a.host + "/archive", true));
46               List.p.execute((Transaction)t);
47  
48           // Specific List ///////////////////////////////////////////////////////////////////////
49           } else if (action.startsWith("List")) {
50               List list = (List)List.p.execute(List.forAddress(Address.parse(request.getParameter("list"))));
51               %><table border=1>
52                     <tr><td>List:</td><td><%=list.address%></td></tr>
53                     <tr><td>Description:</td><td><%=list.one_line_description%></td></tr>
54                     </table>
55                 <input type=hidden name=list value=<%=list.address%>>
56                 <input type=text size=30 name=email>
57                 <input type=submit name=action value=Subscribe>
58               <%
59
60           // Subscribe //////////////////////////////////////////////////////////////////////////////
61           } else if (action.startsWith("Subscribe")) {
62               List.p.execute(List.subscribeNewUser(Address.parse(request.getParameter("email")), request.getParameter("list")));
63               %><h3>Please check your email</h3>
64                 A confirmation message has been sent to you.
65                 response.sendRedirect("");
66               <%
67
68           // Delete //////////////////////////////////////////////////////////////////////////////
69           } else if (action.startsWith("Delete")) {
70               Transaction t = List.delete(new Address(action.substring(6).trim()));
71               List.p.execute((Transaction)t);
72               response.sendRedirect("");
73           }
74               %>         
75       </form>
76
77     </body>
78 </html>