5 * \defgroup Sieve view/edit sieve config
6 * \ingroup WebcitDisplayItems
11 #define MAX_SCRIPTS 100
14 * \brief view/edit sieve config
16 void display_sieve(void)
18 char script_names[MAX_SCRIPTS][64];
20 int active_script = (-1);
25 memset(script_names, 0, sizeof script_names);
27 serv_puts("MSIV listscripts");
28 serv_getln(buf, sizeof(buf));
29 if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
30 if (num_scripts < MAX_SCRIPTS) {
31 extract_token(script_names[num_scripts], buf, 0, '|', 64);
32 if (extract_int(buf, 1) > 0) {
33 active_script = num_scripts;
39 output_headers(1, 1, 2, 0, 0, 0);
41 wprintf("<script type=\"text/javascript\"> \n"
43 "var previously_active_script; \n"
45 "function ToggleSievePanels() { \n"
46 " d = ($('sieveform').bigaction.options[$('sieveform').bigaction.selectedIndex].value); \n"
47 " for (i=0; i<3; ++i) { \n"
49 " $('sievediv' + i).style.display = 'block'; \n"
52 " $('sievediv' + i).style.display = 'none'; \n"
57 "function ToggleScriptPanels() { \n"
58 " d = ($('sieveform').active_script.options[$('sieveform').active_script.selectedIndex].value); \n"
59 " if ($('script_' + previously_active_script)) { \n"
60 " $('script_' + previously_active_script).style.display = 'none'; \n"
62 " $('script_' + d).style.display = 'block'; \n"
63 " previously_active_script = d; \n"
69 wprintf("<div id=\"banner\">\n");
70 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
71 wprintf("<SPAN CLASS=\"titlebar\">");
72 wprintf(_("View/edit server-side mail filters"));
74 wprintf("</TD></TR></TABLE>\n");
75 wprintf("</div>\n<div id=\"content\">\n");
77 wprintf("<div class=\"fix_scrollbar_bug\">"
78 "<table border=0 width=100%% bgcolor=\"#FFFFFF\">"
79 "<tr><td valign=top>\n");
82 wprintf("<form id=\"sieveform\" method=\"post\" action=\"save_sieve\">\n");
84 wprintf(_("When new mail arrives: "));
85 wprintf("<select name=\"bigaction\" size=1 onChange=\"ToggleSievePanels();\">\n");
87 wprintf("<option %s value=\"0\">", ((active_script < 0) ? "selected" : ""));
88 wprintf(_("Leave it in my inbox without filtering"));
89 wprintf("</option>\n");
91 wprintf("<option value=\"1\">");
92 wprintf(_("Filter it according to rules selected below"));
93 wprintf("</option>\n");
95 wprintf("<option %s value=\"2\">", ((active_script >= 0) ? "selected" : ""));
96 wprintf(_("Filter it through a manually edited script (advanced users only)"));
97 wprintf("</option>\n");
103 /* The "no filtering" div */
105 wprintf("<div id=\"sievediv0\" style=\"display:none\">\n");
106 wprintf("<div align=\"center\"><br /><br />");
107 wprintf(_("Your incoming mail will not be filtered through any scripts."));
108 wprintf("<br /><br /></div>\n");
111 /* The "webcit managed scripts" div */
113 wprintf("<div id=\"sievediv1\" style=\"display:none\">\n");
114 wprintf("<div align=\"center\"><br /><br />");
115 wprintf("FIXME div 1 isn't finished yet");
116 wprintf("<br /><br /></div>\n");
120 /* The "I'm smart and can write my own Sieve scripts" div */
122 wprintf("<div id=\"sievediv2\" style=\"display:none\">\n");
124 if (num_scripts > 0) {
125 wprintf(_("The currently active script is: "));
126 wprintf("<select name=\"active_script\" size=1 onChange=\"ToggleScriptPanels();\">\n");
127 for (i=0; i<num_scripts; ++i) {
128 wprintf("<option %s value=\"%s\">%s</option>\n",
129 ((active_script == i) ? "selected" : ""),
134 wprintf("</select>\n");
137 if (num_scripts > 0) {
138 for (i=0; i<num_scripts; ++i) {
139 wprintf("<div id=\"script_%s\" style=\"display:none\">\n", script_names[i]);
140 wprintf("<textarea name=\"text_%s\" wrap=soft rows=20 cols=80 width=80>\n", script_names[i]);
141 serv_printf("MSIV getscript|%s", script_names[i]);
142 serv_getln(buf, sizeof buf);
143 if (buf[0] == '1') while(serv_getln(buf, sizeof (buf)), strcmp(buf, "000")) {
144 wprintf("%s\n", buf);
146 wprintf("</textarea>\n");
151 wprintf("<script type=\"text/javascript\"> \n"
152 "ToggleScriptPanels(); \n"
159 /* The rest of this is common for all panels... */
161 wprintf("<div align=\"center\"><br>");
162 wprintf("<input type=\"submit\" name=\"save_button\" value=\"%s\">", _("Save changes"));
164 wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
165 wprintf("</div></form>\n");
167 wprintf("</td></tr></table></div>\n");
169 wprintf("<script type=\"text/javascript\"> \n"
170 "ToggleSievePanels(); \n"
180 * \brief save sieve config
182 void save_sieve(void) {
184 char script_names[MAX_SCRIPTS][64];
186 int active_script = (-1);
191 if (strlen(bstr("save_button")) == 0) {
192 strcpy(WC->ImportantMessage,
193 _("Cancelled. Changes were not saved."));
198 serv_puts("MSIV listscripts");
199 serv_getln(buf, sizeof(buf));
200 if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
201 if (num_scripts < MAX_SCRIPTS) {
202 extract_token(script_names[num_scripts], buf, 0, '|', 64);
203 if (extract_int(buf, 1) > 0) {
204 active_script = num_scripts;
210 bigaction = atoi(bstr("bigaction"));
212 if (bigaction == 0) {
213 lprintf(9, "MSIV setactive||");
216 else if (bigaction == 2) {
217 lprintf(9, "MSIV setactive|%s|", bstr("active_script"));
220 if (num_scripts > 0) {
221 for (i=0; i<num_scripts; ++i) {
222 lprintf(9, "MSIV putscript|%s|", script_names[i]);
223 snprintf(this_name, sizeof this_name, "text_%s", script_names[i]);
224 lprintf(9, "%s\n", bstr(this_name));
233 strcpy(WC->ImportantMessage, "FIXME");