comparison src/nabble/view/web/mailing_list/SubscribeToMailingList.jtp @ 0:7ecd1a4ef557

add content
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 21 Mar 2019 19:15:52 -0600
parents
children 18cf4872fd7f
comparison
equal deleted inserted replaced
-1:000000000000 0:7ecd1a4ef557
1 <%
2 package nabble.view.web.mailing_list;
3
4 import fschmidt.util.mail.Mail;
5 import fschmidt.util.mail.MailAddress;
6 import fschmidt.util.mail.MailException;
7 import fschmidt.util.mail.MailHome;
8 import fschmidt.util.mail.PlainTextContent;
9 import fschmidt.util.mail.TextContent;
10 import fschmidt.util.servlet.AuthorizingServlet;
11 import nabble.model.ListServer;
12 import nabble.model.MailingList;
13 import nabble.model.ModelHome;
14 import nabble.model.Node;
15 import nabble.model.User;
16 import nabble.view.lib.Jtp;
17 import nabble.view.lib.Shared;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 import javax.servlet.ServletException;
22 import javax.servlet.http.HttpServlet;
23 import javax.servlet.http.HttpServletRequest;
24 import javax.servlet.http.HttpServletResponse;
25 import java.io.IOException;
26 import java.io.PrintWriter;
27
28
29 public final class SubscribeToMailingList extends HttpServlet implements AuthorizingServlet {
30
31 private static final Logger logger = LoggerFactory.getLogger(SubscribeToMailingList.class);
32
33 public String getAuthorizationKey(HttpServletRequest request) throws ServletException {
34 return Jtp.getReadAuthorizationKey( Jtp.getSiteNotNull(request).getNode(Jtp.getLong(request,"node")) );
35 }
36
37 public boolean authorize(String key,HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
38 return Jtp.authorizeForRead(key,request,response);
39 }
40
41 protected void service(HttpServletRequest request,HttpServletResponse response)
42 throws ServletException, IOException
43 {
44 User user = Jtp.getUser(request,response);
45
46 if (user == null) {
47 Jtp.login("You must login to subscribe to mailing list.", request, response);
48 return;
49 }
50
51 Node node = Jtp.getSiteNotNull(request).getNode(Jtp.getLong(request, "node"));
52 boolean allowed = Jtp.canBeEditedBy(node,user);
53 if (!allowed) {
54 Jtp.login("Only administrators can proceed in this area.", request, response);
55 return;
56 }
57
58 PrintWriter out = response.getWriter();
59 boolean isSendEmail = "SendEmail".equals(request.getParameter("action"));
60
61 MailingList mailingList = node.getMailingList();
62 String subscriptionAddress = mailingList.getSubscriberAddress().getAddrSpec();
63 char c = 'A';
64 %>
65 <html>
66 <head>
67 <META NAME="robots" CONTENT="noindex,nofollow">
68 <% Shared.title(request,response,"Subscription Instructions"); %>
69 <style type="text/css">
70 div.field-title {
71 margin-top: 0;
72 }
73 td.number {
74 width: 3em;
75 padding-bottom: .2em;
76 }
77 span.number {
78 font-size: 200%;
79 padding: 0 .3em .03em;
80 border-width:1px;
81 border-style:solid;
82 }
83 </style>
84 </head>
85 <body>
86 <% Shared.minHeader(request, response, node);%>
87 <% Shared.editHeader(node.getSubjectHtml(), "Subscription Instructions", out); %>
88 <%
89 if (isSendEmail && "POST".equals(request.getMethod())) {
90 String errorMsg = sendRequest(node, request, out);
91 Shared.errorMessage(request, response, errorMsg, "Failed to send the request." );
92 }
93 %>
94 <div class="field-box light-border-color">
95 <div class="second-font field-title">General Instructions</div>
96 <div style="margin-left:1.5em">
97 Your mailing list archive will <b>ONLY</b> work properly if you have the following email address subscribed to the mailing list:
98 <div class="info-message" style="margin:.2em;padding:.2em;font-weight:bold"><%=subscriptionAddress%></div>
99 This can be done in several ways. Below you can find the most common ones.
100 </div>
101 </div>
102
103 <div class="second-font field-title" style="margin-top:1em">Subscription Options</div>
104 <div class="weak-color">Choose the best option for this mailing list.</div>
105
106 <div class="field-box light-border-color">
107 <table style="margin-left:1.3em">
108 <tr valign="top">
109 <td class="number"><span class="number shaded-bg-color medium-border-color"><%=c++%></span></td>
110 <td>
111 <div class="second-font field-title">Add to subscriber's list</div>
112 Mailing list administrators usually can add email addresses to the subscribers' list directly.
113 If you can do this, add <b><%=subscriptionAddress%></b> to that list.
114 </td>
115 </tr>
116 </table>
117 </div>
118
119 <% if (mailingList.getListServer() == ListServer.google) { %>
120 <div class="field-box light-border-color">
121 <table style="margin-left:1.3em">
122 <tr valign="top">
123 <td class="number"><span class="number shaded-bg-color medium-border-color"><%=c++%></span></td>
124 <td>
125 <div class="second-font field-title">Use the "Invite" feature of GoogleGroups </div>
126 You can go to the <a href="http://groups.google.com/" rel="nofollow">Google Groups website</a> and
127 invite the following address to be a member:
128 <b><%=subscriptionAddress%></b>.<br>
129 The confirmation email will be forwarded to you so that you can complete this step.
130 </td>
131 </tr>
132 </table>
133 </div>
134 <div class="field-box light-border-color">
135 <table style="margin-left:1.3em">
136 <tr valign="top">
137 <td class="number"><span class="number shaded-bg-color medium-border-color"><%=c++%></span></td>
138 <td>
139 <div class="second-font field-title">Create an account in GoogleGroups for the subscription email</div>
140 You can go to the <a href="http://groups.google.com/" rel="nofollow">Google Groups website</a> and
141 create an account for this email:
142 <b><%=subscriptionAddress%></b>.<br>
143 (Google will probably send a confirmation number to your cell phone so that you can finish the registration)<br>
144 When you have finished the account set up, you can go to the mailing list page and click on "Join this group".
145 </td>
146 </tr>
147 </table>
148 </div>
149 <% } else { %>
150 <div class="field-box light-border-color">
151 <table style="margin-left:1.3em">
152 <tr valign="top">
153 <td class="number"><span class="number shaded-bg-color medium-border-color"><%=c++%></span></td>
154 <td>
155 <div class="second-font field-title">Go to mailing list website</div>
156 You can go to the mailing list homepage (<a href="<%=mailingList.getUrl()%>"><%=mailingList.getUrl()%></a>)
157 and subscribe <b><%=subscriptionAddress%></b> to the list.
158 The confirmation email will be forwarded to your email address as soon as it is received by Nabble.com.
159 You will have to follow the instructions in that email to confirm this request.
160 </td>
161 </tr>
162 </table>
163 </div>
164 <% } %>
165 <% emailForm(node, true, "Subscribe by email", "Send Subscription Request", c, request, out); %>
166
167 <% Shared.footer(request,response); %>
168 <% Shared.analytics(request,response); %>
169 </body>
170 </html>
171 <%
172 }
173
174 static String sendRequest(Node node, HttpServletRequest request, PrintWriter out)
175 throws ServletException, IOException
176 {
177 String emailFrom = request.getParameter("emailFrom");
178 String emailToUser = request.getParameter("emailToUser");
179 String emailToDomain = request.getParameter("emailToDomain");
180 String emailSubject = request.getParameter("emailSubject");
181 String emailBody = request.getParameter("emailBody");
182
183 if (emailFrom == null || emailToUser == null || emailToDomain == null) {
184 return "Invalid message parameters";
185 } else {
186 MailAddress toAddress = new MailAddress(emailToUser + emailToDomain);
187 try {
188 Mail mail = MailHome.newMail();
189 mail.setFrom(new MailAddress(emailFrom, "Nabble Forums"));
190 mail.setTo(toAddress);
191 mail.setSubject(emailSubject);
192 mail.setContent(new PlainTextContent(emailBody));
193 ModelHome.send(mail);
194 } catch(MailException e) {
195 logger.warn("",e);
196 return e.getMessage();
197 }
198 %>
199 <div class="info-message" style="padding:1em">
200 <b>Email Sent</b><br/>
201 The request has been successfully sent. The confirmation email will be forwarded to your email
202 address as soon as it is received by Nabble. You will have to follow the instructions in
203 that email to finish the process.<br/>
204 <a href="<%=Jtp.path(node)%>">Return to forum</a>
205 </div>
206 <%
207 }
208 return null;
209 }
210
211 static void emailForm(Node node, boolean isSubscription, String title, String button, char c, HttpServletRequest request, PrintWriter out) {
212 MailingList mailingList = node.getMailingList();
213 if (!mailingList.getListServer().canSubscribe())
214 return;
215 %>
216 <div class="field-box light-border-color">
217 <table style="margin-left:1.3em">
218 <tr valign="top">
219 <td class="number"><span class="number shaded-bg-color medium-border-color"><%=c%></span></td>
220 <td>
221 <div class="second-font field-title"><%=title%></div>
222 You can send the request by email. Default content of the email is
223 provided according to the mailing list server type (<b><%=mailingList.getListServer().getViewName()%></b>)
224 that you have specified during the mailing list setup. You can modify it if necessary.
225 </td>
226 </tr>
227 </table>
228 </div>
229 <%
230 String emailFrom = request.getParameter("emailFrom");
231 String emailToUser = request.getParameter("emailToUser");
232 String emailToDomain = request.getParameter("emailToDomain");
233 String emailSubject = request.getParameter("emailSubject");
234 String emailBody = request.getParameter("emailBody");
235 Mail mail = isSubscription? mailingList.subscribeMail(): mailingList.unsubscribeMail();
236
237 if (emailFrom == null) {
238 emailFrom = mail.getFrom().getAddrSpec();
239 }
240
241 if (emailToUser == null || emailToDomain == null) {
242 String emailTo = mail.getTo()[0].getAddrSpec();
243 int index = emailTo.indexOf("@");
244 if(index < 0) {
245 throw new RuntimeException("Invalid emailTo: " + emailTo);
246 }
247 emailToUser = emailTo.substring(0, index);
248 emailToDomain = emailTo.substring(index);
249 }
250
251 if (emailSubject == null) {
252 emailSubject = Jtp.hideNull(mail.getSubject());
253 }
254
255 if (emailBody == null) {
256 emailBody = ((TextContent) mail.getContent()).getText();
257 }
258 %>
259 <form method="post" action="/mailing_list/<%=isSubscription? "SubscribeToMailingList.jtp":"UnsubscribeFromMailingList.jtp"%>" accept-charset="UTF-8">
260 <input type="hidden" name="node" value="<%=node.getId()%>">
261 <input type="hidden" name="action" value="SendEmail">
262 <input type="hidden" name="emailToDomain" value="<%=emailToDomain%>">
263 <input type="hidden" name="emailToUser" value="<%=emailToUser%>">
264 <input type="hidden" name="emailSubject" value="<%=emailSubject%>">
265 <input type="hidden" name="emailBody" value="<%=emailBody%>">
266 <input type="hidden" name="emailFrom" value="<%=emailFrom%>"/>
267 <table style="margin-left:2em">
268 <tr>
269 <td align=right>From:&nbsp;</td>
270 <td><input type="text" name="emailFrom2" value="<%=emailFrom%>" size="50" disabled/></td>
271 </tr>
272 <tr>
273 <td align=right>To:&nbsp;</td>
274 <td valign="middle"><input type="text" name="emailToUser2" value="<%=emailToUser%>" size="50" disabled/><%=emailToDomain%></td>
275 </tr>
276 <tr>
277 <td align=right>Subject:&nbsp;</td>
278 <td><input type="text" name="emailSubject2" value="<%=emailSubject%>" size="50" disabled/></td>
279 </tr>
280 <tr>
281 <td align=right valign=top>Message:&nbsp;</td>
282 <td><textarea cols="50" rows="5" name="emailBody2" wrap="SOFT" disabled><%=emailBody%></textarea></td>
283 </tr>
284 <tr>
285 <td><br></td>
286 <td>
287 <input type="submit" value="<%=button%>" />
288 </td>
289 </tr>
290 </table>
291 </form>
292 <%
293 }
294
295 }
296 %>