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("<div class=\"fix_scrollbar_bug\">"
25 "<table class=\"sieve_background\">"
26 "<tr><td valign=top>\n");
28 wc_printf(_("This installation of Citadel was built without support for server-side mail filtering."
29 "<br>Please contact your system administrator if you require this feature.<br>"));
31 wc_printf("</td></tr></table></div>\n");
37 * view/edit sieve config
39 void display_sieve(void)
41 char script_names[MAX_SCRIPTS][64];
43 int active_script = (-1);
44 char buf[SIZ]; /* Don't make this buffer smaller or it will restrict line length */
46 int rules_script_is_active = 0;
48 if (!WC->serv_info->serv_supports_sieve) {
53 memset(script_names, 0, sizeof script_names);
55 serv_puts("MSIV listscripts");
56 serv_getln(buf, sizeof(buf));
57 if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
58 if (num_scripts < MAX_SCRIPTS) {
59 extract_token(script_names[num_scripts], buf, 0, '|', 64);
60 if (extract_int(buf, 1) > 0) {
61 active_script = num_scripts;
62 if (!strcasecmp(script_names[num_scripts], RULES_SCRIPT)) {
63 rules_script_is_active = 1;
70 output_headers(1, 1, 2, 0, 0, 0);
72 wc_printf("<script type=\"text/javascript\"> \n"
74 "var previously_active_script; \n"
76 "function ToggleSievePanels() { \n"
77 " d = ($('sieveform').bigaction.options[$('sieveform').bigaction.selectedIndex].value); \n"
78 " for (i=0; i<3; ++i) { \n"
80 " $('sievediv' + i).style.display = 'block'; \n"
83 " $('sievediv' + i).style.display = 'none'; \n"
88 "function ToggleScriptPanels() { \n"
89 " d = ($('sieveform').active_script.options[$('sieveform').active_script.selectedIndex].value); \n"
90 " if ($('script_' + previously_active_script)) { \n"
91 " $('script_' + previously_active_script).style.display = 'none'; \n"
93 " $('script_' + d).style.display = 'block'; \n"
94 " previously_active_script = d; \n"
100 wc_printf("<div id=\"banner\">\n");
101 wc_printf("<img src=\"static/advanpage2_48x.gif\">");
103 wc_printf(_("View/edit server-side mail filters"));
104 wc_printf("</h1>\n");
105 wc_printf("</div>\n");
107 wc_printf("<div id=\"content\" class=\"service\">\n");
109 wc_printf("<div class=\"fix_scrollbar_bug\">"
110 "<table class=\"sieve_background\">"
111 "<tr><td valign=top>\n");
114 wc_printf("<form id=\"sieveform\" method=\"post\" action=\"save_sieve\">\n");
115 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
117 wc_printf(_("When new mail arrives: "));
118 wc_printf("<select name=\"bigaction\" size=1 onChange=\"ToggleSievePanels();\">\n");
120 wc_printf("<option %s value=\"0\">", ((active_script < 0) ? "selected" : ""));
121 wc_printf(_("Leave it in my inbox without filtering"));
122 wc_printf("</option>\n");
124 wc_printf("<option %s value=\"1\">", ((rules_script_is_active) ? "selected" : ""));
125 wc_printf(_("Filter it according to rules selected below"));
126 wc_printf("</option>\n");
128 wc_printf("<option %s value=\"2\">",
129 (((active_script >= 0) && (!rules_script_is_active)) ? "selected" : ""));
130 wc_printf(_("Filter it through a manually edited script (advanced users only)"));
131 wc_printf("</option>\n");
133 wc_printf("</select>");
137 /* The "no filtering" div */
139 wc_printf("<div id=\"sievediv0\" style=\"display:none\">\n");
140 wc_printf("<div align=\"center\"><br /><br />");
141 wc_printf(_("Your incoming mail will not be filtered through any scripts."));
142 wc_printf("<br /><br /></div>\n");
143 wc_printf("</div>\n");
145 /* The "webcit managed scripts" div */
147 wc_printf("<div id=\"sievediv1\" style=\"display:none\">\n");
148 display_rules_editor_inner_div();
149 wc_printf("</div>\n");
151 /* The "I'm smart and can write my own Sieve scripts" div */
153 wc_printf("<div id=\"sievediv2\" style=\"display:none\">\n");
155 if (num_scripts > 0) {
156 wc_printf(_("The currently active script is: "));
157 wc_printf("<select name=\"active_script\" size=1 onChange=\"ToggleScriptPanels();\">\n");
158 for (i=0; i<num_scripts; ++i) {
159 if (strcasecmp(script_names[i], RULES_SCRIPT)) {
160 wc_printf("<option %s value=\"%s\">%s</option>\n",
161 ((active_script == i) ? "selected" : ""),
167 wc_printf("</select>\n");
170 wc_printf(" ");
171 wc_printf("<a href=\"display_add_remove_scripts\">%s</a>\n", _("Add or delete scripts"));
173 wc_printf("<br />\n");
175 if (num_scripts > 0) {
176 for (i=0; i<num_scripts; ++i) {
177 if (strcasecmp(script_names[i], RULES_SCRIPT)) {
178 wc_printf("<div id=\"script_%s\" style=\"display:none\">\n", script_names[i]);
179 wc_printf("<textarea name=\"text_%s\" wrap=soft rows=20 cols=80 width=80>\n",
181 serv_printf("MSIV getscript|%s", script_names[i]);
182 serv_getln(buf, sizeof buf);
183 if (buf[0] == '1') while(serv_getln(buf, sizeof (buf)), strcmp(buf, "000")) {
184 wc_printf("%s\n", buf);
186 wc_printf("</textarea>\n");
187 wc_printf("</div>\n");
192 wc_printf("<script type=\"text/javascript\"> \n"
193 "ToggleScriptPanels(); \n"
197 wc_printf("</div>\n");
200 /* The rest of this is common for all panels... */
202 wc_printf("<div align=\"center\"><br>");
203 wc_printf("<input type=\"submit\" name=\"save_button\" value=\"%s\">", _("Save changes"));
205 wc_printf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
206 wc_printf("</div></form>\n");
208 wc_printf("</td></tr></table></div>\n");
210 wc_printf("<script type=\"text/javascript\"> \n"
211 "ToggleSievePanels(); \n"
222 * Helper function for output_sieve_rule() to output strings with quotes escaped
224 void osr_sanitize(char *str) {
227 if (str == NULL) return;
229 for (i=0; i<len; ++i) {
233 else if (isspace(str[i])) {
241 * Output parseable Sieve script code based on rules input
243 void output_sieve_rule(char *hfield, char *compare, char *htext, char *sizecomp, int sizeval,
244 char *action, char *fileinto, char *redirect, char *automsg, char *final,
251 osr_sanitize(fileinto);
252 osr_sanitize(redirect);
253 osr_sanitize(automsg);
255 /* Prepare negation and match operators that will be used iff we apply a conditional */
257 if (!strcasecmp(compare, "contains")) {
261 else if (!strcasecmp(compare, "notcontains")) {
265 else if (!strcasecmp(compare, "is")) {
269 else if (!strcasecmp(compare, "isnot")) {
273 else if (!strcasecmp(compare, "matches")) {
277 else if (!strcasecmp(compare, "notmatches")) {
282 /* Now do the conditional */
284 if (!strcasecmp(hfield, "from")) {
285 serv_printf("if%s header %s \"From\" \"%s\"",
291 else if (!strcasecmp(hfield, "tocc")) {
292 serv_printf("if%s header %s [\"To\", \"Cc\"] \"%s\"",
298 else if (!strcasecmp(hfield, "subject")) {
299 serv_printf("if%s header %s \"Subject\" \"%s\"",
305 else if (!strcasecmp(hfield, "replyto")) {
306 serv_printf("if%s header %s \"Reply-to\" \"%s\"",
312 else if (!strcasecmp(hfield, "sender")) {
313 serv_printf("if%s header %s \"Sender\" \"%s\"",
319 else if (!strcasecmp(hfield, "resentfrom")) {
320 serv_printf("if%s header %s \"Resent-from\" \"%s\"",
326 else if (!strcasecmp(hfield, "resentto")) {
327 serv_printf("if%s header %s \"Resent-to\" \"%s\"",
333 else if (!strcasecmp(hfield, "xmailer")) {
334 serv_printf("if%s header %s \"X-Mailer\" \"%s\"",
340 else if (!strcasecmp(hfield, "xspamflag")) {
341 serv_printf("if%s header %s \"X-Spam-Flag\" \"%s\"",
347 else if (!strcasecmp(hfield, "xspamstatus")) {
348 serv_printf("if%s header %s \"X-Spam-Status\" \"%s\"",
354 else if (!strcasecmp(hfield, "listid")) {
355 serv_printf("if%s header %s \"List-ID\" \"%s\"",
361 else if (!strcasecmp(hfield, "envfrom")) {
362 serv_printf("if%s envelope %s \"From\" \"%s\"",
368 else if (!strcasecmp(hfield, "envto")) {
369 serv_printf("if%s envelope %s \"To\" \"%s\"",
375 else if (!strcasecmp(hfield, "size")) {
376 if (!strcasecmp(sizecomp, "larger")) {
377 serv_printf("if size :over %d", sizeval);
379 else if (!strcasecmp(sizecomp, "smaller")) {
380 serv_printf("if size :under %d", sizeval);
382 else { /* failsafe - should never get here, but just in case... */
383 serv_printf("if size :over 1");
387 /* Open braces if we're in a conditional loop */
389 if (strcasecmp(hfield, "all")) {
396 if (!strcasecmp(action, "keep")) {
397 serv_printf("keep;");
400 else if (!strcasecmp(action, "discard")) {
401 serv_printf("discard;");
404 else if (!strcasecmp(action, "reject")) {
405 serv_printf("reject \"%s\";", automsg);
408 else if (!strcasecmp(action, "fileinto")) {
409 serv_printf("fileinto \"%s\";", fileinto);
412 else if (!strcasecmp(action, "redirect")) {
413 serv_printf("redirect \"%s\";", redirect);
416 else if (!strcasecmp(action, "vacation")) {
417 serv_printf("vacation :addresses [%s]\n\"%s\";", my_addresses, automsg);
421 /* Do 'final' action */
423 if (!strcasecmp(final, "stop")) {
424 serv_printf("stop;");
428 /* Close the braces if we're in a conditional loop */
430 if (strcasecmp(hfield, "all")) {
441 * Translate the fields from the rule editor into something we can save...
443 void parse_fields_from_rule_editor(void) {
460 char encoded_rule[4096];
461 char my_addresses[4096];
463 /* Enumerate my email addresses in case they are needed for a vacation rule */
466 serv_getln(buf, sizeof buf);
467 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
468 if (!IsEmptyStr(my_addresses)) {
469 strcat(my_addresses, ",\n");
471 strcat(my_addresses, "\"");
472 strcat(my_addresses, buf);
473 strcat(my_addresses, "\"");
476 /* Now generate the script and write it to the Citadel server */
477 serv_printf("MSIV putscript|%s|", RULES_SCRIPT);
478 serv_getln(buf, sizeof buf);
483 serv_puts("# THIS SCRIPT WAS AUTOMATICALLY GENERATED BY WEBCIT.");
485 serv_puts("# Do not attempt to manually edit it. If you do so,");
486 serv_puts("# your changes will be overwritten the next time WebCit");
487 serv_puts("# saves its mail filtering rule set. If you really want");
488 serv_puts("# to use these rules as the basis for another script,");
489 serv_puts("# copy them to another script and save that instead.");
491 serv_puts("require \"fileinto\";");
492 serv_puts("require \"reject\";");
493 serv_puts("require \"vacation\";");
494 serv_puts("require \"envelope\";");
497 for (i=0; i<MAX_RULES; ++i) {
501 sprintf(fname, "active%d", i);
502 active = !strcasecmp(BSTR(fname), "on") ;
506 sprintf(fname, "hfield%d", i);
507 safestrncpy(hfield, BSTR(fname), sizeof hfield);
509 sprintf(fname, "compare%d", i);
510 safestrncpy(compare, BSTR(fname), sizeof compare);
512 sprintf(fname, "htext%d", i);
513 safestrncpy(htext, BSTR(fname), sizeof htext);
515 sprintf(fname, "sizecomp%d", i);
516 safestrncpy(sizecomp, BSTR(fname), sizeof sizecomp);
518 sprintf(fname, "sizeval%d", i);
519 sizeval = IBSTR(fname);
521 sprintf(fname, "action%d", i);
522 safestrncpy(action, BSTR(fname), sizeof action);
524 sprintf(fname, "fileinto%d", i);
525 safestrncpy(fileinto, BSTR(fname), sizeof fileinto);
527 sprintf(fname, "redirect%d", i);
528 safestrncpy(redirect, BSTR(fname), sizeof redirect);
530 sprintf(fname, "automsg%d", i);
531 safestrncpy(automsg, BSTR(fname), sizeof automsg);
533 sprintf(fname, "final%d", i);
534 safestrncpy(final, BSTR(fname), sizeof final);
536 snprintf(rule, sizeof rule, "%d|%s|%s|%s|%s|%d|%s|%s|%s|%s|%s",
537 active, hfield, compare, htext, sizecomp, sizeval, action, fileinto,
538 redirect, automsg, final
541 CtdlEncodeBase64(encoded_rule, rule, strlen(rule)+1, 0);
542 serv_printf("# WEBCIT_RULE|%d|%s|", i, encoded_rule);
543 output_sieve_rule(hfield, compare, htext, sizecomp, sizeval,
544 action, fileinto, redirect, automsg, final, my_addresses);
560 void save_sieve(void) {
562 char script_names[MAX_SCRIPTS][64];
564 int active_script = (-1);
569 if (!havebstr("save_button")) {
570 strcpy(WC->ImportantMessage,
571 _("Cancelled. Changes were not saved."));
576 parse_fields_from_rule_editor();
578 serv_puts("MSIV listscripts");
579 serv_getln(buf, sizeof(buf));
580 if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
581 if (num_scripts < MAX_SCRIPTS) {
582 extract_token(script_names[num_scripts], buf, 0, '|', 64);
583 if (extract_int(buf, 1) > 0) {
584 active_script = num_scripts;
590 bigaction = ibstr("bigaction");
592 if (bigaction == 0) {
593 serv_puts("MSIV setactive||");
594 serv_getln(buf, sizeof buf);
597 else if (bigaction == 1) {
598 serv_printf("MSIV setactive|%s|", RULES_SCRIPT);
599 serv_getln(buf, sizeof buf);
602 else if (bigaction == 2) {
603 serv_printf("MSIV setactive|%s|", bstr("active_script"));
604 serv_getln(buf, sizeof buf);
607 if (num_scripts > 0) {
608 for (i=0; i<num_scripts; ++i) {
610 * We only want to save the scripts from the "manually edited scripts"
611 * screen. The script that WebCit generates from its ruleset will be
612 * auto-generated by parse_fields_from_rule_editor() and saved there.
614 if (strcasecmp(script_names[i], RULES_SCRIPT)) {
615 serv_printf("MSIV putscript|%s|", script_names[i]);
616 serv_getln(buf, sizeof buf);
618 snprintf(this_name, sizeof this_name, "text_%s", script_names[i]);
619 striplt((char *)BSTR(this_name)); /* TODO: get rid of typecast*/
620 serv_write(BSTR(this_name), strlen(BSTR(this_name)));
627 strcpy(WC->ImportantMessage, _("Your changes have been saved."));
634 * show a list of available scripts to add/remove them
636 void display_add_remove_scripts(char *message)
639 char script_name[256];
641 output_headers(1, 1, 2, 0, 0, 0);
642 wc_printf("<div id=\"banner\">\n");
643 wc_printf("<img src=\"static/advanpage2_48x.gif\">");
644 wc_printf(_("Add or delete scripts"));
645 wc_printf("</h1>\n");
646 wc_printf("</div>\n");
648 wc_printf("<div id=\"content\" class=\"service\">\n");
650 if (message != NULL) {
651 wc_printf("%s", message);
654 wc_printf("<table border=0 cellspacing=10><tr valign=top><td>\n");
656 do_template("beginbox_1", NULL);
657 StrBufAppendBufPlain(WC->WBuf, _("Add a new script"), -1, 0);
658 do_template("beginbox_2", NULL);
660 wc_printf(_("To create a new script, enter the desired "
661 "script name in the box below and click 'Create'."));
662 wc_printf("<br /><br />");
664 wc_printf("<center><form method=\"POST\" action=\"create_script\">\n");
665 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
666 wc_printf(_("Script name: "));
667 wc_printf("<input type=\"text\" name=\"script_name\"><br />\n"
668 "<input type=\"submit\" name=\"create_button\" value=\"%s\">"
669 "</form></center>\n", _("Create"));
671 do_template("endbox", NULL);
673 do_template("beginbox_1", NULL);
674 StrBufAppendBufPlain(WC->WBuf, _("Edit scripts"), -1, 0);
675 do_template("beginbox_2", NULL);
676 wc_printf("<br /><div align=center><a href=\"display_sieve\">%s</a><br /><br />\n",
677 _("Return to the script editing screen")
679 do_template("endbox", NULL);
681 wc_printf("</td><td>");
683 do_template("beginbox_1", NULL);
684 StrBufAppendBufPlain(WC->WBuf, _("Delete scripts"), -1, 0);
685 do_template("beginbox_2", NULL);
687 wc_printf(_("To delete an existing script, select the script "
688 "name from the list and click 'Delete'."));
689 wc_printf("<br /><br />");
692 "<form method=\"POST\" action=\"delete_script\">\n");
693 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
694 wc_printf("<select name=\"script_name\" size=10 style=\"width:100%%\">\n");
696 serv_puts("MSIV listscripts");
697 serv_getln(buf, sizeof buf);
699 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
700 extract_token(script_name, buf, 0, '|', sizeof script_name);
701 if ( (extract_int(buf, 1) == 0) && (strcasecmp(script_name, RULES_SCRIPT)) ) {
702 wc_printf("<option>");
703 escputs(script_name);
704 wc_printf("</option>\n");
708 wc_printf("</select><br />\n");
710 wc_printf("<input type=\"submit\" name=\"delete_button\" value=\"%s\" "
711 "onClick=\"return confirm('%s');\">", _("Delete script"), _("Delete this script?"));
712 wc_printf("</form></center>\n");
713 do_template("endbox", NULL);
715 wc_printf("</td></tr></table>\n");
725 void delete_script(void) {
728 serv_printf("MSIV deletescript|%s", bstr("script_name"));
729 serv_getln(buf, sizeof buf);
730 display_add_remove_scripts(&buf[4]);
736 * create a new script
737 * take the web environment script name and create it on the citadel server
739 void create_script(void) {
742 serv_printf("MSIV getscript|%s", bstr("script_name"));
743 serv_getln(buf, sizeof buf);
745 while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
748 display_add_remove_scripts(_("A script by that name already exists."));
752 serv_printf("MSIV putscript|%s", bstr("script_name"));
753 serv_getln(buf, sizeof buf);
757 display_add_remove_scripts(_("A new script has been created. Return to the script editing screen to edit and activate it."));
761 display_add_remove_scripts(&buf[4]);
767 void display_rules_editor_inner_div(void) {
770 char rules[MAX_RULES][2048];
775 int num_roomnames = 0;
776 int num_roomnames_alloc = 0;
791 memset(rules, 0, sizeof rules);
792 serv_printf("MSIV getscript|%s", RULES_SCRIPT);
793 serv_getln(buf, sizeof buf);
794 if (buf[0] == '1') while(serv_getln(buf, sizeof (buf)), strcmp(buf, "000")) {
795 if (!strncasecmp(buf, "# WEBCIT_RULE|", 14)) {
796 j = extract_int(buf, 1);
797 remove_token(buf, 0, '|');
798 remove_token(buf, 0, '|');
799 CtdlDecodeBase64(rules[j], buf, strlen(buf));
803 /* load the roomnames */
805 serv_getln(buf, sizeof buf);
807 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
809 if (num_roomnames > num_roomnames_alloc) {
810 num_roomnames_alloc += 250;
811 rooms = realloc(rooms, (num_roomnames_alloc * 128));
813 extract_token(rooms[num_roomnames-1].name, buf, 0, '|', 128);
819 * This script should get called by every onChange event...
822 wc_printf("<script type=\"text/javascript\"> \n"
824 "var highest_active_rule = (-1); \n"
826 "function UpdateRules() { \n");
828 * Show only the active rows...
830 wc_printf(" highest_active_rule = (-1); \n");
831 wc_printf(" for (i=0; i<%d; ++i) { \n", MAX_RULES);
832 wc_printf(" if ($('active'+i).checked) { \n"
833 " $('rule' + i).style.display = 'block'; \n"
834 " highest_active_rule = i; \n"
837 " $('rule' + i).style.display = 'none'; \n"
841 * Show only the fields relevant to the rules...
843 wc_printf(" for (i=0; i<=highest_active_rule; ++i) { \n"
844 " d = ($('movedown'+i)); \n"
845 " if (i < highest_active_rule) { \n"
846 " d.style.display = 'block'; \n"
849 " d.style.display = 'none'; \n"
851 " d = ($('hfield'+i).options[$('hfield'+i).selectedIndex].value); \n"
852 " if (d == 'all') { \n"
853 " $('div_size'+i).style.display = 'none'; \n"
854 " $('div_compare'+i).style.display = 'none'; \n"
855 " $('div_nocompare'+i).style.display = 'block'; \n"
857 " else if (d == 'size') { \n"
858 " $('div_size'+i).style.display = 'block'; \n"
859 " $('div_compare'+i).style.display = 'none'; \n"
860 " $('div_nocompare'+i).style.display = 'none'; \n"
863 " $('div_size'+i).style.display = 'none'; \n"
864 " $('div_compare'+i).style.display = 'block'; \n"
865 " $('div_nocompare'+i).style.display = 'none'; \n"
867 " d = ($('action'+i).options[$('action'+i).selectedIndex].value); \n"
868 " if (d == 'fileinto') { \n"
869 " $('div_fileinto'+i).style.display = 'block'; \n"
870 " $('div_redirect'+i).style.display = 'none'; \n"
871 " $('div_automsg'+i).style.display = 'none'; \n"
872 " } else if (d == 'redirect') { \n"
873 " $('div_fileinto'+i).style.display = 'none'; \n"
874 " $('div_redirect'+i).style.display = 'block'; \n"
875 " $('div_automsg'+i).style.display = 'none'; \n"
876 " } else if ((d == 'reject') || (d == 'vacation')) { \n"
877 " $('div_fileinto'+i).style.display = 'none'; \n"
878 " $('div_redirect'+i).style.display = 'none'; \n"
879 " $('div_automsg'+i).style.display = 'block'; \n"
881 " $('div_fileinto'+i).style.display = 'none'; \n"
882 " $('div_redirect'+i).style.display = 'none'; \n"
883 " $('div_automsg'+i).style.display = 'none'; \n"
885 " if (highest_active_rule < %d) { \n", MAX_RULES-1 );
886 wc_printf(" $('div_addrule').style.display = 'block'; \n"
888 " $('div_addrule').style.display = 'none'; \n"
893 * Add a rule (really, just un-hide it)
895 "function AddRule() { \n"
896 " highest_active_rule = highest_active_rule + 1; \n"
897 " $('active'+highest_active_rule).checked = true; \n"
903 "function SwapRules(ra, rb) { \n"
905 " var things = new Array(); \n"
906 " things[0] = 'hfield'; \n"
907 " things[1] = 'compare'; \n"
908 " things[2] = 'htext'; \n"
909 " things[3] = 'action'; \n"
910 " things[4] = 'fileinto'; \n"
911 " things[5] = 'redirect'; \n"
912 " things[6] = 'final'; \n"
913 " things[7] = 'sizecomp'; \n"
914 " things[8] = 'sizeval'; \n"
915 " things[9] = 'automsg'; \n"
917 " for (i=0; i<=9; ++i) { \n"
918 " tempval=$(things[i]+ra).value; \n"
919 " $(things[i]+ra).value = $(things[i]+rb).value; \n"
920 " $(things[i]+rb).value = tempval; \n"
924 * Delete a rule (percolate the deleted rule out to the end, then deactivate it)
926 "function DeleteRule(rd) { \n"
927 " for (j=rd; j<=highest_active_rule; ++j) { \n"
928 " SwapRules(j, (j+1)); \n"
930 " $('active'+highest_active_rule).checked = false; \n"
938 wc_printf("<table cellpadding=2 width=100%%>");
940 for (i=0; i<MAX_RULES; ++i) {
942 /* Grab our existing values to populate */
943 active = extract_int(rules[i], 0);
944 extract_token(hfield, rules[i], 1, '|', sizeof hfield);
945 extract_token(compare, rules[i], 2, '|', sizeof compare);
946 extract_token(htext, rules[i], 3, '|', sizeof htext);
947 extract_token(sizecomp, rules[i], 4, '|', sizeof sizecomp);
948 sizeval = extract_int(rules[i], 5);
949 extract_token(action, rules[i], 6, '|', sizeof action);
950 extract_token(fileinto, rules[i], 7, '|', sizeof fileinto);
951 extract_token(redirect, rules[i], 8, '|', sizeof redirect);
952 extract_token(automsg, rules[i], 9, '|', sizeof automsg);
953 extract_token(final, rules[i], 10, '|', sizeof final);
955 /* now generate the table row */
957 wc_printf("<tr id=\"rule%d\" bgcolor=\"#%s\">",
959 ((i%2) ? "DDDDDD" : "FFFFFF")
962 wc_printf("<td width=5%% align=\"center\">");
964 wc_printf("<div style=\"display:none\">");
965 wc_printf("<input type=\"checkbox\" name=\"active%d\" id=\"active%d\" %s>",
967 (active ? "checked" : "")
971 if (i>0) wc_printf("<a href=\"javascript:SwapRules(%d,%d);UpdateRules();\">"
972 "<img border=\"0\" src=\"static/up_pointer.gif\" "
973 "title=\"%s\"/></a>",
974 i-1, i, _("Move rule up") );
976 wc_printf("<a href=\"javascript:SwapRules(%d,%d);UpdateRules();\">"
977 "<img id=\"movedown%d\" border=\"0\" src=\"static/down_pointer.gif\" "
978 "title=\"%s\"/></a>",
979 i, i+1, i, _("Move rule down") );
981 wc_printf("<a href=\"javascript:DeleteRule(%d);UpdateRules();\">"
982 "<img id=\"delete%d\" border=\"0\" src=\"static/delete.gif\" "
983 "title=\"%s\"/></a>",
984 i, i, _("Delete rule") );
988 wc_printf("<td width=5%% align=\"center\">");
989 wc_printf("<font size=+2>%d</font>", i+1);
992 wc_printf("<td width=20%%>%s ", _("If") );
994 char *hfield_values[15][2] = {
995 { "from", _("From") },
996 { "tocc", _("To or Cc") },
997 { "subject", _("Subject") },
998 { "replyto", _("Reply-to") },
999 { "sender", _("Sender") },
1000 { "resentfrom", _("Resent-From") },
1001 { "resentto", _("Resent-To") },
1002 { "envfrom", _("Envelope From") },
1003 { "envto", _("Envelope To") },
1004 { "xmailer", _("X-Mailer") },
1005 { "xspamflag", _("X-Spam-Flag") },
1006 { "xspamstatus", _("X-Spam-Status") },
1007 { "listid", _("List-ID") },
1008 { "size", _("Message size") },
1012 wc_printf("<select id=\"hfield%d\" name=\"hfield%d\" size=1 onChange=\"UpdateRules();\">",
1014 for (j=0; j<15; ++j) {
1015 wc_printf("<option %s value=\"%s\">%s</option>",
1016 ( (!strcasecmp(hfield, hfield_values[j][0])) ? "selected" : ""),
1017 hfield_values[j][0],
1022 wc_printf("</select>");
1025 wc_printf("<td width=20%%>");
1027 char *compare_values[6][2] = {
1028 { "contains", _("contains") },
1029 { "notcontains", _("does not contain") },
1031 { "isnot", _("is not") },
1032 { "matches", _("matches") },
1033 { "notmatches", _("does not match") }
1036 wc_printf("<div id=\"div_compare%d\">", i);
1037 wc_printf("<select id=\"compare%d\" name=\"compare%d\" size=1 onChange=\"UpdateRules();\">",
1039 for (j=0; j<6; ++j) {
1040 wc_printf("<option %s value=\"%s\">%s</option>",
1041 ( (!strcasecmp(compare, compare_values[j][0])) ? "selected" : ""),
1042 compare_values[j][0],
1043 compare_values[j][1]
1046 wc_printf("</select>");
1048 wc_printf("<input type=\"text\" id=\"htext%d\" name=\"htext%d\" value=\"", i, i);
1050 wc_printf("\"></div>");
1052 wc_printf("<div id=\"div_nocompare%d\">", i);
1053 wc_printf("%s", _("(All messages)"));
1054 wc_printf("</div>");
1056 char *sizecomp_values[2][2] = {
1057 { "larger", _("is larger than") },
1058 { "smaller", _("is smaller than") }
1061 wc_printf("<div id=\"div_size%d\">", i);
1062 wc_printf("<select id=\"sizecomp%d\" name=\"sizecomp%d\" size=1 onChange=\"UpdateRules();\">",
1064 for (j=0; j<2; ++j) {
1065 wc_printf("<option %s value=\"%s\">%s</option>",
1066 ( (!strcasecmp(sizecomp, sizecomp_values[j][0])) ? "selected" : ""),
1067 sizecomp_values[j][0],
1068 sizecomp_values[j][1]
1071 wc_printf("</select>");
1073 wc_printf("<input type=\"text\" id=\"sizeval%d\" name=\"sizeval%d\" value=\"%d\">",
1076 wc_printf("</div>");
1080 char *action_values[6][2] = {
1081 { "keep", _("Keep") },
1082 { "discard", _("Discard silently") },
1083 { "reject", _("Reject") },
1084 { "fileinto", _("Move message to") },
1085 { "redirect", _("Forward to") },
1086 { "vacation", _("Vacation") }
1089 wc_printf("<td width=20%%>");
1090 wc_printf("<select id=\"action%d\" name=\"action%d\" size=1 onChange=\"UpdateRules();\">",
1092 for (j=0; j<6; ++j) {
1093 wc_printf("<option %s value=\"%s\">%s</option>",
1094 ( (!strcasecmp(action, action_values[j][0])) ? "selected" : ""),
1095 action_values[j][0],
1099 wc_printf("</select>");
1101 wc_printf("<div id=\"div_fileinto%d\">", i);
1102 wc_printf("<select name=\"fileinto%d\" id=\"fileinto%d\">", i, i);
1103 for (j=0; j<num_roomnames; ++j) {
1104 wc_printf("<option ");
1105 if (!strcasecmp(rooms[j].name, fileinto)) {
1106 wc_printf("selected ");
1108 wc_printf("value=\"");
1109 escputs(rooms[j].name);
1111 escputs(rooms[j].name);
1112 wc_printf("</option>\n");
1114 wc_printf("</select>\n");
1115 wc_printf("</div>");
1117 wc_printf("<div id=\"div_redirect%d\">", i);
1118 wc_printf("<input type=\"text\" id=\"redirect%d\" name=\"redirect%d\" value=\"", i, i);
1120 wc_printf("\"></div>");
1122 wc_printf("<div id=\"div_automsg%d\">", i);
1123 wc_printf(_("Message:"));
1124 wc_printf("<br />");
1125 wc_printf("<textarea name=\"automsg%d\" id=\"automsg%d\" wrap=soft rows=5>\n", i, i);
1127 wc_printf("</textarea>");
1128 wc_printf("</div>");
1132 char *final_values[2][2] = {
1133 { "continue", _("continue processing") },
1134 { "stop", _("stop") }
1137 wc_printf("<td width=10%% align=\"center\">%s</td>", _("and then") );
1139 wc_printf("<td width=20%%>");
1140 wc_printf("<select name=\"final%d\" id=\"final%d\" size=1 onChange=\"UpdateRules();\">",
1142 for (j=0; j<2; ++j) {
1143 wc_printf("<option %s value=\"%s\">%s</option>",
1144 ( (!strcasecmp(final, final_values[j][0])) ? "selected" : ""),
1149 wc_printf("</select>");
1152 wc_printf("</tr>\n");
1156 wc_printf("</table>");
1157 wc_printf("<div id=\"div_addrule\"><a href=\"javascript:AddRule();\">%s</a><br /></div>\n",
1161 wc_printf("<script type=\"text/javascript\"> \n");
1162 wc_printf("UpdateRules(); \n");
1163 wc_printf("</script> \n");
1168 void _display_add_remove_scripts(void) {display_add_remove_scripts(NULL);}
1174 WebcitAddUrlHandler(HKEY("display_sieve"), "", 0, display_sieve, 0);
1175 WebcitAddUrlHandler(HKEY("save_sieve"), "", 0, save_sieve, 0);
1176 WebcitAddUrlHandler(HKEY("display_add_remove_scripts"), "", 0, _display_add_remove_scripts, 0);
1177 WebcitAddUrlHandler(HKEY("create_script"), "", 0, create_script, 0);
1178 WebcitAddUrlHandler(HKEY("delete_script"), "", 0, delete_script, 0);