* Added another conditional for presence/absence of Subject: header
[citadel.git] / webcit / pushemail.c
blob2f8c6a13069acaf3b6efac4eda08fb1aea504269
1 /*
2 * Edits a users push email settings
3 * Author: Mathew McBride <matt@mcbridematt.dhs.org>
4 */
5 #include "webcit.h"
7 void display_pushemail(void) {
8 char buf[SIZ];
9 int is_none = 0;
10 int is_pager = 0;
11 int is_funambol = 0;
12 char mobnum[20];
14 svput("BOXTITLE", WCS_STRING, _("Push email and SMS settings"));
16 /* Find any existing settings*/
17 if (goto_config_room() == 0) {
18 int msgnum = 0;
19 serv_puts("MSGS ALL|0|1");
20 serv_getln(buf, sizeof(buf));
21 if (buf[0] == '8') {
22 serv_puts("subj|__ Push email settings __");
23 serv_puts("000");
24 while(serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
25 msgnum = atol(buf);
29 if (msgnum > 0L) {
30 serv_printf("MSG0 %d", msgnum);
31 serv_getln(buf, sizeof buf);
32 if (buf[0] == '1') {
33 int i =0;
34 while (serv_getln(buf, sizeof buf),
35 (strcmp(buf, "text") && strcmp(buf, "000"))) {
37 if (!strcmp(buf, "text")) {
38 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
39 if (strncasecmp(buf, "none", 4) == 0) {
40 is_none = 1;
41 } else if (strncasecmp(buf, "textmessage", 11) == 0) {
42 is_pager = 1;
43 i++;
44 } else if (strncasecmp(buf, "funambol", 8) == 0) {
45 is_funambol = 1;
46 } else if (i == 1) {
47 strncpy(mobnum, buf, 20);
48 i++;
54 if (is_none) {
55 svput("PUSH_NONE", WCS_STRING, "checked=\"checked\"");
56 } else if (is_pager) {
57 svput("PUSH_TEXT", WCS_STRING, "checked=\"checked\"");
58 svprintf(HKEY("SMSNUM"), WCS_STRING, "value=\"%s\"", mobnum);
59 } else if (is_funambol) {
60 svput("PUSH_FNBL", WCS_STRING, "checked=\"checked\"");
62 serv_printf("GOTO %s", ChrPtr(WC->wc_roomname));
63 serv_getln(buf, sizeof buf);
65 output_headers(1, 1, 2, 0, 0, 0);
66 do_template("pushemail", NULL);
67 /*do_template("endbox"); */
68 wDumpContent(1);
71 void save_pushemail(void) {
72 char buf[SIZ];
73 int msgnum = 0;
74 char *pushsetting = bstr("pushsetting");
75 char *sms = NULL;
76 if (strncasecmp(pushsetting, "textmessage", 11) == 0) {
77 sms = bstr("user_sms_number");
79 if (goto_config_room() != 0) return; /* oh well. */
80 serv_puts("MSGS ALL|0|1");
81 serv_getln(buf, sizeof buf);
82 if (buf[0] == '8') {
83 serv_puts("subj|__ Push email settings __");
84 serv_puts("000");
85 } else {
86 printf("Junk in save_pushemail buffer!: %s\n", buf);
87 return;
89 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
90 msgnum = atol(buf);
93 if (msgnum > 0L) {
94 serv_printf("DELE %d", msgnum);
95 serv_getln(buf, sizeof buf);
98 serv_printf("ENT0 1||0|1|__ Push email settings __|");
99 serv_getln(buf, sizeof buf);
100 if (buf[0] == '4') {
101 serv_puts(pushsetting);
102 if (sms != NULL) {
103 serv_puts(sms);
105 serv_puts("");
106 serv_puts("000");
109 /** Go back to the room we're supposed to be in */
110 serv_printf("GOTO %s", ChrPtr(WC->wc_roomname));
111 serv_getln(buf, sizeof buf);
112 http_redirect("display_pushemail");
115 void
116 InitModule_PUSHMAIL
117 (void)
119 WebcitAddUrlHandler(HKEY("display_pushemail"), display_pushemail, 0);
120 WebcitAddUrlHandler(HKEY("save_pushemail"), save_pushemail, 0);