7 #define MAX_SCRIPTS 100
9 #define RULES_SCRIPT "__WebCit_Generated_Script__"
13 * dummy panel indicating to the user that the server doesn't support Sieve
15 void display_no_sieve(void) {
17 output_headers(1, 1, 2, 0, 0, 0);
19 wc_printf("<div id=\"banner\">\n");
20 wc_printf("<img src=\"static/advanpage2_48x.gif\">");
22 wc_printf(_("View/edit server-side mail filters"));
24 wc_printf("</div>\n");
26 wc_printf("<div id=\"content\" class=\"service\">\n");
28 wc_printf("<div class=\"fix_scrollbar_bug\">"
29 "<table class=\"sieve_background\">"
30 "<tr><td valign=top>\n");
32 wc_printf(_("This installation of Citadel was built without support for server-side mail filtering."
33 "<br>Please contact your system administrator if you require this feature.<br>"));
35 wc_printf("</td></tr></table></div>\n");
41 * view/edit sieve config
43 void display_sieve(void)
45 char script_names[MAX_SCRIPTS][64];
47 int active_script = (-1);
48 char buf[SIZ]; /* Don't make this buffer smaller or it will restrict line length */
50 int rules_script_is_active = 0;
52 if (!WC->serv_info->serv_supports_sieve) {
57 memset(script_names, 0, sizeof script_names);
59 serv_puts("MSIV listscripts");
60 serv_getln(buf, sizeof(buf));
61 if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
62 if (num_scripts < MAX_SCRIPTS) {
63 extract_token(script_names[num_scripts], buf, 0, '|', 64);
64 if (extract_int(buf, 1) > 0) {
65 active_script = num_scripts;
66 if (!strcasecmp(script_names[num_scripts], RULES_SCRIPT)) {
67 rules_script_is_active = 1;
74 output_headers(1, 1, 2, 0, 0, 0);
76 wc_printf("<script type=\"text/javascript\"> \n"
78 "var previously_active_script; \n"
80 "function ToggleSievePanels() { \n"
81 " d = ($('sieveform').bigaction.options[$('sieveform').bigaction.selectedIndex].value); \n"
82 " for (i=0; i<3; ++i) { \n"
84 " $('sievediv' + i).style.display = 'block'; \n"
87 " $('sievediv' + i).style.display = 'none'; \n"
92 "function ToggleScriptPanels() { \n"
93 " d = ($('sieveform').active_script.options[$('sieveform').active_script.selectedIndex].value); \n"
94 " if ($('script_' + previously_active_script)) { \n"
95 " $('script_' + previously_active_script).style.display = 'none'; \n"
97 " $('script_' + d).style.display = 'block'; \n"
98 " previously_active_script = d; \n"
104 wc_printf("<div id=\"banner\">\n");
105 wc_printf("<img src=\"static/advanpage2_48x.gif\">");
107 wc_printf(_("View/edit server-side mail filters"));
108 wc_printf("</h1>\n");
109 wc_printf("</div>\n");
111 wc_printf("<div id=\"content\" class=\"service\">\n");
113 wc_printf("<div class=\"fix_scrollbar_bug\">"
114 "<table class=\"sieve_background\">"
115 "<tr><td valign=top>\n");
118 wc_printf("<form id=\"sieveform\" method=\"post\" action=\"save_sieve\">\n");
119 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
121 wc_printf(_("When new mail arrives: "));
122 wc_printf("<select name=\"bigaction\" size=1 onChange=\"ToggleSievePanels();\">\n");
124 wc_printf("<option %s value=\"0\">", ((active_script < 0) ? "selected" : ""));
125 wc_printf(_("Leave it in my inbox without filtering"));
126 wc_printf("</option>\n");
128 wc_printf("<option %s value=\"1\">", ((rules_script_is_active) ? "selected" : ""));
129 wc_printf(_("Filter it according to rules selected below"));
130 wc_printf("</option>\n");
132 wc_printf("<option %s value=\"2\">",
133 (((active_script >= 0) && (!rules_script_is_active)) ? "selected" : ""));
134 wc_printf(_("Filter it through a manually edited script (advanced users only)"));
135 wc_printf("</option>\n");
137 wc_printf("</select>");
141 /* The "no filtering" div */
143 wc_printf("<div id=\"sievediv0\" style=\"display:none\">\n");
144 wc_printf("<div align=\"center\"><br /><br />");
145 wc_printf(_("Your incoming mail will not be filtered through any scripts."));
146 wc_printf("<br /><br /></div>\n");
147 wc_printf("</div>\n");
149 /* The "webcit managed scripts" div */
151 wc_printf("<div id=\"sievediv1\" style=\"display:none\">\n");
152 display_rules_editor_inner_div();
153 wc_printf("</div>\n");
155 /* The "I'm smart and can write my own Sieve scripts" div */
157 wc_printf("<div id=\"sievediv2\" style=\"display:none\">\n");
159 if (num_scripts > 0) {
160 wc_printf(_("The currently active script is: "));
161 wc_printf("<select name=\"active_script\" size=1 onChange=\"ToggleScriptPanels();\">\n");
162 for (i=0; i<num_scripts; ++i) {
163 if (strcasecmp(script_names[i], RULES_SCRIPT)) {
164 wc_printf("<option %s value=\"%s\">%s</option>\n",
165 ((active_script == i) ? "selected" : ""),
171 wc_printf("</select>\n");
174 wc_printf(" ");
175 wc_printf("<a href=\"display_add_remove_scripts\">%s</a>\n", _("Add or delete scripts"));
177 wc_printf("<br />\n");
179 if (num_scripts > 0) {
180 for (i=0; i<num_scripts; ++i) {
181 if (strcasecmp(script_names[i], RULES_SCRIPT)) {
182 wc_printf("<div id=\"script_%s\" style=\"display:none\">\n", script_names[i]);
183 wc_printf("<textarea name=\"text_%s\" wrap=soft rows=20 cols=80 width=80>\n",
185 serv_printf("MSIV getscript|%s", script_names[i]);
186 serv_getln(buf, sizeof buf);
187 if (buf[0] == '1') while(serv_getln(buf, sizeof (buf)), strcmp(buf, "000")) {
188 wc_printf("%s\n", buf);
190 wc_printf("</textarea>\n");
191 wc_printf("</div>\n");
196 wc_printf("<script type=\"text/javascript\"> \n"
197 "ToggleScriptPanels(); \n"
201 wc_printf("</div>\n");
204 /* The rest of this is common for all panels... */
206 wc_printf("<div align=\"center\"><br>");
207 wc_printf("<input type=\"submit\" name=\"save_button\" value=\"%s\">", _("Save changes"));
209 wc_printf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
210 wc_printf("</div></form>\n");
212 wc_printf("</td></tr></table></div>\n");
214 wc_printf("<script type=\"text/javascript\"> \n"
215 "ToggleSievePanels(); \n"
226 * Helper function for output_sieve_rule() to output strings with quotes escaped
228 void osr_sanitize(char *str) {
231 if (str == NULL) return;
233 for (i=0; i<len; ++i) {
237 else if (isspace(str[i])) {
245 * Output parseable Sieve script code based on rules input
247 void output_sieve_rule(char *hfield, char *compare, char *htext, char *sizecomp, int sizeval,
248 char *action, char *fileinto, char *redirect, char *automsg, char *final,
255 osr_sanitize(fileinto);
256 osr_sanitize(redirect);
257 osr_sanitize(automsg);
259 /* Prepare negation and match operators that will be used iff we apply a conditional */
261 if (!strcasecmp(compare, "contains")) {
265 else if (!strcasecmp(compare, "notcontains")) {
269 else if (!strcasecmp(compare, "is")) {
273 else if (!strcasecmp(compare, "isnot")) {
277 else if (!strcasecmp(compare, "matches")) {
281 else if (!strcasecmp(compare, "notmatches")) {
286 /* Now do the conditional */
288 if (!strcasecmp(hfield, "from")) {
289 serv_printf("if%s header %s \"From\" \"%s\"",
295 else if (!strcasecmp(hfield, "tocc")) {
296 serv_printf("if%s header %s [\"To\", \"Cc\"] \"%s\"",
302 else if (!strcasecmp(hfield, "subject")) {
303 serv_printf("if%s header %s \"Subject\" \"%s\"",
309 else if (!strcasecmp(hfield, "replyto")) {
310 serv_printf("if%s header %s \"Reply-to\" \"%s\"",
316 else if (!strcasecmp(hfield, "sender")) {
317 serv_printf("if%s header %s \"Sender\" \"%s\"",
323 else if (!strcasecmp(hfield, "resentfrom")) {
324 serv_printf("if%s header %s \"Resent-from\" \"%s\"",
330 else if (!strcasecmp(hfield, "resentto")) {
331 serv_printf("if%s header %s \"Resent-to\" \"%s\"",
337 else if (!strcasecmp(hfield, "xmailer")) {
338 serv_printf("if%s header %s \"X-Mailer\" \"%s\"",
344 else if (!strcasecmp(hfield, "xspamflag")) {
345 serv_printf("if%s header %s \"X-Spam-Flag\" \"%s\"",
351 else if (!strcasecmp(hfield, "xspamstatus")) {
352 serv_printf("if%s header %s \"X-Spam-Status\" \"%s\"",
358 else if (!strcasecmp(hfield, "listid")) {
359 serv_printf("if%s header %s \"List-ID\" \"%s\"",
365 else if (!strcasecmp(hfield, "envfrom")) {
366 serv_printf("if%s envelope %s \"From\" \"%s\"",
372 else if (!strcasecmp(hfield, "envto")) {
373 serv_printf("if%s envelope %s \"To\" \"%s\"",
379 else if (!strcasecmp(hfield, "size")) {
380 if (!strcasecmp(sizecomp, "larger")) {
381 serv_printf("if size :over %d", sizeval);
383 else if (!strcasecmp(sizecomp, "smaller")) {
384 serv_printf("if size :under %d", sizeval);
386 else { /* failsafe - should never get here, but just in case... */
387 serv_printf("if size :over 1");
391 /* Open braces if we're in a conditional loop */
393 if (strcasecmp(hfield, "all")) {
400 if (!strcasecmp(action, "keep")) {
401 serv_printf("keep;");
404 else if (!strcasecmp(action, "discard")) {
405 serv_printf("discard;");
408 else if (!strcasecmp(action, "reject")) {
409 serv_printf("reject \"%s\";", automsg);
412 else if (!strcasecmp(action, "fileinto")) {
413 serv_printf("fileinto \"%s\";", fileinto);
416 else if (!strcasecmp(action, "redirect")) {
417 serv_printf("redirect \"%s\";", redirect);
420 else if (!strcasecmp(action, "vacation")) {
421 serv_printf("vacation :addresses [%s]\n\"%s\";", my_addresses, automsg);
425 /* Do 'final' action */
427 if (!strcasecmp(final, "stop")) {
428 serv_printf("stop;");
432 /* Close the braces if we're in a conditional loop */
434 if (strcasecmp(hfield, "all")) {
445 * Translate the fields from the rule editor into something we can save...
447 void parse_fields_from_rule_editor(void) {
464 char encoded_rule[4096];
465 char my_addresses[4096];
467 /* Enumerate my email addresses in case they are needed for a vacation rule */
470 serv_getln(buf, sizeof buf);
471 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
472 if (!IsEmptyStr(my_addresses)) {
473 strcat(my_addresses, ",\n");
475 strcat(my_addresses, "\"");
476 strcat(my_addresses, buf);
477 strcat(my_addresses, "\"");
480 /* Now generate the script and write it to the Citadel server */
481 serv_printf("MSIV putscript|%s|", RULES_SCRIPT);
482 serv_getln(buf, sizeof buf);
487 serv_puts("# THIS SCRIPT WAS AUTOMATICALLY GENERATED BY WEBCIT.");
489 serv_puts("# Do not attempt to manually edit it. If you do so,");
490 serv_puts("# your changes will be overwritten the next time WebCit");
491 serv_puts("# saves its mail filtering rule set. If you really want");
492 serv_puts("# to use these rules as the basis for another script,");
493 serv_puts("# copy them to another script and save that instead.");
495 serv_puts("require \"fileinto\";");
496 serv_puts("require \"reject\";");
497 serv_puts("require \"vacation\";");
498 serv_puts("require \"envelope\";");
501 for (i=0; i<MAX_RULES; ++i) {
505 sprintf(fname, "active%d", i);
506 active = !strcasecmp(BSTR(fname), "on") ;
510 sprintf(fname, "hfield%d", i);
511 safestrncpy(hfield, BSTR(fname), sizeof hfield);
513 sprintf(fname, "compare%d", i);
514 safestrncpy(compare, BSTR(fname), sizeof compare);
516 sprintf(fname, "htext%d", i);
517 safestrncpy(htext, BSTR(fname), sizeof htext);
519 sprintf(fname, "sizecomp%d", i);
520 safestrncpy(sizecomp, BSTR(fname), sizeof sizecomp);
522 sprintf(fname, "sizeval%d", i);
523 sizeval = IBSTR(fname);
525 sprintf(fname, "action%d", i);
526 safestrncpy(action, BSTR(fname), sizeof action);
528 sprintf(fname, "fileinto%d", i);
529 safestrncpy(fileinto, BSTR(fname), sizeof fileinto);
531 sprintf(fname, "redirect%d", i);
532 safestrncpy(redirect, BSTR(fname), sizeof redirect);
534 sprintf(fname, "automsg%d", i);
535 safestrncpy(automsg, BSTR(fname), sizeof automsg);
537 sprintf(fname, "final%d", i);
538 safestrncpy(final, BSTR(fname), sizeof final);
540 snprintf(rule, sizeof rule, "%d|%s|%s|%s|%s|%d|%s|%s|%s|%s|%s",
541 active, hfield, compare, htext, sizecomp, sizeval, action, fileinto,
542 redirect, automsg, final
545 CtdlEncodeBase64(encoded_rule, rule, strlen(rule)+1, 0);
546 serv_printf("# WEBCIT_RULE|%d|%s|", i, encoded_rule);
547 output_sieve_rule(hfield, compare, htext, sizecomp, sizeval,
548 action, fileinto, redirect, automsg, final, my_addresses);
564 void save_sieve(void) {
566 char script_names[MAX_SCRIPTS][64];
568 int active_script = (-1);
573 if (!havebstr("save_button")) {
574 strcpy(WC->ImportantMessage,
575 _("Cancelled. Changes were not saved."));
580 parse_fields_from_rule_editor();
582 serv_puts("MSIV listscripts");
583 serv_getln(buf, sizeof(buf));
584 if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
585 if (num_scripts < MAX_SCRIPTS) {
586 extract_token(script_names[num_scripts], buf, 0, '|', 64);
587 if (extract_int(buf, 1) > 0) {
588 active_script = num_scripts;
594 bigaction = ibstr("bigaction");
596 if (bigaction == 0) {
597 serv_puts("MSIV setactive||");
598 serv_getln(buf, sizeof buf);
601 else if (bigaction == 1) {
602 serv_printf("MSIV setactive|%s|", RULES_SCRIPT);
603 serv_getln(buf, sizeof buf);
606 else if (bigaction == 2) {
607 serv_printf("MSIV setactive|%s|", bstr("active_script"));
608 serv_getln(buf, sizeof buf);
611 if (num_scripts > 0) {
612 for (i=0; i<num_scripts; ++i) {
614 * We only want to save the scripts from the "manually edited scripts"
615 * screen. The script that WebCit generates from its ruleset will be
616 * auto-generated by parse_fields_from_rule_editor() and saved there.
618 if (strcasecmp(script_names[i], RULES_SCRIPT)) {
619 serv_printf("MSIV putscript|%s|", script_names[i]);
620 serv_getln(buf, sizeof buf);
622 snprintf(this_name, sizeof this_name, "text_%s", script_names[i]);
623 striplt((char *)BSTR(this_name)); /* TODO: get rid of typecast*/
624 serv_write(BSTR(this_name), strlen(BSTR(this_name)));
631 strcpy(WC->ImportantMessage, _("Your changes have been saved."));
638 * show a list of available scripts to add/remove them
640 void display_add_remove_scripts(char *message)
643 char script_name[256];
645 output_headers(1, 1, 2, 0, 0, 0);
646 wc_printf("<div id=\"banner\">\n");
647 wc_printf("<img src=\"static/advanpage2_48x.gif\">");
648 wc_printf(_("Add or delete scripts"));
649 wc_printf("</h1>\n");
650 wc_printf("</div>\n");
652 wc_printf("<div id=\"content\" class=\"service\">\n");
654 if (message != NULL) {
655 wc_printf("%s", message);
658 wc_printf("<table border=0 cellspacing=10><tr valign=top><td>\n");
660 svput("BOXTITLE", WCS_STRING, _("Add a new script"));
661 do_template("beginboxx", NULL);
663 wc_printf(_("To create a new script, enter the desired "
664 "script name in the box below and click 'Create'."));
665 wc_printf("<br /><br />");
667 wc_printf("<center><form method=\"POST\" action=\"create_script\">\n");
668 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
669 wc_printf(_("Script name: "));
670 wc_printf("<input type=\"text\" name=\"script_name\"><br />\n"
671 "<input type=\"submit\" name=\"create_button\" value=\"%s\">"
672 "</form></center>\n", _("Create"));
674 do_template("endbox", NULL);
676 svput("BOXTITLE", WCS_STRING, _("Edit scripts"));
677 do_template("beginboxx", NULL);
678 wc_printf("<br /><div align=center><a href=\"display_sieve\">%s</a><br /><br />\n",
679 _("Return to the script editing screen")
681 do_template("endbox", NULL);
683 wc_printf("</td><td>");
685 svput("BOXTITLE", WCS_STRING, _("Delete scripts"));
686 do_template("beginboxx", NULL);
688 wc_printf(_("To delete an existing script, select the script "
689 "name from the list and click 'Delete'."));
690 wc_printf("<br /><br />");
693 "<form method=\"POST\" action=\"delete_script\">\n");
694 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
695 wc_printf("<select name=\"script_name\" size=10 style=\"width:100%%\">\n");
697 serv_puts("MSIV listscripts");
698 serv_getln(buf, sizeof buf);
700 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
701 extract_token(script_name, buf, 0, '|', sizeof script_name);
702 if ( (extract_int(buf, 1) == 0) && (strcasecmp(script_name, RULES_SCRIPT)) ) {
703 wc_printf("<option>");
704 escputs(script_name);
705 wc_printf("</option>\n");
709 wc_printf("</select><br />\n");
711 wc_printf("<input type=\"submit\" name=\"delete_button\" value=\"%s\" "
712 "onClick=\"return confirm('%s');\">", _("Delete script"), _("Delete this script?"));
713 wc_printf("</form></center>\n");
714 do_template("endbox", NULL);
716 wc_printf("</td></tr></table>\n");
726 void delete_script(void) {
729 serv_printf("MSIV deletescript|%s", bstr("script_name"));
730 serv_getln(buf, sizeof buf);
731 display_add_remove_scripts(&buf[4]);
737 * create a new script
738 * take the web environment script name and create it on the citadel server
740 void create_script(void) {
743 serv_printf("MSIV getscript|%s", bstr("script_name"));
744 serv_getln(buf, sizeof buf);
746 while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
749 display_add_remove_scripts(_("A script by that name already exists."));
753 serv_printf("MSIV putscript|%s", bstr("script_name"));
754 serv_getln(buf, sizeof buf);
758 display_add_remove_scripts(_("A new script has been created. Return to the script editing screen to edit and activate it."));
762 display_add_remove_scripts(&buf[4]);
768 void display_rules_editor_inner_div(void) {
771 char rules[MAX_RULES][2048];
776 int num_roomnames = 0;
777 int num_roomnames_alloc = 0;
792 memset(rules, 0, sizeof rules);
793 serv_printf("MSIV getscript|%s", RULES_SCRIPT);
794 serv_getln(buf, sizeof buf);
795 if (buf[0] == '1') while(serv_getln(buf, sizeof (buf)), strcmp(buf, "000")) {
796 if (!strncasecmp(buf, "# WEBCIT_RULE|", 14)) {
797 j = extract_int(buf, 1);
798 remove_token(buf, 0, '|');
799 remove_token(buf, 0, '|');
800 CtdlDecodeBase64(rules[j], buf, strlen(buf));
804 /* load the roomnames */
806 serv_getln(buf, sizeof buf);
808 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
810 if (num_roomnames > num_roomnames_alloc) {
811 num_roomnames_alloc += 250;
812 rooms = realloc(rooms, (num_roomnames_alloc * 128));
814 extract_token(rooms[num_roomnames-1].name, buf, 0, '|', 128);
820 * This script should get called by every onChange event...
823 wc_printf("<script type=\"text/javascript\"> \n"
825 "var highest_active_rule = (-1); \n"
827 "function UpdateRules() { \n");
829 * Show only the active rows...
831 wc_printf(" highest_active_rule = (-1); \n");
832 wc_printf(" for (i=0; i<%d; ++i) { \n", MAX_RULES);
833 wc_printf(" if ($('active'+i).checked) { \n"
834 " $('rule' + i).style.display = 'block'; \n"
835 " highest_active_rule = i; \n"
838 " $('rule' + i).style.display = 'none'; \n"
842 * Show only the fields relevant to the rules...
844 wc_printf(" for (i=0; i<=highest_active_rule; ++i) { \n"
845 " d = ($('movedown'+i)); \n"
846 " if (i < highest_active_rule) { \n"
847 " d.style.display = 'block'; \n"
850 " d.style.display = 'none'; \n"
852 " d = ($('hfield'+i).options[$('hfield'+i).selectedIndex].value); \n"
853 " if (d == 'all') { \n"
854 " $('div_size'+i).style.display = 'none'; \n"
855 " $('div_compare'+i).style.display = 'none'; \n"
856 " $('div_nocompare'+i).style.display = 'block'; \n"
858 " else if (d == 'size') { \n"
859 " $('div_size'+i).style.display = 'block'; \n"
860 " $('div_compare'+i).style.display = 'none'; \n"
861 " $('div_nocompare'+i).style.display = 'none'; \n"
864 " $('div_size'+i).style.display = 'none'; \n"
865 " $('div_compare'+i).style.display = 'block'; \n"
866 " $('div_nocompare'+i).style.display = 'none'; \n"
868 " d = ($('action'+i).options[$('action'+i).selectedIndex].value); \n"
869 " if (d == 'fileinto') { \n"
870 " $('div_fileinto'+i).style.display = 'block'; \n"
871 " $('div_redirect'+i).style.display = 'none'; \n"
872 " $('div_automsg'+i).style.display = 'none'; \n"
873 " } else if (d == 'redirect') { \n"
874 " $('div_fileinto'+i).style.display = 'none'; \n"
875 " $('div_redirect'+i).style.display = 'block'; \n"
876 " $('div_automsg'+i).style.display = 'none'; \n"
877 " } else if ((d == 'reject') || (d == 'vacation')) { \n"
878 " $('div_fileinto'+i).style.display = 'none'; \n"
879 " $('div_redirect'+i).style.display = 'none'; \n"
880 " $('div_automsg'+i).style.display = 'block'; \n"
882 " $('div_fileinto'+i).style.display = 'none'; \n"
883 " $('div_redirect'+i).style.display = 'none'; \n"
884 " $('div_automsg'+i).style.display = 'none'; \n"
886 " if (highest_active_rule < %d) { \n", MAX_RULES-1 );
887 wc_printf(" $('div_addrule').style.display = 'block'; \n"
889 " $('div_addrule').style.display = 'none'; \n"
894 * Add a rule (really, just un-hide it)
896 "function AddRule() { \n"
897 " highest_active_rule = highest_active_rule + 1; \n"
898 " $('active'+highest_active_rule).checked = true; \n"
904 "function SwapRules(ra, rb) { \n"
906 " var things = new Array(); \n"
907 " things[0] = 'hfield'; \n"
908 " things[1] = 'compare'; \n"
909 " things[2] = 'htext'; \n"
910 " things[3] = 'action'; \n"
911 " things[4] = 'fileinto'; \n"
912 " things[5] = 'redirect'; \n"
913 " things[6] = 'final'; \n"
914 " things[7] = 'sizecomp'; \n"
915 " things[8] = 'sizeval'; \n"
916 " things[9] = 'automsg'; \n"
918 " for (i=0; i<=9; ++i) { \n"
919 " tempval=$(things[i]+ra).value; \n"
920 " $(things[i]+ra).value = $(things[i]+rb).value; \n"
921 " $(things[i]+rb).value = tempval; \n"
925 * Delete a rule (percolate the deleted rule out to the end, then deactivate it)
927 "function DeleteRule(rd) { \n"
928 " for (j=rd; j<=highest_active_rule; ++j) { \n"
929 " SwapRules(j, (j+1)); \n"
931 " $('active'+highest_active_rule).checked = false; \n"
939 wc_printf("<table cellpadding=2 width=100%%>");
941 for (i=0; i<MAX_RULES; ++i) {
943 /* Grab our existing values to populate */
944 active = extract_int(rules[i], 0);
945 extract_token(hfield, rules[i], 1, '|', sizeof hfield);
946 extract_token(compare, rules[i], 2, '|', sizeof compare);
947 extract_token(htext, rules[i], 3, '|', sizeof htext);
948 extract_token(sizecomp, rules[i], 4, '|', sizeof sizecomp);
949 sizeval = extract_int(rules[i], 5);
950 extract_token(action, rules[i], 6, '|', sizeof action);
951 extract_token(fileinto, rules[i], 7, '|', sizeof fileinto);
952 extract_token(redirect, rules[i], 8, '|', sizeof redirect);
953 extract_token(automsg, rules[i], 9, '|', sizeof automsg);
954 extract_token(final, rules[i], 10, '|', sizeof final);
956 /* now generate the table row */
958 wc_printf("<tr id=\"rule%d\" bgcolor=\"#%s\">",
960 ((i%2) ? "DDDDDD" : "FFFFFF")
963 wc_printf("<td width=5%% align=\"center\">");
965 wc_printf("<div style=\"display:none\">");
966 wc_printf("<input type=\"checkbox\" name=\"active%d\" id=\"active%d\" %s>",
968 (active ? "checked" : "")
972 if (i>0) wc_printf("<a href=\"javascript:SwapRules(%d,%d);UpdateRules();\">"
973 "<img border=\"0\" src=\"static/up_pointer.gif\" "
974 "title=\"%s\"/></a>",
975 i-1, i, _("Move rule up") );
977 wc_printf("<a href=\"javascript:SwapRules(%d,%d);UpdateRules();\">"
978 "<img id=\"movedown%d\" border=\"0\" src=\"static/down_pointer.gif\" "
979 "title=\"%s\"/></a>",
980 i, i+1, i, _("Move rule down") );
982 wc_printf("<a href=\"javascript:DeleteRule(%d);UpdateRules();\">"
983 "<img id=\"delete%d\" border=\"0\" src=\"static/delete.gif\" "
984 "title=\"%s\"/></a>",
985 i, i, _("Delete rule") );
989 wc_printf("<td width=5%% align=\"center\">");
990 wc_printf("<font size=+2>%d</font>", i+1);
993 wc_printf("<td width=20%%>%s ", _("If") );
995 char *hfield_values[15][2] = {
996 { "from", _("From") },
997 { "tocc", _("To or Cc") },
998 { "subject", _("Subject") },
999 { "replyto", _("Reply-to") },
1000 { "sender", _("Sender") },
1001 { "resentfrom", _("Resent-From") },
1002 { "resentto", _("Resent-To") },
1003 { "envfrom", _("Envelope From") },
1004 { "envto", _("Envelope To") },
1005 { "xmailer", _("X-Mailer") },
1006 { "xspamflag", _("X-Spam-Flag") },
1007 { "xspamstatus", _("X-Spam-Status") },
1008 { "listid", _("List-ID") },
1009 { "size", _("Message size") },
1013 wc_printf("<select id=\"hfield%d\" name=\"hfield%d\" size=1 onChange=\"UpdateRules();\">",
1015 for (j=0; j<15; ++j) {
1016 wc_printf("<option %s value=\"%s\">%s</option>",
1017 ( (!strcasecmp(hfield, hfield_values[j][0])) ? "selected" : ""),
1018 hfield_values[j][0],
1023 wc_printf("</select>");
1026 wc_printf("<td width=20%%>");
1028 char *compare_values[6][2] = {
1029 { "contains", _("contains") },
1030 { "notcontains", _("does not contain") },
1032 { "isnot", _("is not") },
1033 { "matches", _("matches") },
1034 { "notmatches", _("does not match") }
1037 wc_printf("<div id=\"div_compare%d\">", i);
1038 wc_printf("<select id=\"compare%d\" name=\"compare%d\" size=1 onChange=\"UpdateRules();\">",
1040 for (j=0; j<6; ++j) {
1041 wc_printf("<option %s value=\"%s\">%s</option>",
1042 ( (!strcasecmp(compare, compare_values[j][0])) ? "selected" : ""),
1043 compare_values[j][0],
1044 compare_values[j][1]
1047 wc_printf("</select>");
1049 wc_printf("<input type=\"text\" id=\"htext%d\" name=\"htext%d\" value=\"", i, i);
1051 wc_printf("\"></div>");
1053 wc_printf("<div id=\"div_nocompare%d\">", i);
1054 wc_printf("%s", _("(All messages)"));
1055 wc_printf("</div>");
1057 char *sizecomp_values[2][2] = {
1058 { "larger", _("is larger than") },
1059 { "smaller", _("is smaller than") }
1062 wc_printf("<div id=\"div_size%d\">", i);
1063 wc_printf("<select id=\"sizecomp%d\" name=\"sizecomp%d\" size=1 onChange=\"UpdateRules();\">",
1065 for (j=0; j<2; ++j) {
1066 wc_printf("<option %s value=\"%s\">%s</option>",
1067 ( (!strcasecmp(sizecomp, sizecomp_values[j][0])) ? "selected" : ""),
1068 sizecomp_values[j][0],
1069 sizecomp_values[j][1]
1072 wc_printf("</select>");
1074 wc_printf("<input type=\"text\" id=\"sizeval%d\" name=\"sizeval%d\" value=\"%d\">",
1077 wc_printf("</div>");
1081 char *action_values[6][2] = {
1082 { "keep", _("Keep") },
1083 { "discard", _("Discard silently") },
1084 { "reject", _("Reject") },
1085 { "fileinto", _("Move message to") },
1086 { "redirect", _("Forward to") },
1087 { "vacation", _("Vacation") }
1090 wc_printf("<td width=20%%>");
1091 wc_printf("<select id=\"action%d\" name=\"action%d\" size=1 onChange=\"UpdateRules();\">",
1093 for (j=0; j<6; ++j) {
1094 wc_printf("<option %s value=\"%s\">%s</option>",
1095 ( (!strcasecmp(action, action_values[j][0])) ? "selected" : ""),
1096 action_values[j][0],
1100 wc_printf("</select>");
1102 wc_printf("<div id=\"div_fileinto%d\">", i);
1103 wc_printf("<select name=\"fileinto%d\" id=\"fileinto%d\">", i, i);
1104 for (j=0; j<num_roomnames; ++j) {
1105 wc_printf("<option ");
1106 if (!strcasecmp(rooms[j].name, fileinto)) {
1107 wc_printf("selected ");
1109 wc_printf("value=\"");
1110 escputs(rooms[j].name);
1112 escputs(rooms[j].name);
1113 wc_printf("</option>\n");
1115 wc_printf("</select>\n");
1116 wc_printf("</div>");
1118 wc_printf("<div id=\"div_redirect%d\">", i);
1119 wc_printf("<input type=\"text\" id=\"redirect%d\" name=\"redirect%d\" value=\"", i, i);
1121 wc_printf("\"></div>");
1123 wc_printf("<div id=\"div_automsg%d\">", i);
1124 wc_printf(_("Message:"));
1125 wc_printf("<br />");
1126 wc_printf("<textarea name=\"automsg%d\" id=\"automsg%d\" wrap=soft rows=5>\n", i, i);
1128 wc_printf("</textarea>");
1129 wc_printf("</div>");
1133 char *final_values[2][2] = {
1134 { "continue", _("continue processing") },
1135 { "stop", _("stop") }
1138 wc_printf("<td width=10%% align=\"center\">%s</td>", _("and then") );
1140 wc_printf("<td width=20%%>");
1141 wc_printf("<select name=\"final%d\" id=\"final%d\" size=1 onChange=\"UpdateRules();\">",
1143 for (j=0; j<2; ++j) {
1144 wc_printf("<option %s value=\"%s\">%s</option>",
1145 ( (!strcasecmp(final, final_values[j][0])) ? "selected" : ""),
1150 wc_printf("</select>");
1153 wc_printf("</tr>\n");
1157 wc_printf("</table>");
1158 wc_printf("<div id=\"div_addrule\"><a href=\"javascript:AddRule();\">%s</a><br /></div>\n",
1162 wc_printf("<script type=\"text/javascript\"> \n");
1163 wc_printf("UpdateRules(); \n");
1164 wc_printf("</script> \n");
1169 void _display_add_remove_scripts(void) {display_add_remove_scripts(NULL);}
1175 WebcitAddUrlHandler(HKEY("display_sieve"), "", 0, display_sieve, 0);
1176 WebcitAddUrlHandler(HKEY("save_sieve"), "", 0, save_sieve, 0);
1177 WebcitAddUrlHandler(HKEY("display_add_remove_scripts"), "", 0, _display_add_remove_scripts, 0);
1178 WebcitAddUrlHandler(HKEY("create_script"), "", 0, create_script, 0);
1179 WebcitAddUrlHandler(HKEY("delete_script"), "", 0, delete_script, 0);