5 * \defgroup Sieve view/edit sieve config
6 * \ingroup WebcitDisplayItems
11 #define MAX_SCRIPTS 100
13 #define RULES_SCRIPT "__WebCit_Generated_Script__"
16 * \brief view/edit sieve config
18 void display_sieve(void)
20 char script_names[MAX_SCRIPTS][64];
22 int active_script = (-1);
25 int rules_script_is_active = 0;
28 memset(script_names, 0, sizeof script_names);
30 serv_puts("MSIV listscripts");
31 serv_getln(buf, sizeof(buf));
32 if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
33 if (num_scripts < MAX_SCRIPTS) {
34 extract_token(script_names[num_scripts], buf, 0, '|', 64);
35 if (extract_int(buf, 1) > 0) {
36 active_script = num_scripts;
37 if (!strcasecmp(script_names[num_scripts], RULES_SCRIPT)) {
38 rules_script_is_active = 1;
45 output_headers(1, 1, 2, 0, 0, 0);
47 wprintf("<script type=\"text/javascript\"> \n"
49 "var previously_active_script; \n"
51 "function ToggleSievePanels() { \n"
52 " d = ($('sieveform').bigaction.options[$('sieveform').bigaction.selectedIndex].value); \n"
53 " for (i=0; i<3; ++i) { \n"
55 " $('sievediv' + i).style.display = 'block'; \n"
58 " $('sievediv' + i).style.display = 'none'; \n"
63 "function ToggleScriptPanels() { \n"
64 " d = ($('sieveform').active_script.options[$('sieveform').active_script.selectedIndex].value); \n"
65 " if ($('script_' + previously_active_script)) { \n"
66 " $('script_' + previously_active_script).style.display = 'none'; \n"
68 " $('script_' + d).style.display = 'block'; \n"
69 " previously_active_script = d; \n"
75 wprintf("<div id=\"banner\">\n");
76 wprintf("<TABLE class=\"sieve_banner\"><TR><TD>");
77 wprintf("<SPAN CLASS=\"titlebar\">"
78 "<img src=\"static/advanpage2_48x.gif\">");
79 wprintf(_("View/edit server-side mail filters"));
81 wprintf("</TD></TR></TABLE>\n");
82 wprintf("</div>\n<div id=\"content\">\n");
84 wprintf("<div class=\"fix_scrollbar_bug\">"
85 "<table class=\"sieve_background\">"
86 "<tr><td valign=top>\n");
89 wprintf("<form id=\"sieveform\" method=\"post\" action=\"save_sieve\">\n");
90 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
92 wprintf(_("When new mail arrives: "));
93 wprintf("<select name=\"bigaction\" size=1 onChange=\"ToggleSievePanels();\">\n");
95 wprintf("<option %s value=\"0\">", ((active_script < 0) ? "selected" : ""));
96 wprintf(_("Leave it in my inbox without filtering"));
97 wprintf("</option>\n");
99 wprintf("<option %s value=\"1\">", ((rules_script_is_active) ? "selected" : ""));
100 wprintf(_("Filter it according to rules selected below"));
101 wprintf("</option>\n");
103 wprintf("<option %s value=\"2\">",
104 (((active_script >= 0) && (!rules_script_is_active)) ? "selected" : ""));
105 wprintf(_("Filter it through a manually edited script (advanced users only)"));
106 wprintf("</option>\n");
108 wprintf("</select>");
112 /* The "no filtering" div */
114 wprintf("<div id=\"sievediv0\" style=\"display:none\">\n");
115 wprintf("<div align=\"center\"><br /><br />");
116 wprintf(_("Your incoming mail will not be filtered through any scripts."));
117 wprintf("<br /><br /></div>\n");
120 /* The "webcit managed scripts" div */
122 wprintf("<div id=\"sievediv1\" style=\"display:none\">\n");
123 display_rules_editor_inner_div();
126 /* The "I'm smart and can write my own Sieve scripts" div */
128 wprintf("<div id=\"sievediv2\" style=\"display:none\">\n");
130 if (num_scripts > 0) {
131 wprintf(_("The currently active script is: "));
132 wprintf("<select name=\"active_script\" size=1 onChange=\"ToggleScriptPanels();\">\n");
133 for (i=0; i<num_scripts; ++i) {
134 if (strcasecmp(script_names[i], RULES_SCRIPT)) {
135 wprintf("<option %s value=\"%s\">%s</option>\n",
136 ((active_script == i) ? "selected" : ""),
142 wprintf("</select>\n");
145 wprintf(" ");
146 wprintf("<a href=\"display_add_remove_scripts\">%s</a>\n", _("Add or delete scripts"));
150 if (num_scripts > 0) {
151 for (i=0; i<num_scripts; ++i) {
152 if (strcasecmp(script_names[i], RULES_SCRIPT)) {
153 wprintf("<div id=\"script_%s\" style=\"display:none\">\n", script_names[i]);
154 wprintf("<textarea name=\"text_%s\" wrap=soft rows=20 cols=80 width=80>\n",
156 serv_printf("MSIV getscript|%s", script_names[i]);
157 serv_getln(buf, sizeof buf);
158 if (buf[0] == '1') while(serv_getln(buf, sizeof (buf)), strcmp(buf, "000")) {
159 wprintf("%s\n", buf);
161 wprintf("</textarea>\n");
167 wprintf("<script type=\"text/javascript\"> \n"
168 "ToggleScriptPanels(); \n"
175 /* The rest of this is common for all panels... */
177 wprintf("<div align=\"center\"><br>");
178 wprintf("<input type=\"submit\" name=\"save_button\" value=\"%s\">", _("Save changes"));
180 wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
181 wprintf("</div></form>\n");
183 wprintf("</td></tr></table></div>\n");
185 wprintf("<script type=\"text/javascript\"> \n"
186 "ToggleSievePanels(); \n"
197 * \brief Helper function for output_sieve_rule() to output strings with quotes escaped
199 void osr_sanitize(char *str) {
202 if (str == NULL) return;
204 for (i=0; i<len; ++i) {
208 else if (isspace(str[i])) {
216 * \brief Output parseable Sieve script code based on rules input
218 void output_sieve_rule(char *hfield, char *compare, char *htext, char *sizecomp, int sizeval,
219 char *action, char *fileinto, char *redirect, char *automsg, char *final,
226 osr_sanitize(fileinto);
227 osr_sanitize(redirect);
228 osr_sanitize(automsg);
230 /* Prepare negation and match operators that will be used iff we apply a conditional */
232 if (!strcasecmp(compare, "contains")) {
236 else if (!strcasecmp(compare, "notcontains")) {
240 else if (!strcasecmp(compare, "is")) {
244 else if (!strcasecmp(compare, "isnot")) {
248 else if (!strcasecmp(compare, "matches")) {
252 else if (!strcasecmp(compare, "notmatches")) {
257 /* Now do the conditional */
259 if (!strcasecmp(hfield, "from")) {
260 serv_printf("if%s header %s \"From\" \"%s\"",
266 else if (!strcasecmp(hfield, "tocc")) {
267 serv_printf("if%s header %s [\"To\", \"Cc\"] \"%s\"",
273 else if (!strcasecmp(hfield, "subject")) {
274 serv_printf("if%s header %s \"Subject\" \"%s\"",
280 else if (!strcasecmp(hfield, "replyto")) {
281 serv_printf("if%s header %s \"Reply-to\" \"%s\"",
287 else if (!strcasecmp(hfield, "sender")) {
288 serv_printf("if%s header %s \"Sender\" \"%s\"",
294 else if (!strcasecmp(hfield, "resentfrom")) {
295 serv_printf("if%s header %s \"Resent-from\" \"%s\"",
301 else if (!strcasecmp(hfield, "resentto")) {
302 serv_printf("if%s header %s \"Resent-to\" \"%s\"",
308 else if (!strcasecmp(hfield, "xmailer")) {
309 serv_printf("if%s header %s \"X-Mailer\" \"%s\"",
315 else if (!strcasecmp(hfield, "xspamflag")) {
316 serv_printf("if%s header %s \"X-Spam-Flag\" \"%s\"",
322 else if (!strcasecmp(hfield, "xspamstatus")) {
323 serv_printf("if%s header %s \"X-Spam-Status\" \"%s\"",
329 else if (!strcasecmp(hfield, "envfrom")) {
330 serv_printf("if%s envelope %s \"From\" \"%s\"",
336 else if (!strcasecmp(hfield, "envto")) {
337 serv_printf("if%s envelope %s \"To\" \"%s\"",
343 else if (!strcasecmp(hfield, "size")) {
344 if (!strcasecmp(sizecomp, "larger")) {
345 serv_printf("if size :over %d", sizeval);
347 else if (!strcasecmp(sizecomp, "smaller")) {
348 serv_printf("if size :under %d", sizeval);
350 else { /* failsafe - should never get here, but just in case... */
351 serv_printf("if size :over 1");
355 /* Open braces if we're in a conditional loop */
357 if (strcasecmp(hfield, "all")) {
364 if (!strcasecmp(action, "keep")) {
365 serv_printf("keep;");
368 else if (!strcasecmp(action, "discard")) {
369 serv_printf("discard;");
372 else if (!strcasecmp(action, "reject")) {
373 serv_printf("reject \"%s\";", automsg);
376 else if (!strcasecmp(action, "fileinto")) {
377 serv_printf("fileinto \"%s\";", fileinto);
380 else if (!strcasecmp(action, "redirect")) {
381 serv_printf("redirect \"%s\";", redirect);
384 else if (!strcasecmp(action, "vacation")) {
385 serv_printf("vacation :addresses [%s]\n\"%s\";", my_addresses, automsg);
389 /* Do 'final' action */
391 if (!strcasecmp(final, "stop")) {
392 serv_printf("stop;");
396 /* Close the braces if we're in a conditional loop */
398 if (strcasecmp(hfield, "all")) {
409 * \brief Translate the fields from the rule editor into something we can save...
411 void parse_fields_from_rule_editor(void) {
428 char encoded_rule[4096];
429 char my_addresses[4096];
431 /* Enumerate my email addresses in case they are needed for a vacation rule */
434 serv_getln(buf, sizeof buf);
435 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
436 if (!IsEmptyStr(my_addresses)) {
437 strcat(my_addresses, ",\n");
439 strcat(my_addresses, "\"");
440 strcat(my_addresses, buf);
441 strcat(my_addresses, "\"");
444 /* Now generate the script and write it to the Citadel server */
445 serv_printf("MSIV putscript|%s|", RULES_SCRIPT);
446 serv_getln(buf, sizeof buf);
451 serv_puts("# THIS SCRIPT WAS AUTOMATICALLY GENERATED BY WEBCIT.");
453 serv_puts("# Do not attempt to manually edit it. If you do so,");
454 serv_puts("# your changes will be overwritten the next time WebCit");
455 serv_puts("# saves its mail filtering rule set. If you really want");
456 serv_puts("# to use these rules as the basis for another script,");
457 serv_puts("# copy them to another script and save that instead.");
459 serv_puts("require \"fileinto\";");
460 serv_puts("require \"reject\";");
461 serv_puts("require \"vacation\";");
462 serv_puts("require \"envelope\";");
465 for (i=0; i<MAX_RULES; ++i) {
469 sprintf(fname, "active%d", i);
470 active = !strcasecmp(bstr(fname), "on") ;
474 sprintf(fname, "hfield%d", i);
475 safestrncpy(hfield, bstr(fname), sizeof hfield);
477 sprintf(fname, "compare%d", i);
478 safestrncpy(compare, bstr(fname), sizeof compare);
480 sprintf(fname, "htext%d", i);
481 safestrncpy(htext, bstr(fname), sizeof htext);
483 sprintf(fname, "sizecomp%d", i);
484 safestrncpy(sizecomp, bstr(fname), sizeof sizecomp);
486 sprintf(fname, "sizeval%d", i);
487 sizeval = atoi(bstr(fname));
489 sprintf(fname, "action%d", i);
490 safestrncpy(action, bstr(fname), sizeof action);
492 sprintf(fname, "fileinto%d", i);
493 safestrncpy(fileinto, bstr(fname), sizeof fileinto);
495 sprintf(fname, "redirect%d", i);
496 safestrncpy(redirect, bstr(fname), sizeof redirect);
498 sprintf(fname, "automsg%d", i);
499 safestrncpy(automsg, bstr(fname), sizeof automsg);
501 sprintf(fname, "final%d", i);
502 safestrncpy(final, bstr(fname), sizeof final);
504 snprintf(rule, sizeof rule, "%d|%s|%s|%s|%s|%d|%s|%s|%s|%s|%s",
505 active, hfield, compare, htext, sizecomp, sizeval, action, fileinto,
506 redirect, automsg, final
509 CtdlEncodeBase64(encoded_rule, rule, strlen(rule)+1, 0);
510 serv_printf("# WEBCIT_RULE|%d|%s|", i, encoded_rule);
511 output_sieve_rule(hfield, compare, htext, sizecomp, sizeval,
512 action, fileinto, redirect, automsg, final, my_addresses);
527 * \brief save sieve config
529 void save_sieve(void) {
531 char script_names[MAX_SCRIPTS][64];
533 int active_script = (-1);
538 if (IsEmptyStr(bstr("save_button"))) {
539 strcpy(WC->ImportantMessage,
540 _("Cancelled. Changes were not saved."));
545 parse_fields_from_rule_editor();
547 serv_puts("MSIV listscripts");
548 serv_getln(buf, sizeof(buf));
549 if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
550 if (num_scripts < MAX_SCRIPTS) {
551 extract_token(script_names[num_scripts], buf, 0, '|', 64);
552 if (extract_int(buf, 1) > 0) {
553 active_script = num_scripts;
559 bigaction = atoi(bstr("bigaction"));
561 if (bigaction == 0) {
562 serv_puts("MSIV setactive||");
563 serv_getln(buf, sizeof buf);
566 else if (bigaction == 1) {
567 serv_printf("MSIV setactive|%s|", RULES_SCRIPT);
568 serv_getln(buf, sizeof buf);
571 else if (bigaction == 2) {
572 serv_printf("MSIV setactive|%s|", bstr("active_script"));
573 serv_getln(buf, sizeof buf);
576 if (num_scripts > 0) {
577 for (i=0; i<num_scripts; ++i) {
579 * We only want to save the scripts from the "manually edited scripts"
580 * screen. The script that WebCit generates from its ruleset will be
581 * auto-generated by parse_fields_from_rule_editor() and saved there.
583 if (strcasecmp(script_names[i], RULES_SCRIPT)) {
584 serv_printf("MSIV putscript|%s|", script_names[i]);
585 serv_getln(buf, sizeof buf);
587 snprintf(this_name, sizeof this_name, "text_%s", script_names[i]);
588 striplt(bstr(this_name));
589 serv_printf("%s", bstr(this_name));
596 strcpy(WC->ImportantMessage, _("Your changes have been saved."));
603 * \brief show a list of available scripts to add/remove them
605 void display_add_remove_scripts(char *message)
608 char script_name[256];
610 output_headers(1, 1, 2, 0, 0, 0);
611 wprintf("<div id=\"banner\">\n");
612 wprintf("<table class=\"sieve_banner\"><tr>"
614 "<span class=\"titlebar\">"
615 "<img src=\"static/advanpage2_48x.gif\">");
616 wprintf(_("Add or delete scripts"));
617 wprintf("</span></td></tr></table>\n"
618 "</div>\n<div id=\"content\">\n"
621 if (message != NULL) wprintf(message);
623 wprintf("<table border=0 cellspacing=10><tr valign=top><td>\n");
625 svprintf("BOXTITLE", WCS_STRING, _("Add a new script"));
626 do_template("beginbox");
628 wprintf(_("To create a new script, enter the desired "
629 "script name in the box below and click 'Create'."));
630 wprintf("<br /><br />");
632 wprintf("<center><form method=\"POST\" action=\"create_script\">\n");
633 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
634 wprintf(_("Script name: "));
635 wprintf("<input type=\"text\" name=\"script_name\"><br />\n"
636 "<input type=\"submit\" name=\"create_button\" value=\"%s\">"
637 "</form></center>\n", _("Create"));
639 do_template("endbox");
641 svprintf("BOXTITLE", WCS_STRING, _("Edit scripts"));
642 do_template("beginbox");
643 wprintf("<br /><div align=center><a href=\"display_sieve\">%s</a><br /><br />\n",
644 _("Return to the script editing screen")
646 do_template("endbox");
648 wprintf("</td><td>");
650 svprintf("BOXTITLE", WCS_STRING, _("Delete scripts"));
651 do_template("beginbox");
653 wprintf(_("To delete an existing script, select the script "
654 "name from the list and click 'Delete'."));
655 wprintf("<br /><br />");
658 "<form method=\"POST\" action=\"delete_script\">\n");
659 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
660 wprintf("<select name=\"script_name\" size=10 style=\"width:100%%\">\n");
662 serv_puts("MSIV listscripts");
663 serv_getln(buf, sizeof buf);
665 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
666 extract_token(script_name, buf, 0, '|', sizeof script_name);
667 if ( (extract_int(buf, 1) == 0) && (strcasecmp(script_name, RULES_SCRIPT)) ) {
669 escputs(script_name);
670 wprintf("</option>\n");
674 wprintf("</select><br />\n");
676 wprintf("<input type=\"submit\" name=\"delete_button\" value=\"%s\" "
677 "onClick=\"return confirm('%s');\">", _("Delete script"), _("Delete this script?"));
678 wprintf("</form></center>\n");
679 do_template("endbox");
681 wprintf("</td></tr></table>\n");
689 * \brief delete a script
691 void delete_script(void) {
694 serv_printf("MSIV deletescript|%s", bstr("script_name"));
695 serv_getln(buf, sizeof buf);
696 display_add_remove_scripts(&buf[4]);
702 * \brief create a new script
703 * take the web environment script name and create it on the citadel server
705 void create_script(void) {
708 serv_printf("MSIV getscript|%s", bstr("script_name"));
709 serv_getln(buf, sizeof buf);
711 while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
714 display_add_remove_scripts(_("A script by that name already exists."));
718 serv_printf("MSIV putscript|%s", bstr("script_name"));
719 serv_getln(buf, sizeof buf);
723 display_add_remove_scripts(_("A new script has been created. Return to the script editing screen to edit and activate it."));
727 display_add_remove_scripts(&buf[4]);
733 void display_rules_editor_inner_div(void) {
736 char rules[MAX_RULES][2048];
741 int num_roomnames = 0;
742 int num_roomnames_alloc = 0;
757 memset(rules, 0, sizeof rules);
758 serv_printf("MSIV getscript|%s", RULES_SCRIPT);
759 serv_getln(buf, sizeof buf);
760 if (buf[0] == '1') while(serv_getln(buf, sizeof (buf)), strcmp(buf, "000")) {
761 if (!strncasecmp(buf, "# WEBCIT_RULE|", 14)) {
762 j = extract_int(buf, 1);
763 remove_token(buf, 0, '|');
764 remove_token(buf, 0, '|');
765 CtdlDecodeBase64(rules[j], buf, strlen(buf));
769 /* load the roomnames */
771 serv_getln(buf, sizeof buf);
773 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
775 if (num_roomnames > num_roomnames_alloc) {
776 num_roomnames_alloc += 250;
777 rooms = realloc(rooms, (num_roomnames_alloc * 128));
779 extract_token(rooms[num_roomnames-1].name, buf, 0, '|', 128);
785 * This script should get called by every onChange event...
788 wprintf("<script type=\"text/javascript\"> \n"
790 "var highest_active_rule = (-1); \n"
792 "function UpdateRules() { \n");
794 * Show only the active rows...
796 wprintf(" highest_active_rule = (-1); \n");
797 wprintf(" for (i=0; i<%d; ++i) { \n", MAX_RULES);
798 wprintf(" if ($('active'+i).checked) { \n"
799 " $('rule' + i).style.display = 'block'; \n"
800 " highest_active_rule = i; \n"
803 " $('rule' + i).style.display = 'none'; \n"
807 * Show only the fields relevant to the rules...
809 wprintf(" for (i=0; i<=highest_active_rule; ++i) { \n"
810 " d = ($('movedown'+i)); \n"
811 " if (i < highest_active_rule) { \n"
812 " d.style.display = 'block'; \n"
815 " d.style.display = 'none'; \n"
817 " d = ($('hfield'+i).options[$('hfield'+i).selectedIndex].value); \n"
818 " if (d == 'all') { \n"
819 " $('div_size'+i).style.display = 'none'; \n"
820 " $('div_compare'+i).style.display = 'none'; \n"
821 " $('div_nocompare'+i).style.display = 'block'; \n"
823 " else if (d == 'size') { \n"
824 " $('div_size'+i).style.display = 'block'; \n"
825 " $('div_compare'+i).style.display = 'none'; \n"
826 " $('div_nocompare'+i).style.display = 'none'; \n"
829 " $('div_size'+i).style.display = 'none'; \n"
830 " $('div_compare'+i).style.display = 'block'; \n"
831 " $('div_nocompare'+i).style.display = 'none'; \n"
833 " d = ($('action'+i).options[$('action'+i).selectedIndex].value); \n"
834 " if (d == 'fileinto') { \n"
835 " $('div_fileinto'+i).style.display = 'block'; \n"
836 " $('div_redirect'+i).style.display = 'none'; \n"
837 " $('div_automsg'+i).style.display = 'none'; \n"
838 " } else if (d == 'redirect') { \n"
839 " $('div_fileinto'+i).style.display = 'none'; \n"
840 " $('div_redirect'+i).style.display = 'block'; \n"
841 " $('div_automsg'+i).style.display = 'none'; \n"
842 " } else if ((d == 'reject') || (d == 'vacation')) { \n"
843 " $('div_fileinto'+i).style.display = 'none'; \n"
844 " $('div_redirect'+i).style.display = 'none'; \n"
845 " $('div_automsg'+i).style.display = 'block'; \n"
847 " $('div_fileinto'+i).style.display = 'none'; \n"
848 " $('div_redirect'+i).style.display = 'none'; \n"
849 " $('div_automsg'+i).style.display = 'none'; \n"
851 " if (highest_active_rule < %d) { \n", MAX_RULES-1 );
852 wprintf(" $('div_addrule').style.display = 'block'; \n"
854 " $('div_addrule').style.display = 'none'; \n"
859 * Add a rule (really, just un-hide it)
861 "function AddRule() { \n"
862 " highest_active_rule = highest_active_rule + 1; \n"
863 " $('active'+highest_active_rule).checked = true; \n"
869 "function SwapRules(ra, rb) { \n"
871 " var things = new Array(); \n"
872 " things[0] = 'hfield'; \n"
873 " things[1] = 'compare'; \n"
874 " things[2] = 'htext'; \n"
875 " things[3] = 'action'; \n"
876 " things[4] = 'fileinto'; \n"
877 " things[5] = 'redirect'; \n"
878 " things[6] = 'final'; \n"
879 " things[7] = 'sizecomp'; \n"
880 " things[8] = 'sizeval'; \n"
881 " things[9] = 'automsg'; \n"
883 " for (i=0; i<=9; ++i) { \n"
884 " tempval=$(things[i]+ra).value; \n"
885 " $(things[i]+ra).value = $(things[i]+rb).value; \n"
886 " $(things[i]+rb).value = tempval; \n"
890 * Delete a rule (percolate the deleted rule out to the end, then deactivate it)
892 "function DeleteRule(rd) { \n"
893 " for (j=rd; j<=highest_active_rule; ++j) { \n"
894 " SwapRules(j, (j+1)); \n"
896 " $('active'+highest_active_rule).checked = false; \n"
904 wprintf("<table cellpadding=2 width=100%%>");
906 for (i=0; i<MAX_RULES; ++i) {
908 /* Grab our existing values to populate */
909 active = extract_int(rules[i], 0);
910 extract_token(hfield, rules[i], 1, '|', sizeof hfield);
911 extract_token(compare, rules[i], 2, '|', sizeof compare);
912 extract_token(htext, rules[i], 3, '|', sizeof htext);
913 extract_token(sizecomp, rules[i], 4, '|', sizeof sizecomp);
914 sizeval = extract_int(rules[i], 5);
915 extract_token(action, rules[i], 6, '|', sizeof action);
916 extract_token(fileinto, rules[i], 7, '|', sizeof fileinto);
917 extract_token(redirect, rules[i], 8, '|', sizeof redirect);
918 extract_token(automsg, rules[i], 9, '|', sizeof automsg);
919 extract_token(final, rules[i], 10, '|', sizeof final);
921 /* now generate the table row */
923 wprintf("<tr id=\"rule%d\" bgcolor=\"#%s\">",
925 ((i%2) ? "DDDDDD" : "FFFFFF")
928 wprintf("<td width=5%% align=\"center\">");
930 wprintf("<div style=\"display:none\">");
931 wprintf("<input type=\"checkbox\" name=\"active%d\" id=\"active%d\" %s>",
933 (active ? "checked" : "")
937 if (i>0) wprintf("<a href=\"javascript:SwapRules(%d,%d);UpdateRules();\">"
938 "<img border=\"0\" src=\"static/up_pointer.gif\" "
939 "title=\"%s\"/></a>",
940 i-1, i, _("Move rule up") );
942 wprintf("<a href=\"javascript:SwapRules(%d,%d);UpdateRules();\">"
943 "<img id=\"movedown%d\" border=\"0\" src=\"static/down_pointer.gif\" "
944 "title=\"%s\"/></a>",
945 i, i+1, i, _("Move rule down") );
947 wprintf("<a href=\"javascript:DeleteRule(%d);UpdateRules();\">"
948 "<img id=\"delete%d\" border=\"0\" src=\"static/delete.gif\" "
949 "title=\"%s\"/></a>",
950 i, i, _("Delete rule") );
954 wprintf("<td width=5%% align=\"center\">");
955 wprintf("<font size=+2>%d</font>", i+1);
958 wprintf("<td width=20%%>%s ", _("If") );
960 char *hfield_values[14][2] = {
961 { "from", _("From") },
962 { "tocc", _("To or Cc") },
963 { "subject", _("Subject") },
964 { "replyto", _("Reply-to") },
965 { "sender", _("Sender") },
966 { "resentfrom", _("Resent-From") },
967 { "resentto", _("Resent-To") },
968 { "envfrom", _("Envelope From") },
969 { "envto", _("Envelope To") },
970 { "xmailer", _("X-Mailer") },
971 { "xspamflag", _("X-Spam-Flag") },
972 { "xspamstatus", _("X-Spam-Status") },
973 { "size", _("Message size") },
977 wprintf("<select id=\"hfield%d\" name=\"hfield%d\" size=1 onChange=\"UpdateRules();\">",
979 for (j=0; j<14; ++j) {
980 wprintf("<option %s value=\"%s\">%s</option>",
981 ( (!strcasecmp(hfield, hfield_values[j][0])) ? "selected" : ""),
987 wprintf("</select>");
990 wprintf("<td width=20%%>");
992 char *compare_values[6][2] = {
993 { "contains", _("contains") },
994 { "notcontains", _("does not contain") },
996 { "isnot", _("is not") },
997 { "matches", _("matches") },
998 { "notmatches", _("does not match") }
1001 wprintf("<div id=\"div_compare%d\">", i);
1002 wprintf("<select id=\"compare%d\" name=\"compare%d\" size=1 onChange=\"UpdateRules();\">",
1004 for (j=0; j<6; ++j) {
1005 wprintf("<option %s value=\"%s\">%s</option>",
1006 ( (!strcasecmp(compare, compare_values[j][0])) ? "selected" : ""),
1007 compare_values[j][0],
1008 compare_values[j][1]
1011 wprintf("</select>");
1013 wprintf("<input type=\"text\" id=\"htext%d\" name=\"htext%d\" value=\"", i, i);
1015 wprintf("\"></div>");
1017 wprintf("<div id=\"div_nocompare%d\">", i);
1018 wprintf("%s", _("(All messages)"));
1021 char *sizecomp_values[2][2] = {
1022 { "larger", _("is larger than") },
1023 { "smaller", _("is smaller than") }
1026 wprintf("<div id=\"div_size%d\">", i);
1027 wprintf("<select id=\"sizecomp%d\" name=\"sizecomp%d\" size=1 onChange=\"UpdateRules();\">",
1029 for (j=0; j<2; ++j) {
1030 wprintf("<option %s value=\"%s\">%s</option>",
1031 ( (!strcasecmp(sizecomp, sizecomp_values[j][0])) ? "selected" : ""),
1032 sizecomp_values[j][0],
1033 sizecomp_values[j][1]
1036 wprintf("</select>");
1038 wprintf("<input type=\"text\" id=\"sizeval%d\" name=\"sizeval%d\" value=\"%d\">",
1045 char *action_values[6][2] = {
1046 { "keep", _("Keep") },
1047 { "discard", _("Discard silently") },
1048 { "reject", _("Reject") },
1049 { "fileinto", _("Move message to") },
1050 { "redirect", _("Forward to") },
1051 { "vacation", _("Vacation") }
1054 wprintf("<td width=20%%>");
1055 wprintf("<select id=\"action%d\" name=\"action%d\" size=1 onChange=\"UpdateRules();\">",
1057 for (j=0; j<6; ++j) {
1058 wprintf("<option %s value=\"%s\">%s</option>",
1059 ( (!strcasecmp(action, action_values[j][0])) ? "selected" : ""),
1060 action_values[j][0],
1064 wprintf("</select>");
1066 wprintf("<div id=\"div_fileinto%d\">", i);
1067 wprintf("<select name=\"fileinto%d\" id=\"fileinto%d\">", i, i);
1068 for (j=0; j<num_roomnames; ++j) {
1069 wprintf("<option ");
1070 if (!strcasecmp(rooms[j].name, fileinto)) {
1071 wprintf("selected ");
1073 wprintf("value=\"");
1074 escputs(rooms[j].name);
1076 escputs(rooms[j].name);
1077 wprintf("</option>\n");
1079 wprintf("</select>\n");
1082 wprintf("<div id=\"div_redirect%d\">", i);
1083 wprintf("<input type=\"text\" id=\"redirect%d\" name=\"redirect%d\" value=\"", i, i);
1085 wprintf("\"></div>");
1087 wprintf("<div id=\"div_automsg%d\">", i);
1088 wprintf(_("Message:"));
1090 wprintf("<textarea name=\"automsg%d\" id=\"automsg%d\" wrap=soft rows=5>\n", i, i);
1092 wprintf("</textarea>");
1097 char *final_values[2][2] = {
1098 { "continue", _("continue processing") },
1099 { "stop", _("stop") }
1102 wprintf("<td width=10%% align=\"center\">%s</td>", _("and then") );
1104 wprintf("<td width=20%%>");
1105 wprintf("<select name=\"final%d\" id=\"final%d\" size=1 onChange=\"UpdateRules();\">",
1107 for (j=0; j<2; ++j) {
1108 wprintf("<option %s value=\"%s\">%s</option>",
1109 ( (!strcasecmp(final, final_values[j][0])) ? "selected" : ""),
1114 wprintf("</select>");
1121 wprintf("</table>");
1122 wprintf("<div id=\"div_addrule\"><a href=\"javascript:AddRule();\">%s</a><br /></div>\n",
1126 wprintf("<script type=\"text/javascript\"> \n");
1127 wprintf("UpdateRules(); \n");
1128 wprintf("</script> \n");