validate_recipients() now strips out duplicate recipients ... probably some 15 years...
[citadel] / webcit / pushemail.c
1 /*
2  * Edits a users push email settings 
3  * Author: Mathew McBride <matt@mcbridematt.dhs.org>
4  */
5 #include "webcit.h"
6
7 void display_pushemail(void) 
8 {
9         folder Room;
10         int Done = 0;
11         StrBuf *Buf;
12         long vector[8] = {8, 0, 0, 1, 2, 3, 4, 5};
13         WCTemplputParams SubTP;
14         char mobnum[20];
15
16         StackContext(NULL, &SubTP, &vector, CTX_LONGVECTOR, 0, NULL);
17         vector[0] = 16;
18
19         /* Find any existing settings*/
20         Buf = NewStrBuf();
21         memset(&Room, 0, sizeof(folder));
22         if (goto_config_room(Buf, &Room) == 0) {
23                 int msgnum = 0;
24                 serv_puts("MSGS ALL|0|1");
25                 StrBuf_ServGetln(Buf);
26                 if (GetServerStatus(Buf, NULL) == 8) {
27                         serv_puts("subj|__ Push email settings __");
28                         serv_puts("000");
29                         while (!Done &&
30                                StrBuf_ServGetln(Buf) >= 0) {
31                                 if ( (StrLength(Buf)==3) && 
32                                      !strcmp(ChrPtr(Buf), "000")) {
33                                         Done = 1;
34                                         break;
35                                 }
36                                 msgnum = StrTol(Buf);
37                         }
38                 }
39                 if (msgnum > 0L) {
40                 serv_printf("MSG0 %d", msgnum);
41                 StrBuf_ServGetln(Buf);
42                 if (GetServerStatus(Buf, NULL) == 1) {
43                         int i =0;
44                         Done = 0;
45                         while (!Done &&
46                                StrBuf_ServGetln(Buf) >= 0) {
47                                 if (( (StrLength(Buf)==3) && 
48                                       !strcmp(ChrPtr(Buf), "000"))||
49                                     ((StrLength(Buf)==4) && 
50                                      !strcmp(ChrPtr(Buf), "text")))
51                                 {
52                                         Done = 1;
53                                         break;
54                                 }
55                         }
56                         if (!strcmp(ChrPtr(Buf), "text")) {
57                                 Done = 0;
58                                 while (!Done &&
59                                        StrBuf_ServGetln(Buf) >= 0) {
60                                         if ( (StrLength(Buf)==3) && 
61                                              !strcmp(ChrPtr(Buf), "000")) {
62                                                 Done = 1;
63                                                 break;
64                                         }
65                                         if (strncasecmp(ChrPtr(Buf), "none", 4) == 0) {
66                                                 vector[1] = 0;
67                                         } else if (strncasecmp(ChrPtr(Buf), "textmessage", 11) == 0) {
68                                                 vector[1] = 1;
69                                                 i++;
70                                         } else if (strncasecmp(ChrPtr(Buf), "funambol", 8) == 0) {
71                                                 vector[1] = 2;
72                                         } else if (strncasecmp(ChrPtr(Buf), "httpmessage", 12) == 0) {
73                                                 vector[1] = 3;
74                                         } else if (i == 1) {
75                                                 strncpy(mobnum, ChrPtr(Buf), 20);
76                                                 i++;
77                                         }
78                                 }       
79                         }
80                 }
81                 }
82                 serv_printf("GOTO %s", ChrPtr(WC->CurRoom.name));
83                 StrBuf_ServGetln(Buf);
84                 GetServerStatus(Buf, NULL);
85         }
86         FlushFolder(&Room);
87         output_headers(1, 1, 1, 0, 0, 0);
88         DoTemplate(HKEY("prefs_pushemail"), NULL, &SubTP);
89         wDumpContent(1);
90         UnStackContext(&SubTP);
91         FreeStrBuf(&Buf);
92 }
93
94 void save_pushemail(void) 
95 {
96         folder Room;
97         int Done = 0;
98         StrBuf *Buf;
99         char buf[SIZ];
100         int msgnum = 0;
101         char *pushsetting = bstr("pushsetting");
102         char *sms = NULL;
103
104         if (strncasecmp(pushsetting, "textmessage", 11) == 0) {
105                 sms = bstr("user_sms_number");
106         }
107         Buf = NewStrBuf();
108         memset(&Room, 0, sizeof(folder));
109         if (goto_config_room(Buf, &Room) != 0) {
110                 FreeStrBuf(&Buf);
111                 FlushFolder(&Room);
112                 return; /* oh well. */
113         }
114         FlushFolder(&Room);
115
116         serv_puts("MSGS ALL|0|1");
117         StrBuf_ServGetln(Buf);
118         if (GetServerStatus(Buf, NULL) == 8) {
119                 serv_puts("subj|__ Push email settings __");
120                 serv_puts("000");
121         } else {
122                 printf("Junk in save_pushemail buffer!: %s\n", buf);
123                 FreeStrBuf(&Buf);
124                 return;
125         }
126
127         while (!Done &&
128                StrBuf_ServGetln(Buf) >= 0) {
129                 if ( (StrLength(Buf)==3) && 
130                      !strcmp(ChrPtr(Buf), "000")) {
131                         Done = 1;
132                         break;
133                 }
134                 msgnum = StrTol(Buf);
135         }
136
137         if (msgnum > 0L) {
138                 serv_printf("DELE %d", msgnum);
139                 StrBuf_ServGetln(Buf);
140                 GetServerStatus(Buf, NULL);
141         }
142
143         serv_printf("ENT0 1||0|1|__ Push email settings __|");
144         StrBuf_ServGetln(Buf);
145         if (GetServerStatus(Buf, NULL) == 4) {
146                 serv_puts(pushsetting);
147                 if (sms != NULL) {
148                 serv_puts(sms);
149                 } 
150                 serv_puts("");
151                 serv_puts("000");
152         }
153
154         /** Go back to the room we're supposed to be in */
155         serv_printf("GOTO %s", ChrPtr(WC->CurRoom.name));
156         StrBuf_ServGetln(Buf);
157         GetServerStatus(Buf, NULL);
158         http_redirect("display_pushemail");
159         FreeStrBuf(&Buf);
160 }
161
162 void 
163 InitModule_PUSHMAIL
164 (void)
165 {
166         WebcitAddUrlHandler(HKEY("display_pushemail"), "", 0, display_pushemail, 0);
167         WebcitAddUrlHandler(HKEY("save_pushemail"), "", 0, save_pushemail, 0);
168 }