Began making changes to do better handling of character sets.
[citadel.git] / webcit / listsub.c
1 /*
2  * $Id$
3  */
4 /**
5  * \defgroup ListSubForms Web forms for handling mailing list subscribe/unsubscribe requests.
6  * \ingroup WebcitDisplayItems
7  */
8
9 /*@{*/
10 #include "webcit.h"
11
12
13
14 /**
15  * \brief List subscription handling
16  */
17 void do_listsub(void)
18 {
19         char cmd[256];
20         char room[256];
21         char token[256];
22         char email[256];
23         char subtype[256];
24         char escaped_email[256];
25         char escaped_room[256];
26
27         char buf[SIZ];
28         int self;
29         char sroom[SIZ];
30
31         strcpy(WC->wc_fullname, "");
32         strcpy(WC->wc_username, "");
33         strcpy(WC->wc_password, "");
34         strcpy(WC->wc_roomname, "");
35
36         output_headers(1, 0, 0, 1, 1, 0);
37         begin_burst();
38
39         wprintf("<HTML><HEAD>\n"
40                 "<meta name=\"MSSmartTagsPreventParsing\" content=\"TRUE\" />\n"
41                 "<link href=\"static/webcit.css\" rel=\"stylesheet\" type=\"text/css\">\n"
42                 "<TITLE>\n"
43         );
44         wprintf(_("List subscription"));
45         wprintf("</TITLE></HEAD><BODY>\n");
46
47         strcpy(cmd, bstr("cmd"));
48         strcpy(room, bstr("room"));
49         strcpy(token, bstr("token"));
50         strcpy(email, bstr("email"));
51         strcpy(subtype, bstr("subtype"));
52
53         wprintf("<CENTER>"
54                 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
55                 "<SPAN CLASS=\"titlebar\">");
56         wprintf(_("List subscribe/unsubscribe"));
57         wprintf("</SPAN></TD></TR></TABLE><br />\n");
58
59         /**
60          * Subscribe command
61          */
62         if (!strcasecmp(cmd, "subscribe")) {
63                 serv_printf("SUBS subscribe|%s|%s|%s|%s://%s/listsub",
64                         room,
65                         email,
66                         subtype,
67                         (is_https ? "https" : "http"),
68                         WC->http_host
69                 );
70                 serv_getln(buf, sizeof buf);
71                 if (buf[0] == '2') {
72                         stresc(escaped_email, email, 0, 0);
73                         stresc(escaped_room, room, 0, 0);
74
75                         wprintf("<CENTER><H1>");
76                         wprintf(_("Confirmation request sent"));
77                         wprintf("</H1>");
78                         wprintf(_("You are subscribing <TT>%s"
79                                 "</TT> to the <b>%s</b> mailing list.  "
80                                 "The listserver has "
81                                 "sent you an e-mail with one additional "
82                                 "Web link for you to click on to confirm "
83                                 "your subscription.  This extra step is for "
84                                 "your protection, as it prevents others from "
85                                 "being able to subscribe you to lists "
86                                 "without your consent.<br /><br />"
87                                 "Please click on the link which is being "
88                                 "e-mailed to you and your subscription will "
89                                 "be confirmed.<br />\n"),
90                                 escaped_email, escaped_room);
91                         wprintf("<a href=\"listsub\">%s</A></CENTER>\n", _("Go back..."));
92                 }
93                 else {
94                         wprintf("<FONT SIZE=+1><B>ERROR: %s</B>"
95                                 "</FONT><br /><br />\n",
96                                 &buf[4]);
97                         goto FORM;
98                 }
99         }
100
101         /**
102          * Unsubscribe command
103          */
104         else if (!strcasecmp(cmd, "unsubscribe")) {
105                 serv_printf("SUBS unsubscribe|%s|%s|%s://%s/listsub",
106                         room,
107                         email,
108                         (is_https ? "https" : "http"),
109                         WC->http_host
110                 );
111                 serv_getln(buf, sizeof buf);
112                 if (buf[0] == '2') {
113                         wprintf("<CENTER><H1>Confirmation request sent</H1>"
114                                 "You are unsubscribing <TT>");
115                         escputs(email);
116                         wprintf("</TT> from the &quot;");
117                         escputs(room);
118                         wprintf("&quot; mailing list.  The listserver has "
119                                 "sent you an e-mail with one additional "
120                                 "Web link for you to click on to confirm "
121                                 "your unsubscription.  This extra step is for "
122                                 "your protection, as it prevents others from "
123                                 "being able to unsubscribe you from "
124                                 "lists without your consent.<br /><br />"
125                                 "Please click on the link which is being "
126                                 "e-mailed to you and your unsubscription will "
127                                 "be confirmed.<br />\n"
128                                 "<a href=\"listsub\">Back...</A></CENTER>\n"
129                         );
130                 }
131                 else {
132                         wprintf("<FONT SIZE=+1><B>ERROR: %s</B>"
133                                 "</FONT><br /><br />\n",
134                                 &buf[4]);
135                         goto FORM;
136                 }
137         }
138
139         /**
140          * Confirm command
141          */
142         else if (!strcasecmp(cmd, "confirm")) {
143                 serv_printf("SUBS confirm|%s|%s",
144                         room,
145                         token
146                 );
147                 serv_getln(buf, sizeof buf);
148                 if (buf[0] == '2') {
149                         wprintf("<CENTER><H1>Confirmation successful!</H1>");
150                 }
151                 else {
152                         wprintf("<CENTER><H1>Confirmation failed.</H1>"
153                                 "This could mean one of two things:<UL>\n"
154                                 "<LI>You waited too long to confirm your "
155                                 "subscribe/unsubscribe request (the "
156                                 "confirmation link is only valid for three "
157                                 "days)\n<LI>You have <i>already</i> "
158                                 "successfully confirmed your "
159                                 "subscribe/unsubscribe request and are "
160                                 "attempting to do it again.</UL>\n"
161                                 "The error returned by the server was: "
162                         );
163                 }
164                 wprintf("%s</CENTER><br />\n", &buf[4]);
165         }
166
167         /**
168          * Any other (invalid) command causes the form to be displayed
169          */
170         else {
171 FORM:           wprintf("<FORM METHOD=\"POST\" action=\"listsub\">\n"
172                         "<TABLE BORDER=0>\n"
173                 );
174
175                 wprintf("<TR><TD>Name of list</TD><TD>"
176                         "<SELECT NAME=\"room\" SIZE=1>\n");
177
178                 serv_puts("LPRM");
179                 serv_getln(buf, sizeof buf);
180                 if (buf[0] == '1') {
181                         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
182                                 extract_token(sroom, buf, 0, '|', sizeof sroom);
183                                 self = extract_int(buf, 4) & QR2_SELFLIST ;
184                                 if (self) {
185                                         wprintf("<OPTION VALUE=\"");
186                                         escputs(sroom);
187                                         wprintf("\">");
188                                         escputs(sroom);
189                                         wprintf("</OPTION>\n");
190                                 }
191                         }
192                 }
193                 wprintf("</SELECT>"
194                         "</TD></TR>\n");
195
196                 wprintf("<TR><TD>Your e-mail address</TD><TD>"
197                         "<INPUT TYPE=\"text\" NAME=\"email\" "
198                         "VALUE=\""
199                 );
200                 escputs(email);
201                 wprintf("\" MAXLENGTH=128></TD></TR>\n");
202
203                 wprintf("</TABLE>"
204                         "(If subscribing) preferred format: "
205                         "<INPUT TYPE=\"radio\" NAME=\"subtype\""
206                         "VALUE=\"list\">One message at a time&nbsp; "
207                         "<INPUT TYPE=\"radio\" NAME=\"subtype\""
208                         "VALUE=\"digest\" CHECKED>Digest format&nbsp; "
209                         "<br />\n"
210                         "<INPUT TYPE=\"submit\" NAME=\"cmd\""
211                         " VALUE=\"subscribe\">\n"
212                         "<INPUT TYPE=\"submit\" NAME=\"cmd\""
213                         " VALUE=\"unsubscribe\">\n"
214                         "</FORM>\n"
215                 );
216
217                 wprintf("<br />When you attempt to subscribe or unsubscribe to "
218                         "a mailing list, you will receive an e-mail containing"
219                         " one additional web link to click on for final "
220                         "confirmation.  This extra step is for your "
221                         "protection, as it prevents others from being able to "
222                         "subscribe or unsubscribe you to lists.<br />\n"
223                 );
224
225         }
226
227         wprintf("</BODY></HTML>\n");
228         wDumpContent(0);
229         end_webcit_session();
230 }
231
232
233
234 /*@}*/