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