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 "<img src=\"static/advanpage2_48x.gif\">");
73 wprintf(_("View/edit server-side mail filters"));
75 wprintf("</TD></TR></TABLE>\n");
76 wprintf("</div>\n<div id=\"content\">\n");
78 wprintf("<div class=\"fix_scrollbar_bug\">"
79 "<table border=0 width=100%% bgcolor=\"#FFFFFF\">"
80 "<tr><td valign=top>\n");
83 wprintf("<form id=\"sieveform\" method=\"post\" action=\"save_sieve\">\n");
85 wprintf(_("When new mail arrives: "));
86 wprintf("<select name=\"bigaction\" size=1 onChange=\"ToggleSievePanels();\">\n");
88 wprintf("<option %s value=\"0\">", ((active_script < 0) ? "selected" : ""));
89 wprintf(_("Leave it in my inbox without filtering"));
90 wprintf("</option>\n");
93 * FIXME uncomment this when we write the rules editor
95 wprintf("<option value=\"1\">");
96 wprintf(_("Filter it according to rules selected below"));
97 wprintf("</option>\n");
101 wprintf("<option %s value=\"2\">", ((active_script >= 0) ? "selected" : ""));
102 wprintf(_("Filter it through a manually edited script (advanced users only)"));
103 wprintf("</option>\n");
105 wprintf("</select>");
109 /* The "no filtering" div */
111 wprintf("<div id=\"sievediv0\" style=\"display:none\">\n");
112 wprintf("<div align=\"center\"><br /><br />");
113 wprintf(_("Your incoming mail will not be filtered through any scripts."));
114 wprintf("<br /><br /></div>\n");
117 /* The "webcit managed scripts" div */
119 wprintf("<div id=\"sievediv1\" style=\"display:none\">\n");
120 wprintf("<div align=\"center\"><br /><br />");
122 wprintf("<br /><br /></div>\n");
125 /* The "I'm smart and can write my own Sieve scripts" div */
127 wprintf("<div id=\"sievediv2\" style=\"display:none\">\n");
129 if (num_scripts > 0) {
130 wprintf(_("The currently active script is: "));
131 wprintf("<select name=\"active_script\" size=1 onChange=\"ToggleScriptPanels();\">\n");
132 for (i=0; i<num_scripts; ++i) {
133 wprintf("<option %s value=\"%s\">%s</option>\n",
134 ((active_script == i) ? "selected" : ""),
139 wprintf("</select>\n");
142 wprintf(" ");
143 wprintf("<a href=\"display_add_remove_scripts\">%s</a>\n", _("Add or delete scripts"));
147 if (num_scripts > 0) {
148 for (i=0; i<num_scripts; ++i) {
149 wprintf("<div id=\"script_%s\" style=\"display:none\">\n", script_names[i]);
150 wprintf("<textarea name=\"text_%s\" wrap=soft rows=20 cols=80 width=80>\n", script_names[i]);
151 serv_printf("MSIV getscript|%s", script_names[i]);
152 serv_getln(buf, sizeof buf);
153 if (buf[0] == '1') while(serv_getln(buf, sizeof (buf)), strcmp(buf, "000")) {
154 wprintf("%s\n", buf);
156 wprintf("</textarea>\n");
161 wprintf("<script type=\"text/javascript\"> \n"
162 "ToggleScriptPanels(); \n"
169 /* The rest of this is common for all panels... */
171 wprintf("<div align=\"center\"><br>");
172 wprintf("<input type=\"submit\" name=\"save_button\" value=\"%s\">", _("Save changes"));
174 wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
175 wprintf("</div></form>\n");
177 wprintf("</td></tr></table></div>\n");
179 wprintf("<script type=\"text/javascript\"> \n"
180 "ToggleSievePanels(); \n"
190 * \brief save sieve config
192 void save_sieve(void) {
194 char script_names[MAX_SCRIPTS][64];
196 int active_script = (-1);
201 if (strlen(bstr("save_button")) == 0) {
202 strcpy(WC->ImportantMessage,
203 _("Cancelled. Changes were not saved."));
208 serv_puts("MSIV listscripts");
209 serv_getln(buf, sizeof(buf));
210 if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
211 if (num_scripts < MAX_SCRIPTS) {
212 extract_token(script_names[num_scripts], buf, 0, '|', 64);
213 if (extract_int(buf, 1) > 0) {
214 active_script = num_scripts;
220 bigaction = atoi(bstr("bigaction"));
222 if (bigaction == 0) {
223 serv_puts("MSIV setactive||");
224 serv_getln(buf, sizeof buf);
227 else if (bigaction == 2) {
228 serv_printf("MSIV setactive|%s|", bstr("active_script"));
229 serv_getln(buf, sizeof buf);
232 if (num_scripts > 0) {
233 for (i=0; i<num_scripts; ++i) {
234 serv_printf("MSIV putscript|%s|", script_names[i]);
235 serv_getln(buf, sizeof buf);
237 snprintf(this_name, sizeof this_name, "text_%s", script_names[i]);
238 striplt(bstr(this_name));
239 serv_printf("%s", bstr(this_name));
245 strcpy(WC->ImportantMessage, _("Your changes have been saved."));
252 * \brief show a list of available scripts to add/remove them
254 void display_add_remove_scripts(char *message)
257 char script_name[256];
259 output_headers(1, 1, 2, 0, 0, 0);
260 wprintf("<div id=\"banner\">\n");
261 wprintf("<table width=100%% border=0 bgcolor=#444455><tr>"
263 "<span class=\"titlebar\">"
264 "<img src=\"static/advanpage2_48x.gif\">");
265 wprintf(_("Add or delete scripts"));
266 wprintf("</span></td></tr></table>\n"
267 "</div>\n<div id=\"content\">\n"
270 if (message != NULL) wprintf(message);
272 wprintf("<table border=0 cellspacing=10><tr valign=top><td>\n");
274 svprintf("BOXTITLE", WCS_STRING, _("Add a new script"));
275 do_template("beginbox");
277 wprintf(_("To create a new script, enter the desired "
278 "script name in the box below and click 'Create'."));
279 wprintf("<br /><br />");
281 wprintf("<center><form method=\"POST\" action=\"create_script\">\n");
282 wprintf(_("Script name: "));
283 wprintf("<input type=\"text\" name=\"script_name\"><br />\n"
284 "<input type=\"submit\" name=\"create_button\" value=\"%s\">"
285 "</form></center>\n", _("Create"));
287 do_template("endbox");
289 svprintf("BOXTITLE", WCS_STRING, _("Edit scripts"));
290 do_template("beginbox");
291 wprintf("<br /><div align=center><a href=\"display_sieve\">%s</a><br /><br />\n",
292 _("Return to the script editing screen")
294 do_template("endbox");
296 wprintf("</td><td>");
298 svprintf("BOXTITLE", WCS_STRING, _("Delete scripts"));
299 do_template("beginbox");
301 wprintf(_("To delete an existing script, select the script "
302 "name from the list and click 'Delete'."));
303 wprintf("<br /><br />");
306 "<form method=\"POST\" action=\"delete_script\">\n");
307 wprintf("<select name=\"script_name\" size=10 style=\"width:100%%\">\n");
309 serv_puts("MSIV listscripts");
310 serv_getln(buf, sizeof buf);
312 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
313 extract_token(script_name, buf, 0, '|', sizeof script_name);
314 if (extract_int(buf, 1) == 0) {
316 escputs(script_name);
317 wprintf("</option>\n");
321 wprintf("</select><br />\n");
323 wprintf("<input type=\"submit\" name=\"delete_button\" value=\"%s\" "
324 "onClick=\"return confirm('%s');\">", _("Delete script"), _("Delete this script?"));
325 wprintf("</form></center>\n");
326 do_template("endbox");
328 wprintf("</td></tr></table>\n");
336 * \brief delete a script
338 void delete_script(void) {
341 serv_printf("MSIV deletescript|%s", bstr("script_name"));
342 serv_getln(buf, sizeof buf);
343 display_add_remove_scripts(&buf[4]);
349 * \brief create a new script
350 * take the web environment script name and create it on the citadel server
352 void create_script(void) {
355 serv_printf("MSIV getscript|%s", bstr("script_name"));
356 serv_getln(buf, sizeof buf);
358 while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
361 display_add_remove_scripts(_("A script by that name already exists."));
365 serv_printf("MSIV putscript|%s", bstr("script_name"));
366 serv_getln(buf, sizeof buf);
370 display_add_remove_scripts(_("A new script has been created. Return to the script editing screen to edit and activate it."));
374 display_add_remove_scripts(&buf[4]);