3 #define MAX_SCRIPTS 100
5 #define RULES_SCRIPT "__WebCit_Generated_Script__"
9 * dummy panel indicating to the user that the server doesn't support Sieve
11 void display_no_sieve(void) {
13 output_headers(1, 1, 2, 0, 0, 0);
15 wc_printf("<div id=\"banner\">\n");
16 wc_printf("<img src=\"static/advanpage2_48x.gif\">");
18 wc_printf(_("View/edit server-side mail filters"));
20 wc_printf("</div>\n");
22 wc_printf("<div id=\"content\" class=\"service\">\n");
24 wc_printf("<table class=\"sieve_background\">"
25 "<tr><td valign=top>\n");
27 wc_printf(_("This installation of Citadel was built without support for server-side mail filtering."
28 "<br>Please contact your system administrator if you require this feature.<br>"));
30 wc_printf("</td></tr></table>\n");
36 * view/edit sieve config
38 void display_sieve(void)
40 char script_names[MAX_SCRIPTS][64];
42 int active_script = (-1);
43 char buf[SIZ]; /* Don't make this buffer smaller or it will restrict line length */
45 int rules_script_is_active = 0;
47 if (!WC->serv_info->serv_supports_sieve) {
52 memset(script_names, 0, sizeof script_names);
54 serv_puts("MSIV listscripts");
55 serv_getln(buf, sizeof(buf));
56 if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
57 if (num_scripts < MAX_SCRIPTS) {
58 extract_token(script_names[num_scripts], buf, 0, '|', 64);
59 if (extract_int(buf, 1) > 0) {
60 active_script = num_scripts;
61 if (!strcasecmp(script_names[num_scripts], RULES_SCRIPT)) {
62 rules_script_is_active = 1;
69 output_headers(1, 1, 2, 0, 0, 0);
71 wc_printf("<script type=\"text/javascript\"> \n"
73 "var previously_active_script; \n"
75 "function ToggleSievePanels() { \n"
76 " d = ($('sieveform').bigaction.options[$('sieveform').bigaction.selectedIndex].value); \n"
77 " for (i=0; i<3; ++i) { \n"
79 " $('sievediv' + i).style.display = 'block'; \n"
82 " $('sievediv' + i).style.display = 'none'; \n"
87 "function ToggleScriptPanels() { \n"
88 " d = ($('sieveform').active_script.options[$('sieveform').active_script.selectedIndex].value); \n"
89 " if ($('script_' + previously_active_script)) { \n"
90 " $('script_' + previously_active_script).style.display = 'none'; \n"
92 " $('script_' + d).style.display = 'block'; \n"
93 " previously_active_script = d; \n"
99 wc_printf("<div id=\"banner\">\n");
100 wc_printf("<img src=\"static/advanpage2_48x.gif\">");
102 wc_printf(_("View/edit server-side mail filters"));
103 wc_printf("</h1>\n");
104 wc_printf("</div>\n");
106 wc_printf("<div id=\"content\" class=\"service\">\n");
108 wc_printf("<table class=\"sieve_background\">"
109 "<tr><td valign=top>\n");
112 wc_printf("<form id=\"sieveform\" method=\"post\" action=\"save_sieve\">\n");
113 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
115 wc_printf(_("When new mail arrives: "));
116 wc_printf("<select name=\"bigaction\" size=1 onChange=\"ToggleSievePanels();\">\n");
118 wc_printf("<option %s value=\"0\">", ((active_script < 0) ? "selected" : ""));
119 wc_printf(_("Leave it in my inbox without filtering"));
120 wc_printf("</option>\n");
122 wc_printf("<option %s value=\"1\">", ((rules_script_is_active) ? "selected" : ""));
123 wc_printf(_("Filter it according to rules selected below"));
124 wc_printf("</option>\n");
126 wc_printf("<option %s value=\"2\">",
127 (((active_script >= 0) && (!rules_script_is_active)) ? "selected" : ""));
128 wc_printf(_("Filter it through a manually edited script (advanced users only)"));
129 wc_printf("</option>\n");
131 wc_printf("</select>");
135 /* The "no filtering" div */
137 wc_printf("<div id=\"sievediv0\" style=\"display:none\">\n");
138 wc_printf("<div align=\"center\"><br /><br />");
139 wc_printf(_("Your incoming mail will not be filtered through any scripts."));
140 wc_printf("<br /><br /></div>\n");
141 wc_printf("</div>\n");
143 /* The "webcit managed scripts" div */
145 wc_printf("<div id=\"sievediv1\" style=\"display:none\">\n");
146 display_rules_editor_inner_div();
147 wc_printf("</div>\n");
149 /* The "I'm smart and can write my own Sieve scripts" div */
151 wc_printf("<div id=\"sievediv2\" style=\"display:none\">\n");
153 if (num_scripts > 0) {
154 wc_printf(_("The currently active script is: "));
155 wc_printf("<select name=\"active_script\" size=1 onChange=\"ToggleScriptPanels();\">\n");
156 for (i=0; i<num_scripts; ++i) {
157 if (strcasecmp(script_names[i], RULES_SCRIPT)) {
158 wc_printf("<option %s value=\"%s\">%s</option>\n",
159 ((active_script == i) ? "selected" : ""),
165 wc_printf("</select>\n");
168 wc_printf(" ");
169 wc_printf("<a href=\"display_add_remove_scripts\">%s</a>\n", _("Add or delete scripts"));
171 wc_printf("<br />\n");
173 if (num_scripts > 0) {
174 for (i=0; i<num_scripts; ++i) {
175 if (strcasecmp(script_names[i], RULES_SCRIPT)) {
176 wc_printf("<div id=\"script_%s\" style=\"display:none\">\n", script_names[i]);
177 wc_printf("<textarea name=\"text_%s\" wrap=soft rows=20 cols=80 width=80>\n",
179 serv_printf("MSIV getscript|%s", script_names[i]);
180 serv_getln(buf, sizeof buf);
181 if (buf[0] == '1') while(serv_getln(buf, sizeof (buf)), strcmp(buf, "000")) {
182 wc_printf("%s\n", buf);
184 wc_printf("</textarea>\n");
185 wc_printf("</div>\n");
190 wc_printf("<script type=\"text/javascript\"> \n"
191 "ToggleScriptPanels(); \n"
195 wc_printf("</div>\n");
198 /* The rest of this is common for all panels... */
200 wc_printf("<div align=\"center\"><br>");
201 wc_printf("<input type=\"submit\" name=\"save_button\" value=\"%s\">", _("Save changes"));
203 wc_printf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
204 wc_printf("</div></form>\n");
206 wc_printf("</td></tr></table>\n");
208 wc_printf("<script type=\"text/javascript\"> \n"
209 "ToggleSievePanels(); \n"
220 * Helper function for output_sieve_rule() to output strings with quotes escaped
222 void osr_sanitize(char *str) {
225 if (str == NULL) return;
227 for (i=0; i<len; ++i) {
231 else if (isspace(str[i])) {
239 * Output parseable Sieve script code based on rules input
241 void output_sieve_rule(char *hfield, char *compare, char *htext, char *sizecomp, int sizeval,
242 char *action, char *fileinto, char *redirect, char *automsg, char *final,
249 osr_sanitize(fileinto);
250 osr_sanitize(redirect);
251 osr_sanitize(automsg);
253 /* Prepare negation and match operators that will be used iff we apply a conditional */
255 if (!strcasecmp(compare, "contains")) {
259 else if (!strcasecmp(compare, "notcontains")) {
263 else if (!strcasecmp(compare, "is")) {
267 else if (!strcasecmp(compare, "isnot")) {
271 else if (!strcasecmp(compare, "matches")) {
275 else if (!strcasecmp(compare, "notmatches")) {
280 /* Now do the conditional */
282 if (!strcasecmp(hfield, "from")) {
283 serv_printf("if%s header %s \"From\" \"%s\"",
289 else if (!strcasecmp(hfield, "tocc")) {
290 serv_printf("if%s header %s [\"To\", \"Cc\"] \"%s\"",
296 else if (!strcasecmp(hfield, "subject")) {
297 serv_printf("if%s header %s \"Subject\" \"%s\"",
303 else if (!strcasecmp(hfield, "replyto")) {
304 serv_printf("if%s header %s \"Reply-to\" \"%s\"",
310 else if (!strcasecmp(hfield, "sender")) {
311 serv_printf("if%s header %s \"Sender\" \"%s\"",
317 else if (!strcasecmp(hfield, "resentfrom")) {
318 serv_printf("if%s header %s \"Resent-from\" \"%s\"",
324 else if (!strcasecmp(hfield, "resentto")) {
325 serv_printf("if%s header %s \"Resent-to\" \"%s\"",
331 else if (!strcasecmp(hfield, "xmailer")) {
332 serv_printf("if%s header %s \"X-Mailer\" \"%s\"",
338 else if (!strcasecmp(hfield, "xspamflag")) {
339 serv_printf("if%s header %s \"X-Spam-Flag\" \"%s\"",
345 else if (!strcasecmp(hfield, "xspamstatus")) {
346 serv_printf("if%s header %s \"X-Spam-Status\" \"%s\"",
352 else if (!strcasecmp(hfield, "listid")) {
353 serv_printf("if%s header %s \"List-ID\" \"%s\"",
359 else if (!strcasecmp(hfield, "envfrom")) {
360 serv_printf("if%s envelope %s \"From\" \"%s\"",
366 else if (!strcasecmp(hfield, "envto")) {
367 serv_printf("if%s envelope %s \"To\" \"%s\"",
373 else if (!strcasecmp(hfield, "size")) {
374 if (!strcasecmp(sizecomp, "larger")) {
375 serv_printf("if size :over %d", sizeval);
377 else if (!strcasecmp(sizecomp, "smaller")) {
378 serv_printf("if size :under %d", sizeval);
380 else { /* failsafe - should never get here, but just in case... */
381 serv_printf("if size :over 1");
385 /* Open braces if we're in a conditional loop */
387 if (strcasecmp(hfield, "all")) {
394 if (!strcasecmp(action, "keep")) {
395 serv_printf("keep;");
398 else if (!strcasecmp(action, "discard")) {
399 serv_printf("discard;");
402 else if (!strcasecmp(action, "reject")) {
403 serv_printf("reject \"%s\";", automsg);
406 else if (!strcasecmp(action, "fileinto")) {
407 serv_printf("fileinto \"%s\";", fileinto);
410 else if (!strcasecmp(action, "redirect")) {
411 serv_printf("redirect \"%s\";", redirect);
414 else if (!strcasecmp(action, "vacation")) {
415 serv_printf("vacation :addresses [%s]\n\"%s\";", my_addresses, automsg);
419 /* Do 'final' action */
421 if (!strcasecmp(final, "stop")) {
422 serv_printf("stop;");
426 /* Close the braces if we're in a conditional loop */
428 if (strcasecmp(hfield, "all")) {
439 * Translate the fields from the rule editor into something we can save...
441 void parse_fields_from_rule_editor(void) {
458 char encoded_rule[4096];
459 char my_addresses[4096];
461 /* Enumerate my email addresses in case they are needed for a vacation rule */
464 serv_getln(buf, sizeof buf);
465 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
466 if (!IsEmptyStr(my_addresses)) {
467 strcat(my_addresses, ",\n");
469 strcat(my_addresses, "\"");
470 strcat(my_addresses, buf);
471 strcat(my_addresses, "\"");
474 /* Now generate the script and write it to the Citadel server */
475 serv_printf("MSIV putscript|%s|", RULES_SCRIPT);
476 serv_getln(buf, sizeof buf);
481 serv_puts("# THIS SCRIPT WAS AUTOMATICALLY GENERATED BY WEBCIT.");
483 serv_puts("# Do not attempt to manually edit it. If you do so,");
484 serv_puts("# your changes will be overwritten the next time WebCit");
485 serv_puts("# saves its mail filtering rule set. If you really want");
486 serv_puts("# to use these rules as the basis for another script,");
487 serv_puts("# copy them to another script and save that instead.");
489 serv_puts("require \"fileinto\";");
490 serv_puts("require \"reject\";");
491 serv_puts("require \"vacation\";");
492 serv_puts("require \"envelope\";");
495 for (i=0; i<MAX_RULES; ++i) {
499 sprintf(fname, "active%d", i);
500 active = !strcasecmp(BSTR(fname), "on") ;
504 sprintf(fname, "hfield%d", i);
505 safestrncpy(hfield, BSTR(fname), sizeof hfield);
507 sprintf(fname, "compare%d", i);
508 safestrncpy(compare, BSTR(fname), sizeof compare);
510 sprintf(fname, "htext%d", i);
511 safestrncpy(htext, BSTR(fname), sizeof htext);
513 sprintf(fname, "sizecomp%d", i);
514 safestrncpy(sizecomp, BSTR(fname), sizeof sizecomp);
516 sprintf(fname, "sizeval%d", i);
517 sizeval = IBSTR(fname);
519 sprintf(fname, "action%d", i);
520 safestrncpy(action, BSTR(fname), sizeof action);
522 sprintf(fname, "fileinto%d", i);
523 safestrncpy(fileinto, BSTR(fname), sizeof fileinto);
525 sprintf(fname, "redirect%d", i);
526 safestrncpy(redirect, BSTR(fname), sizeof redirect);
528 sprintf(fname, "automsg%d", i);
529 safestrncpy(automsg, BSTR(fname), sizeof automsg);
531 sprintf(fname, "final%d", i);
532 safestrncpy(final, BSTR(fname), sizeof final);
534 snprintf(rule, sizeof rule, "%d|%s|%s|%s|%s|%d|%s|%s|%s|%s|%s",
535 active, hfield, compare, htext, sizecomp, sizeval, action, fileinto,
536 redirect, automsg, final
539 CtdlEncodeBase64(encoded_rule, rule, strlen(rule)+1, 0);
540 serv_printf("# WEBCIT_RULE|%d|%s|", i, encoded_rule);
541 output_sieve_rule(hfield, compare, htext, sizecomp, sizeval,
542 action, fileinto, redirect, automsg, final, my_addresses);
558 void save_sieve(void) {
560 char script_names[MAX_SCRIPTS][64];
562 int active_script = (-1);
567 if (!havebstr("save_button")) {
568 strcpy(WC->ImportantMessage,
569 _("Cancelled. Changes were not saved."));
574 parse_fields_from_rule_editor();
576 serv_puts("MSIV listscripts");
577 serv_getln(buf, sizeof(buf));
578 if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
579 if (num_scripts < MAX_SCRIPTS) {
580 extract_token(script_names[num_scripts], buf, 0, '|', 64);
581 if (extract_int(buf, 1) > 0) {
582 active_script = num_scripts;
588 bigaction = ibstr("bigaction");
590 if (bigaction == 0) {
591 serv_puts("MSIV setactive||");
592 serv_getln(buf, sizeof buf);
595 else if (bigaction == 1) {
596 serv_printf("MSIV setactive|%s|", RULES_SCRIPT);
597 serv_getln(buf, sizeof buf);
600 else if (bigaction == 2) {
601 serv_printf("MSIV setactive|%s|", bstr("active_script"));
602 serv_getln(buf, sizeof buf);
605 if (num_scripts > 0) {
606 for (i=0; i<num_scripts; ++i) {
608 * We only want to save the scripts from the "manually edited scripts"
609 * screen. The script that WebCit generates from its ruleset will be
610 * auto-generated by parse_fields_from_rule_editor() and saved there.
612 if (strcasecmp(script_names[i], RULES_SCRIPT)) {
613 serv_printf("MSIV putscript|%s|", script_names[i]);
614 serv_getln(buf, sizeof buf);
616 snprintf(this_name, sizeof this_name, "text_%s", script_names[i]);
617 striplt((char *)BSTR(this_name)); /* TODO: get rid of typecast*/
618 serv_write(BSTR(this_name), strlen(BSTR(this_name)));
625 strcpy(WC->ImportantMessage, _("Your changes have been saved."));
632 * show a list of available scripts to add/remove them
634 void display_add_remove_scripts(char *message)
637 char script_name[256];
639 output_headers(1, 1, 2, 0, 0, 0);
640 wc_printf("<div id=\"banner\">\n");
641 wc_printf("<img src=\"static/advanpage2_48x.gif\">");
642 wc_printf(_("Add or delete scripts"));
643 wc_printf("</h1>\n");
644 wc_printf("</div>\n");
646 wc_printf("<div id=\"content\" class=\"service\">\n");
648 if (message != NULL) {
649 wc_printf("%s", message);
652 wc_printf("<table border=0 cellspacing=10><tr valign=top><td>\n");
654 do_template("beginbox_1", NULL);
655 StrBufAppendBufPlain(WC->WBuf, _("Add a new script"), -1, 0);
656 do_template("beginbox_2", NULL);
658 wc_printf(_("To create a new script, enter the desired "
659 "script name in the box below and click 'Create'."));
660 wc_printf("<br /><br />");
662 wc_printf("<center><form method=\"POST\" action=\"create_script\">\n");
663 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
664 wc_printf(_("Script name: "));
665 wc_printf("<input type=\"text\" name=\"script_name\"><br />\n"
666 "<input type=\"submit\" name=\"create_button\" value=\"%s\">"
667 "</form></center>\n", _("Create"));
669 do_template("endbox", NULL);
671 do_template("beginbox_1", NULL);
672 StrBufAppendBufPlain(WC->WBuf, _("Edit scripts"), -1, 0);
673 do_template("beginbox_2", NULL);
674 wc_printf("<br /><div align=center><a href=\"display_sieve\">%s</a><br /><br />\n",
675 _("Return to the script editing screen")
677 do_template("endbox", NULL);
679 wc_printf("</td><td>");
681 do_template("beginbox_1", NULL);
682 StrBufAppendBufPlain(WC->WBuf, _("Delete scripts"), -1, 0);
683 do_template("beginbox_2", NULL);
685 wc_printf(_("To delete an existing script, select the script "
686 "name from the list and click 'Delete'."));
687 wc_printf("<br /><br />");
690 "<form method=\"POST\" action=\"delete_script\">\n");
691 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
692 wc_printf("<select name=\"script_name\" size=10 style=\"width:100%%\">\n");
694 serv_puts("MSIV listscripts");
695 serv_getln(buf, sizeof buf);
697 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
698 extract_token(script_name, buf, 0, '|', sizeof script_name);
699 if ( (extract_int(buf, 1) == 0) && (strcasecmp(script_name, RULES_SCRIPT)) ) {
700 wc_printf("<option>");
701 escputs(script_name);
702 wc_printf("</option>\n");
706 wc_printf("</select><br />\n");
708 wc_printf("<input type=\"submit\" name=\"delete_button\" value=\"%s\" "
709 "onClick=\"return confirm('%s');\">", _("Delete script"), _("Delete this script?"));
710 wc_printf("</form></center>\n");
711 do_template("endbox", NULL);
713 wc_printf("</td></tr></table>\n");
723 void delete_script(void) {
726 serv_printf("MSIV deletescript|%s", bstr("script_name"));
727 serv_getln(buf, sizeof buf);
728 display_add_remove_scripts(&buf[4]);
734 * create a new script
735 * take the web environment script name and create it on the citadel server
737 void create_script(void) {
740 serv_printf("MSIV getscript|%s", bstr("script_name"));
741 serv_getln(buf, sizeof buf);
743 while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
746 display_add_remove_scripts(_("A script by that name already exists."));
750 serv_printf("MSIV putscript|%s", bstr("script_name"));
751 serv_getln(buf, sizeof buf);
755 display_add_remove_scripts(_("A new script has been created. Return to the script editing screen to edit and activate it."));
759 display_add_remove_scripts(&buf[4]);
765 void display_rules_editor_inner_div(void) {
768 char rules[MAX_RULES][2048];
773 int num_roomnames = 0;
774 int num_roomnames_alloc = 0;
789 memset(rules, 0, sizeof rules);
790 serv_printf("MSIV getscript|%s", RULES_SCRIPT);
791 serv_getln(buf, sizeof buf);
792 if (buf[0] == '1') while(serv_getln(buf, sizeof (buf)), strcmp(buf, "000")) {
793 if (!strncasecmp(buf, "# WEBCIT_RULE|", 14)) {
794 j = extract_int(buf, 1);
795 remove_token(buf, 0, '|');
796 remove_token(buf, 0, '|');
797 CtdlDecodeBase64(rules[j], buf, strlen(buf));
801 /* load the roomnames */
803 serv_getln(buf, sizeof buf);
805 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
807 if (num_roomnames > num_roomnames_alloc) {
808 num_roomnames_alloc += 250;
809 rooms = realloc(rooms, (num_roomnames_alloc * 128));
811 extract_token(rooms[num_roomnames-1].name, buf, 0, '|', 128);
817 * This script should get called by every onChange event...
820 wc_printf("<script type=\"text/javascript\"> \n"
822 "var highest_active_rule = (-1); \n"
824 "function UpdateRules() { \n");
826 * Show only the active rows...
828 wc_printf(" highest_active_rule = (-1); \n");
829 wc_printf(" for (i=0; i<%d; ++i) { \n", MAX_RULES);
830 wc_printf(" if ($('active'+i).checked) { \n"
831 " $('rule' + i).style.display = 'block'; \n"
832 " highest_active_rule = i; \n"
835 " $('rule' + i).style.display = 'none'; \n"
839 * Show only the fields relevant to the rules...
841 wc_printf(" for (i=0; i<=highest_active_rule; ++i) { \n"
842 " d = ($('movedown'+i)); \n"
843 " if (i < highest_active_rule) { \n"
844 " d.style.display = 'block'; \n"
847 " d.style.display = 'none'; \n"
849 " d = ($('hfield'+i).options[$('hfield'+i).selectedIndex].value); \n"
850 " if (d == 'all') { \n"
851 " $('div_size'+i).style.display = 'none'; \n"
852 " $('div_compare'+i).style.display = 'none'; \n"
853 " $('div_nocompare'+i).style.display = 'block'; \n"
855 " else if (d == 'size') { \n"
856 " $('div_size'+i).style.display = 'block'; \n"
857 " $('div_compare'+i).style.display = 'none'; \n"
858 " $('div_nocompare'+i).style.display = 'none'; \n"
861 " $('div_size'+i).style.display = 'none'; \n"
862 " $('div_compare'+i).style.display = 'block'; \n"
863 " $('div_nocompare'+i).style.display = 'none'; \n"
865 " d = ($('action'+i).options[$('action'+i).selectedIndex].value); \n"
866 " if (d == 'fileinto') { \n"
867 " $('div_fileinto'+i).style.display = 'block'; \n"
868 " $('div_redirect'+i).style.display = 'none'; \n"
869 " $('div_automsg'+i).style.display = 'none'; \n"
870 " } else if (d == 'redirect') { \n"
871 " $('div_fileinto'+i).style.display = 'none'; \n"
872 " $('div_redirect'+i).style.display = 'block'; \n"
873 " $('div_automsg'+i).style.display = 'none'; \n"
874 " } else if ((d == 'reject') || (d == 'vacation')) { \n"
875 " $('div_fileinto'+i).style.display = 'none'; \n"
876 " $('div_redirect'+i).style.display = 'none'; \n"
877 " $('div_automsg'+i).style.display = 'block'; \n"
879 " $('div_fileinto'+i).style.display = 'none'; \n"
880 " $('div_redirect'+i).style.display = 'none'; \n"
881 " $('div_automsg'+i).style.display = 'none'; \n"
883 " if (highest_active_rule < %d) { \n", MAX_RULES-1 );
884 wc_printf(" $('div_addrule').style.display = 'block'; \n"
886 " $('div_addrule').style.display = 'none'; \n"
891 * Add a rule (really, just un-hide it)
893 "function AddRule() { \n"
894 " highest_active_rule = highest_active_rule + 1; \n"
895 " $('active'+highest_active_rule).checked = true; \n"
901 "function SwapRules(ra, rb) { \n"
903 " var things = new Array(); \n"
904 " things[0] = 'hfield'; \n"
905 " things[1] = 'compare'; \n"
906 " things[2] = 'htext'; \n"
907 " things[3] = 'action'; \n"
908 " things[4] = 'fileinto'; \n"
909 " things[5] = 'redirect'; \n"
910 " things[6] = 'final'; \n"
911 " things[7] = 'sizecomp'; \n"
912 " things[8] = 'sizeval'; \n"
913 " things[9] = 'automsg'; \n"
915 " for (i=0; i<=9; ++i) { \n"
916 " tempval=$(things[i]+ra).value; \n"
917 " $(things[i]+ra).value = $(things[i]+rb).value; \n"
918 " $(things[i]+rb).value = tempval; \n"
922 * Delete a rule (percolate the deleted rule out to the end, then deactivate it)
924 "function DeleteRule(rd) { \n"
925 " for (j=rd; j<=highest_active_rule; ++j) { \n"
926 " SwapRules(j, (j+1)); \n"
928 " $('active'+highest_active_rule).checked = false; \n"
936 wc_printf("<table cellpadding=2 width=100%%>");
938 for (i=0; i<MAX_RULES; ++i) {
940 /* Grab our existing values to populate */
941 active = extract_int(rules[i], 0);
942 extract_token(hfield, rules[i], 1, '|', sizeof hfield);
943 extract_token(compare, rules[i], 2, '|', sizeof compare);
944 extract_token(htext, rules[i], 3, '|', sizeof htext);
945 extract_token(sizecomp, rules[i], 4, '|', sizeof sizecomp);
946 sizeval = extract_int(rules[i], 5);
947 extract_token(action, rules[i], 6, '|', sizeof action);
948 extract_token(fileinto, rules[i], 7, '|', sizeof fileinto);
949 extract_token(redirect, rules[i], 8, '|', sizeof redirect);
950 extract_token(automsg, rules[i], 9, '|', sizeof automsg);
951 extract_token(final, rules[i], 10, '|', sizeof final);
953 /* now generate the table row */
955 wc_printf("<tr id=\"rule%d\" bgcolor=\"#%s\">",
957 ((i%2) ? "DDDDDD" : "FFFFFF")
960 wc_printf("<td width=5%% align=\"center\">");
962 wc_printf("<div style=\"display:none\">");
963 wc_printf("<input type=\"checkbox\" name=\"active%d\" id=\"active%d\" %s>",
965 (active ? "checked" : "")
969 if (i>0) wc_printf("<a href=\"javascript:SwapRules(%d,%d);UpdateRules();\">"
970 "<img border=\"0\" src=\"static/up_pointer.gif\" "
971 "title=\"%s\"/></a>",
972 i-1, i, _("Move rule up") );
974 wc_printf("<a href=\"javascript:SwapRules(%d,%d);UpdateRules();\">"
975 "<img id=\"movedown%d\" border=\"0\" src=\"static/down_pointer.gif\" "
976 "title=\"%s\"/></a>",
977 i, i+1, i, _("Move rule down") );
979 wc_printf("<a href=\"javascript:DeleteRule(%d);UpdateRules();\">"
980 "<img id=\"delete%d\" border=\"0\" src=\"static/delete.gif\" "
981 "title=\"%s\"/></a>",
982 i, i, _("Delete rule") );
986 wc_printf("<td width=5%% align=\"center\">");
987 wc_printf("<font size=+2>%d</font>", i+1);
990 wc_printf("<td width=20%%>%s ", _("If") );
992 char *hfield_values[15][2] = {
993 { "from", _("From") },
994 { "tocc", _("To or Cc") },
995 { "subject", _("Subject") },
996 { "replyto", _("Reply-to") },
997 { "sender", _("Sender") },
998 { "resentfrom", _("Resent-From") },
999 { "resentto", _("Resent-To") },
1000 { "envfrom", _("Envelope From") },
1001 { "envto", _("Envelope To") },
1002 { "xmailer", _("X-Mailer") },
1003 { "xspamflag", _("X-Spam-Flag") },
1004 { "xspamstatus", _("X-Spam-Status") },
1005 { "listid", _("List-ID") },
1006 { "size", _("Message size") },
1010 wc_printf("<select id=\"hfield%d\" name=\"hfield%d\" size=1 onChange=\"UpdateRules();\">",
1012 for (j=0; j<15; ++j) {
1013 wc_printf("<option %s value=\"%s\">%s</option>",
1014 ( (!strcasecmp(hfield, hfield_values[j][0])) ? "selected" : ""),
1015 hfield_values[j][0],
1020 wc_printf("</select>");
1023 wc_printf("<td width=20%%>");
1025 char *compare_values[6][2] = {
1026 { "contains", _("contains") },
1027 { "notcontains", _("does not contain") },
1029 { "isnot", _("is not") },
1030 { "matches", _("matches") },
1031 { "notmatches", _("does not match") }
1034 wc_printf("<div id=\"div_compare%d\">", i);
1035 wc_printf("<select id=\"compare%d\" name=\"compare%d\" size=1 onChange=\"UpdateRules();\">",
1037 for (j=0; j<6; ++j) {
1038 wc_printf("<option %s value=\"%s\">%s</option>",
1039 ( (!strcasecmp(compare, compare_values[j][0])) ? "selected" : ""),
1040 compare_values[j][0],
1041 compare_values[j][1]
1044 wc_printf("</select>");
1046 wc_printf("<input type=\"text\" id=\"htext%d\" name=\"htext%d\" value=\"", i, i);
1048 wc_printf("\"></div>");
1050 wc_printf("<div id=\"div_nocompare%d\">", i);
1051 wc_printf("%s", _("(All messages)"));
1052 wc_printf("</div>");
1054 char *sizecomp_values[2][2] = {
1055 { "larger", _("is larger than") },
1056 { "smaller", _("is smaller than") }
1059 wc_printf("<div id=\"div_size%d\">", i);
1060 wc_printf("<select id=\"sizecomp%d\" name=\"sizecomp%d\" size=1 onChange=\"UpdateRules();\">",
1062 for (j=0; j<2; ++j) {
1063 wc_printf("<option %s value=\"%s\">%s</option>",
1064 ( (!strcasecmp(sizecomp, sizecomp_values[j][0])) ? "selected" : ""),
1065 sizecomp_values[j][0],
1066 sizecomp_values[j][1]
1069 wc_printf("</select>");
1071 wc_printf("<input type=\"text\" id=\"sizeval%d\" name=\"sizeval%d\" value=\"%d\">",
1074 wc_printf("</div>");
1078 char *action_values[6][2] = {
1079 { "keep", _("Keep") },
1080 { "discard", _("Discard silently") },
1081 { "reject", _("Reject") },
1082 { "fileinto", _("Move message to") },
1083 { "redirect", _("Forward to") },
1084 { "vacation", _("Vacation") }
1087 wc_printf("<td width=20%%>");
1088 wc_printf("<select id=\"action%d\" name=\"action%d\" size=1 onChange=\"UpdateRules();\">",
1090 for (j=0; j<6; ++j) {
1091 wc_printf("<option %s value=\"%s\">%s</option>",
1092 ( (!strcasecmp(action, action_values[j][0])) ? "selected" : ""),
1093 action_values[j][0],
1097 wc_printf("</select>");
1099 wc_printf("<div id=\"div_fileinto%d\">", i);
1100 wc_printf("<select name=\"fileinto%d\" id=\"fileinto%d\">", i, i);
1101 for (j=0; j<num_roomnames; ++j) {
1102 wc_printf("<option ");
1103 if (!strcasecmp(rooms[j].name, fileinto)) {
1104 wc_printf("selected ");
1106 wc_printf("value=\"");
1107 escputs(rooms[j].name);
1109 escputs(rooms[j].name);
1110 wc_printf("</option>\n");
1112 wc_printf("</select>\n");
1113 wc_printf("</div>");
1115 wc_printf("<div id=\"div_redirect%d\">", i);
1116 wc_printf("<input type=\"text\" id=\"redirect%d\" name=\"redirect%d\" value=\"", i, i);
1118 wc_printf("\"></div>");
1120 wc_printf("<div id=\"div_automsg%d\">", i);
1121 wc_printf(_("Message:"));
1122 wc_printf("<br />");
1123 wc_printf("<textarea name=\"automsg%d\" id=\"automsg%d\" wrap=soft rows=5>\n", i, i);
1125 wc_printf("</textarea>");
1126 wc_printf("</div>");
1130 char *final_values[2][2] = {
1131 { "continue", _("continue processing") },
1132 { "stop", _("stop") }
1135 wc_printf("<td width=10%% align=\"center\">%s</td>", _("and then") );
1137 wc_printf("<td width=20%%>");
1138 wc_printf("<select name=\"final%d\" id=\"final%d\" size=1 onChange=\"UpdateRules();\">",
1140 for (j=0; j<2; ++j) {
1141 wc_printf("<option %s value=\"%s\">%s</option>",
1142 ( (!strcasecmp(final, final_values[j][0])) ? "selected" : ""),
1147 wc_printf("</select>");
1150 wc_printf("</tr>\n");
1154 wc_printf("</table>");
1155 wc_printf("<div id=\"div_addrule\"><a href=\"javascript:AddRule();\">%s</a><br /></div>\n",
1159 wc_printf("<script type=\"text/javascript\"> \n");
1160 wc_printf("UpdateRules(); \n");
1161 wc_printf("</script> \n");
1166 void _display_add_remove_scripts(void) {display_add_remove_scripts(NULL);}
1172 WebcitAddUrlHandler(HKEY("display_sieve"), "", 0, display_sieve, 0);
1173 WebcitAddUrlHandler(HKEY("save_sieve"), "", 0, save_sieve, 0);
1174 WebcitAddUrlHandler(HKEY("display_add_remove_scripts"), "", 0, _display_add_remove_scripts, 0);
1175 WebcitAddUrlHandler(HKEY("create_script"), "", 0, create_script, 0);
1176 WebcitAddUrlHandler(HKEY("delete_script"), "", 0, delete_script, 0);