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
21 int Conditional_LISTSUB_EXECUTE_SUBSCRIBE(StrBuf *Target, WCTemplputParams *TP)
22 {
23         int rc;
24         StrBuf *Line;
25         const char *ImpMsg;
26         const StrBuf *Room, *Email, *SubType;
27
28         if (strcmp(bstr("cmd"), "subscribe")) {
29                 return 0;
30         }
31
32         Room = sbstr("room");
33         if (Room == NULL)
34         {
35                 ImpMsg = _("You need to specify the mailinglist to subscribe to.");
36                 AppendImportantMessage(ImpMsg, -1);
37                 return 0;
38         }
39         Email = sbstr("email");
40         if (Email == NULL)
41         {
42                 ImpMsg = _("You need to specify the email address you'd like to subscribe with.");
43                 AppendImportantMessage(ImpMsg, -1);
44                 return 0;
45         }
46         SubType = sbstr("subtype");
47
48         Line = NewStrBuf();
49         serv_printf("SUBS subscribe|%s|%s|%s|%s/listsub",
50                     ChrPtr(Room),
51                     ChrPtr(Email),
52                     ChrPtr(SubType),
53                     ChrPtr(site_prefix)
54                 );
55         StrBuf_ServGetln(Line);
56         rc = GetServerStatusMsg(Line, NULL, 1, 2);
57         FreeStrBuf(&Line);
58         if (rc == 2)
59                 putbstr("__FAIL", NewStrBufPlain(HKEY("1")));
60         return rc == 2;
61 }
62
63 int Conditional_LISTSUB_EXECUTE_UNSUBSCRIBE(StrBuf *Target, WCTemplputParams *TP)
64 {
65         int rc;
66         StrBuf *Line;
67         const char *ImpMsg;
68         const StrBuf *Room, *Email;
69
70         if (strcmp(bstr("cmd"), "unsubscribe")) {
71                 return 0;
72         }
73
74         Room = sbstr("room");
75         if (Room == NULL)
76         {
77                 ImpMsg = _("You need to specify the mailinglist to subscribe to.");
78                 AppendImportantMessage(ImpMsg, -1);
79                 return 0;
80         }
81         Email = sbstr("email");
82         if (Email == NULL)
83         {
84                 ImpMsg = _("You need to specify the email address you'd like to subscribe with.");
85                 AppendImportantMessage(ImpMsg, -1);
86                 return 0;
87         }
88
89         serv_printf("SUBS unsubscribe|%s|%s|%s/listsub",
90                     ChrPtr(Room),
91                     ChrPtr(Email),
92                     ChrPtr(site_prefix)
93                 );
94         Line = NewStrBuf();
95         StrBuf_ServGetln(Line);
96         rc = GetServerStatusMsg(Line, NULL, 1, 2);
97         FreeStrBuf(&Line);
98         if (rc == 2)
99                 putbstr("__FAIL", NewStrBufPlain(HKEY("1")));
100         return rc == 2;
101 }
102
103 int Conditional_LISTSUB_EXECUTE_CONFIRM_SUBSCRIBE(StrBuf *Target, WCTemplputParams *TP)
104 {
105         int rc;
106         StrBuf *Line;
107         const char *ImpMsg;
108         const StrBuf *Room, *Token;
109
110         if (strcmp(bstr("cmd"), "confirm")) {
111                 return 0;
112         }
113
114         Room = sbstr("room");
115         if (Room == NULL)
116         {
117                 ImpMsg = _("You need to specify the mailinglist to subscribe to.");
118                 AppendImportantMessage(ImpMsg, -1);
119                 return 0;
120         }
121         Token = sbstr("token");
122         if (Room == NULL)
123         {
124                 ImpMsg = _("You need to specify the mailinglist to subscribe to.");
125                 AppendImportantMessage(ImpMsg, -1);
126                 return 0;
127         }
128
129         Line = NewStrBuf();
130         serv_printf("SUBS confirm|%s|%s",
131                     ChrPtr(Room),
132                     ChrPtr(Token)
133                 );
134         StrBuf_ServGetln(Line);
135         rc = GetServerStatusMsg(Line, NULL, 1, 2);
136         FreeStrBuf(&Line);
137         if (rc == 2)
138                 putbstr("__FAIL", NewStrBufPlain(HKEY("1")));
139         return rc == 2;
140 }
141
142 void do_listsub(void)
143 {
144         if (!havebstr("cmd"))
145         {
146                 putbstr("cmd", NewStrBufPlain(HKEY("choose")));
147         }
148         output_headers(1, 0, 0, 0, 1, 0);
149         do_template("listsub_display");
150         end_burst();
151 }
152
153 void 
154 InitModule_LISTSUB
155 (void)
156 {
157         RegisterConditional("COND:LISTSUB:EXECUTE:SUBSCRIBE", 0, Conditional_LISTSUB_EXECUTE_SUBSCRIBE,  CTX_NONE);
158         RegisterConditional("COND:LISTSUB:EXECUTE:UNSUBSCRIBE", 0, Conditional_LISTSUB_EXECUTE_UNSUBSCRIBE,  CTX_NONE);
159         RegisterConditional("COND:LISTSUB:EXECUTE:CONFIRM:SUBSCRIBE", 0, Conditional_LISTSUB_EXECUTE_CONFIRM_SUBSCRIBE,  CTX_NONE);
160
161         WebcitAddUrlHandler(HKEY("listsub"), "", 0, do_listsub, ANONYMOUS|COOKIEUNNEEDED|FORCE_SESSIONCLOSE);
162
163
164 }