Mailing list header changes (fuck you Google)
[citadel.git] / webcit / listsub.c
1 /*
2  * Web forms for handling mailing list subscribe/unsubscribe requests.
3  *
4  * Copyright (c) 1996-2012 by the citadel.org team
5  *
6  * This program is open source software.  You can redistribute it and/or
7  * modify it under the terms of the GNU General Public License, version 3.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  */
14
15 #include "webcit.h"
16
17 /*
18  * List subscription handling
19  */
20 int Conditional_LISTSUB_EXECUTE_SUBSCRIBE(StrBuf *Target, WCTemplputParams *TP) {
21         int rc;
22         StrBuf *Line;
23         const char *ImpMsg;
24         const StrBuf *Room, *Email;
25
26         if (strcmp(bstr("cmd"), "subscribe")) {
27                 return 0;
28         }
29
30         Room = sbstr("room");
31         if (Room == NULL)
32         {
33                 ImpMsg = _("You need to specify the mailinglist to subscribe to.");
34                 AppendImportantMessage(ImpMsg, -1);
35                 return 0;
36         }
37         Email = sbstr("email");
38         if (Email == NULL)
39         {
40                 ImpMsg = _("You need to specify the email address you'd like to subscribe with.");
41                 AppendImportantMessage(ImpMsg, -1);
42                 return 0;
43         }
44
45         Line = NewStrBuf();
46         serv_printf("LSUB subscribe|%s|%s|%s/listsub", ChrPtr(Room), ChrPtr(Email), ChrPtr(site_prefix));
47         StrBuf_ServGetln(Line);
48         rc = GetServerStatusMsg(Line, NULL, 1, 2);
49         FreeStrBuf(&Line);
50         if (rc == 2) {
51                 putbstr("__FAIL", NewStrBufPlain(HKEY("1")));
52         }
53         return rc == 2;
54 }
55
56
57 int Conditional_LISTSUB_EXECUTE_UNSUBSCRIBE(StrBuf *Target, WCTemplputParams *TP) {
58         int rc;
59         StrBuf *Line;
60         const char *ImpMsg;
61         const StrBuf *Room, *Email;
62
63         if (strcmp(bstr("cmd"), "unsubscribe")) {
64                 return 0;
65         }
66
67         Room = sbstr("room");
68         if (Room == NULL)
69         {
70                 ImpMsg = _("You need to specify the mailinglist to subscribe to.");
71                 AppendImportantMessage(ImpMsg, -1);
72                 return 0;
73         }
74         Email = sbstr("email");
75         if (Email == NULL)
76         {
77                 ImpMsg = _("You need to specify the email address you'd like to subscribe with.");
78                 AppendImportantMessage(ImpMsg, -1);
79                 return 0;
80         }
81
82         serv_printf("LSUB unsubscribe|%s|%s|%s/listsub", ChrPtr(Room), ChrPtr(Email), ChrPtr(site_prefix));
83         Line = NewStrBuf();
84         StrBuf_ServGetln(Line);
85         rc = GetServerStatusMsg(Line, NULL, 1, 2);
86         FreeStrBuf(&Line);
87         if (rc == 2)
88                 putbstr("__FAIL", NewStrBufPlain(HKEY("1")));
89         return rc == 2;
90 }
91
92 int Conditional_LISTSUB_EXECUTE_CONFIRM_SUBSCRIBE(StrBuf *Target, WCTemplputParams *TP)
93 {
94         int rc;
95         StrBuf *Line;
96         const char *ImpMsg;
97         const StrBuf *Room, *Token;
98
99         if (strcmp(bstr("cmd"), "confirm")) {
100                 return 0;
101         }
102
103         Room = sbstr("room");
104         if (Room == NULL)
105         {
106                 ImpMsg = _("You need to specify the mailinglist to subscribe to.");
107                 AppendImportantMessage(ImpMsg, -1);
108                 return 0;
109         }
110         Token = sbstr("token");
111         if (Room == NULL)
112         {
113                 ImpMsg = _("You need to specify the mailinglist to subscribe to.");
114                 AppendImportantMessage(ImpMsg, -1);
115                 return 0;
116         }
117
118         Line = NewStrBuf();
119         serv_printf("LSUB confirm|%s|%s", ChrPtr(Room), ChrPtr(Token));
120         StrBuf_ServGetln(Line);
121         rc = GetServerStatusMsg(Line, NULL, 1, 2);
122         FreeStrBuf(&Line);
123         if (rc == 2)
124                 putbstr("__FAIL", NewStrBufPlain(HKEY("1")));
125         return rc == 2;
126 }
127
128 void do_listsub(void)
129 {
130         if (!havebstr("cmd"))
131         {
132                 putbstr("cmd", NewStrBufPlain(HKEY("choose")));
133         }
134         output_headers(1, 0, 0, 0, 1, 0);
135         do_template("listsub_display");
136         end_burst();
137 }
138
139 void 
140 InitModule_LISTSUB
141 (void)
142 {
143         RegisterConditional("COND:LISTSUB:EXECUTE:SUBSCRIBE", 0, Conditional_LISTSUB_EXECUTE_SUBSCRIBE,  CTX_NONE);
144         RegisterConditional("COND:LISTSUB:EXECUTE:UNSUBSCRIBE", 0, Conditional_LISTSUB_EXECUTE_UNSUBSCRIBE,  CTX_NONE);
145         RegisterConditional("COND:LISTSUB:EXECUTE:CONFIRM:SUBSCRIBE", 0, Conditional_LISTSUB_EXECUTE_CONFIRM_SUBSCRIBE,  CTX_NONE);
146
147         WebcitAddUrlHandler(HKEY("listsub"), "", 0, do_listsub, ANONYMOUS|COOKIEUNNEEDED|FORCE_SESSIONCLOSE);
148
149
150 }