5 * \defgroup Sieve view/edit sieve config
6 * \ingroup WebcitDisplayItems
11 #define MAX_SCRIPTS 100
15 * \brief view/edit sieve config
17 void display_sieve(void)
19 char script_names[MAX_SCRIPTS][64];
21 int active_script = (-1);
26 memset(script_names, 0, sizeof script_names);
28 serv_puts("MSIV listscripts");
29 serv_getln(buf, sizeof(buf));
30 if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
31 if (num_scripts < MAX_SCRIPTS) {
32 extract_token(script_names[num_scripts], buf, 0, '|', 64);
33 if (extract_int(buf, 1) > 0) {
34 active_script = num_scripts;
40 output_headers(1, 1, 2, 0, 0, 0);
42 wprintf("<script type=\"text/javascript\"> \n"
44 "var previously_active_script; \n"
46 "function ToggleSievePanels() { \n"
47 " d = ($('sieveform').bigaction.options[$('sieveform').bigaction.selectedIndex].value); \n"
48 " for (i=0; i<3; ++i) { \n"
50 " $('sievediv' + i).style.display = 'block'; \n"
53 " $('sievediv' + i).style.display = 'none'; \n"
58 "function ToggleScriptPanels() { \n"
59 " d = ($('sieveform').active_script.options[$('sieveform').active_script.selectedIndex].value); \n"
60 " if ($('script_' + previously_active_script)) { \n"
61 " $('script_' + previously_active_script).style.display = 'none'; \n"
63 " $('script_' + d).style.display = 'block'; \n"
64 " previously_active_script = d; \n"
70 wprintf("<div id=\"banner\">\n");
71 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
72 wprintf("<SPAN CLASS=\"titlebar\">"
73 "<img src=\"static/advanpage2_48x.gif\">");
74 wprintf(_("View/edit server-side mail filters"));
76 wprintf("</TD></TR></TABLE>\n");
77 wprintf("</div>\n<div id=\"content\">\n");
79 wprintf("<div class=\"fix_scrollbar_bug\">"
80 "<table border=0 width=100%% bgcolor=\"#FFFFFF\">"
81 "<tr><td valign=top>\n");
84 wprintf("<form id=\"sieveform\" method=\"post\" action=\"save_sieve\">\n");
86 wprintf(_("When new mail arrives: "));
87 wprintf("<select name=\"bigaction\" size=1 onChange=\"ToggleSievePanels();\">\n");
89 wprintf("<option %s value=\"0\">", ((active_script < 0) ? "selected" : ""));
90 wprintf(_("Leave it in my inbox without filtering"));
91 wprintf("</option>\n");
93 wprintf("<option value=\"1\">");
94 wprintf(_("Filter it according to rules selected below"));
95 wprintf("</option>\n");
97 wprintf("<option %s value=\"2\">", ((active_script >= 0) ? "selected" : ""));
98 wprintf(_("Filter it through a manually edited script (advanced users only)"));
99 wprintf("</option>\n");
101 wprintf("</select>");
105 /* The "no filtering" div */
107 wprintf("<div id=\"sievediv0\" style=\"display:none\">\n");
108 wprintf("<div align=\"center\"><br /><br />");
109 wprintf(_("Your incoming mail will not be filtered through any scripts."));
110 wprintf("<br /><br /></div>\n");
113 /* The "webcit managed scripts" div */
115 wprintf("<div id=\"sievediv1\" style=\"display:none\">\n");
116 display_rules_editor_inner_div();
119 /* The "I'm smart and can write my own Sieve scripts" div */
121 wprintf("<div id=\"sievediv2\" style=\"display:none\">\n");
123 if (num_scripts > 0) {
124 wprintf(_("The currently active script is: "));
125 wprintf("<select name=\"active_script\" size=1 onChange=\"ToggleScriptPanels();\">\n");
126 for (i=0; i<num_scripts; ++i) {
127 wprintf("<option %s value=\"%s\">%s</option>\n",
128 ((active_script == i) ? "selected" : ""),
133 wprintf("</select>\n");
136 wprintf(" ");
137 wprintf("<a href=\"display_add_remove_scripts\">%s</a>\n", _("Add or delete scripts"));
141 if (num_scripts > 0) {
142 for (i=0; i<num_scripts; ++i) {
143 wprintf("<div id=\"script_%s\" style=\"display:none\">\n", script_names[i]);
144 wprintf("<textarea name=\"text_%s\" wrap=soft rows=20 cols=80 width=80>\n", script_names[i]);
145 serv_printf("MSIV getscript|%s", script_names[i]);
146 serv_getln(buf, sizeof buf);
147 if (buf[0] == '1') while(serv_getln(buf, sizeof (buf)), strcmp(buf, "000")) {
148 wprintf("%s\n", buf);
150 wprintf("</textarea>\n");
155 wprintf("<script type=\"text/javascript\"> \n"
156 "ToggleScriptPanels(); \n"
163 /* The rest of this is common for all panels... */
165 wprintf("<div align=\"center\"><br>");
166 wprintf("<input type=\"submit\" name=\"save_button\" value=\"%s\">", _("Save changes"));
168 wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
169 wprintf("</div></form>\n");
171 wprintf("</td></tr></table></div>\n");
173 wprintf("<script type=\"text/javascript\"> \n"
174 "ToggleSievePanels(); \n"
184 * \brief save sieve config
186 void save_sieve(void) {
188 char script_names[MAX_SCRIPTS][64];
190 int active_script = (-1);
195 if (strlen(bstr("save_button")) == 0) {
196 strcpy(WC->ImportantMessage,
197 _("Cancelled. Changes were not saved."));
202 serv_puts("MSIV listscripts");
203 serv_getln(buf, sizeof(buf));
204 if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
205 if (num_scripts < MAX_SCRIPTS) {
206 extract_token(script_names[num_scripts], buf, 0, '|', 64);
207 if (extract_int(buf, 1) > 0) {
208 active_script = num_scripts;
214 bigaction = atoi(bstr("bigaction"));
216 if (bigaction == 0) {
217 serv_puts("MSIV setactive||");
218 serv_getln(buf, sizeof buf);
221 else if (bigaction == 2) {
222 serv_printf("MSIV setactive|%s|", bstr("active_script"));
223 serv_getln(buf, sizeof buf);
226 if (num_scripts > 0) {
227 for (i=0; i<num_scripts; ++i) {
228 serv_printf("MSIV putscript|%s|", script_names[i]);
229 serv_getln(buf, sizeof buf);
231 snprintf(this_name, sizeof this_name, "text_%s", script_names[i]);
232 striplt(bstr(this_name));
233 serv_printf("%s", bstr(this_name));
239 strcpy(WC->ImportantMessage, _("Your changes have been saved."));
246 * \brief show a list of available scripts to add/remove them
248 void display_add_remove_scripts(char *message)
251 char script_name[256];
253 output_headers(1, 1, 2, 0, 0, 0);
254 wprintf("<div id=\"banner\">\n");
255 wprintf("<table width=100%% border=0 bgcolor=#444455><tr>"
257 "<span class=\"titlebar\">"
258 "<img src=\"static/advanpage2_48x.gif\">");
259 wprintf(_("Add or delete scripts"));
260 wprintf("</span></td></tr></table>\n"
261 "</div>\n<div id=\"content\">\n"
264 if (message != NULL) wprintf(message);
266 wprintf("<table border=0 cellspacing=10><tr valign=top><td>\n");
268 svprintf("BOXTITLE", WCS_STRING, _("Add a new script"));
269 do_template("beginbox");
271 wprintf(_("To create a new script, enter the desired "
272 "script name in the box below and click 'Create'."));
273 wprintf("<br /><br />");
275 wprintf("<center><form method=\"POST\" action=\"create_script\">\n");
276 wprintf(_("Script name: "));
277 wprintf("<input type=\"text\" name=\"script_name\"><br />\n"
278 "<input type=\"submit\" name=\"create_button\" value=\"%s\">"
279 "</form></center>\n", _("Create"));
281 do_template("endbox");
283 svprintf("BOXTITLE", WCS_STRING, _("Edit scripts"));
284 do_template("beginbox");
285 wprintf("<br /><div align=center><a href=\"display_sieve\">%s</a><br /><br />\n",
286 _("Return to the script editing screen")
288 do_template("endbox");
290 wprintf("</td><td>");
292 svprintf("BOXTITLE", WCS_STRING, _("Delete scripts"));
293 do_template("beginbox");
295 wprintf(_("To delete an existing script, select the script "
296 "name from the list and click 'Delete'."));
297 wprintf("<br /><br />");
300 "<form method=\"POST\" action=\"delete_script\">\n");
301 wprintf("<select name=\"script_name\" size=10 style=\"width:100%%\">\n");
303 serv_puts("MSIV listscripts");
304 serv_getln(buf, sizeof buf);
306 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
307 extract_token(script_name, buf, 0, '|', sizeof script_name);
308 if (extract_int(buf, 1) == 0) {
310 escputs(script_name);
311 wprintf("</option>\n");
315 wprintf("</select><br />\n");
317 wprintf("<input type=\"submit\" name=\"delete_button\" value=\"%s\" "
318 "onClick=\"return confirm('%s');\">", _("Delete script"), _("Delete this script?"));
319 wprintf("</form></center>\n");
320 do_template("endbox");
322 wprintf("</td></tr></table>\n");
330 * \brief delete a script
332 void delete_script(void) {
335 serv_printf("MSIV deletescript|%s", bstr("script_name"));
336 serv_getln(buf, sizeof buf);
337 display_add_remove_scripts(&buf[4]);
343 * \brief create a new script
344 * take the web environment script name and create it on the citadel server
346 void create_script(void) {
349 serv_printf("MSIV getscript|%s", bstr("script_name"));
350 serv_getln(buf, sizeof buf);
352 while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
355 display_add_remove_scripts(_("A script by that name already exists."));
359 serv_printf("MSIV putscript|%s", bstr("script_name"));
360 serv_getln(buf, sizeof buf);
364 display_add_remove_scripts(_("A new script has been created. Return to the script editing screen to edit and activate it."));
368 display_add_remove_scripts(&buf[4]);
374 void display_rules_editor_inner_div(void) {
376 char buf[256], targ[256];
379 * This script should get called by every onChange event...
382 wprintf("<script type=\"text/javascript\"> \n"
384 "var highest_active_rule = (-1); \n"
386 "function UpdateRules() { \n"
387 " for (i=0; i<%d; ++i) { \n", MAX_RULES);
388 wprintf(" d = ($('action'+i).options[$('action'+i).selectedIndex].value); \n"
389 " if (d == 'fileinto') { \n"
390 " $('div_fileinto'+i).style.display = 'block'; \n"
391 " $('div_redirect'+i).style.display = 'none'; \n"
392 " } else if (d == 'redirect') { \n"
393 " $('div_fileinto'+i).style.display = 'none'; \n"
394 " $('div_redirect'+i).style.display = 'block'; \n"
396 " $('div_fileinto'+i).style.display = 'none'; \n"
397 " $('div_redirect'+i).style.display = 'none'; \n"
402 * Show only the active rows...
404 wprintf(" for (i=0; i<%d; ++i) { \n", MAX_RULES);
405 wprintf(" if ($('active'+i).checked) { \n"
406 " $('rule' + i).style.display = 'block'; \n"
407 " highest_active_rule = i; \n"
410 " $('rule' + i).style.display = 'none'; \n"
415 * Add a rule (really, just un-hide it)
416 * FIXME check the upper bound
418 "function AddRule() { \n"
419 " highest_active_rule = highest_active_rule + 1; \n"
420 " $('active'+highest_active_rule).checked = true; \n"
429 wprintf("<table class=\"mailbox_summary\" rules=rows cellpadding=2 "
430 "style=\"width:100%%;-moz-user-select:none;\">"
433 for (i=0; i<MAX_RULES; ++i) {
435 wprintf("<tr id=\"rule%d\">", i);
439 wprintf("<div style=\"display:none\">");
440 wprintf("<input type=\"checkbox\" id=\"active%d\">", i);
443 wprintf("%d. %s</td>", i+1, _("If") );
446 wprintf("<select name=\"hfield%d\" size=1 onChange=\"UpdateRules();\">", i);
447 wprintf("<option value=\"sender\">%s</option>", _("Sender"));
448 wprintf("<option value=\"recipient\">%s</option>", _("Recipient"));
449 wprintf("</select>");
453 wprintf("<select name=\"compare%d\" size=1 onChange=\"UpdateRules();\">", i);
454 wprintf("<option value=\"match\">%s</option>", _("matches"));
455 wprintf("<option value=\"notmatch\">%s</option>", _("does not match"));
456 wprintf("</select>");
458 wprintf("<input type=\"text\" name=\"htext%d\">", i);
462 wprintf("<select id=\"action%d\" name=\"action%d\" size=1 onChange=\"UpdateRules();\">",
464 wprintf("<option value=\"fileinto\">%s</option>", _("file into"));
465 wprintf("<option value=\"redirect\">%s</option>", _("forward to"));
466 wprintf("<option value=\"reject\">%s</option>", _("reject"));
467 wprintf("</select>");
469 wprintf("<div id=\"div_fileinto%d\">", i);
470 wprintf("<select name=\"fileinto%d\">", i);
471 serv_puts("LKRA"); /* FIXME buffer this and keep reusing it */
472 serv_getln(buf, sizeof buf);
474 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
475 extract_token(targ, buf, 0, '|', sizeof targ);
476 if (!strcasecmp(targ, "Mail")) {
477 wprintf("<option selected>");
486 wprintf("</select>\n");
489 wprintf("<div id=\"div_redirect%d\">", i);
490 wprintf("<input type=\"text\" name=\"redirect%d\">", i);
496 wprintf("<td>%s</td>", _("and then") );
499 wprintf("<select name=\"final%d\" size=1 onChange=\"UpdateRules();\">", i);
500 wprintf("<option value=\"stop\">%s</option>", _("stop"));
501 wprintf("<option value=\"continue\">%s</option>", _("continue processing"));
502 wprintf("</select>");
510 wprintf("<a href=\"javascript:AddRule();\">Add rule</a>\n");
513 wprintf("<script type=\"text/javascript\"> \n"