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("<img src=\"static/advanpage2_48x.gif\">");
78 wprintf(_("View/edit server-side mail filters"));
82 wprintf("<div id=\"content\" class=\"service\">\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) {
429 char my_addresses[4096];
433 encoded_rule = (char*) malloc (encoded_len);
434 /* Enumerate my email addresses in case they are needed for a vacation rule */
437 serv_getln(buf, sizeof buf);
438 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
439 if (!IsEmptyStr(my_addresses)) {
440 strcat(my_addresses, ",\n");
442 strcat(my_addresses, "\"");
443 strcat(my_addresses, buf);
444 strcat(my_addresses, "\"");
447 /* Now generate the script and write it to the Citadel server */
448 serv_printf("MSIV putscript|%s|", RULES_SCRIPT);
449 serv_getln(buf, sizeof buf);
454 serv_puts("# THIS SCRIPT WAS AUTOMATICALLY GENERATED BY WEBCIT.");
456 serv_puts("# Do not attempt to manually edit it. If you do so,");
457 serv_puts("# your changes will be overwritten the next time WebCit");
458 serv_puts("# saves its mail filtering rule set. If you really want");
459 serv_puts("# to use these rules as the basis for another script,");
460 serv_puts("# copy them to another script and save that instead.");
462 serv_puts("require \"fileinto\";");
463 serv_puts("require \"reject\";");
464 serv_puts("require \"vacation\";");
465 serv_puts("require \"envelope\";");
468 for (i=0; i<MAX_RULES; ++i) {
472 sprintf(fname, "active%d", i);
473 active = !strcasecmp(bstr(fname), "on") ;
477 sprintf(fname, "hfield%d", i);
478 safestrncpy(hfield, bstr(fname), sizeof hfield);
480 sprintf(fname, "compare%d", i);
481 safestrncpy(compare, bstr(fname), sizeof compare);
483 sprintf(fname, "htext%d", i);
484 safestrncpy(htext, bstr(fname), sizeof htext);
486 sprintf(fname, "sizecomp%d", i);
487 safestrncpy(sizecomp, bstr(fname), sizeof sizecomp);
489 sprintf(fname, "sizeval%d", i);
490 sizeval = atoi(bstr(fname));
492 sprintf(fname, "action%d", i);
493 safestrncpy(action, bstr(fname), sizeof action);
495 sprintf(fname, "fileinto%d", i);
496 safestrncpy(fileinto, bstr(fname), sizeof fileinto);
498 sprintf(fname, "redirect%d", i);
499 safestrncpy(redirect, bstr(fname), sizeof redirect);
501 sprintf(fname, "automsg%d", i);
502 safestrncpy(automsg, bstr(fname), sizeof automsg);
504 sprintf(fname, "final%d", i);
505 safestrncpy(final, bstr(fname), sizeof final);
507 snprintf(rule, sizeof rule, "%d|%s|%s|%s|%s|%d|%s|%s|%s|%s|%s",
508 active, hfield, compare, htext, sizecomp, sizeval, action, fileinto,
509 redirect, automsg, final
512 CtdlEncodeBase64(&encoded_rule, rule, strlen(rule)+1, &encoded_len, 0);
513 serv_printf("# WEBCIT_RULE|%d|%s|", i, encoded_rule);
514 output_sieve_rule(hfield, compare, htext, sizecomp, sizeval,
515 action, fileinto, redirect, automsg, final, my_addresses);
530 * \brief save sieve config
532 void save_sieve(void) {
534 char script_names[MAX_SCRIPTS][64];
536 int active_script = (-1);
541 if (IsEmptyStr(bstr("save_button"))) {
542 strcpy(WC->ImportantMessage,
543 _("Cancelled. Changes were not saved."));
548 parse_fields_from_rule_editor();
550 serv_puts("MSIV listscripts");
551 serv_getln(buf, sizeof(buf));
552 if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
553 if (num_scripts < MAX_SCRIPTS) {
554 extract_token(script_names[num_scripts], buf, 0, '|', 64);
555 if (extract_int(buf, 1) > 0) {
556 active_script = num_scripts;
562 bigaction = atoi(bstr("bigaction"));
564 if (bigaction == 0) {
565 serv_puts("MSIV setactive||");
566 serv_getln(buf, sizeof buf);
569 else if (bigaction == 1) {
570 serv_printf("MSIV setactive|%s|", RULES_SCRIPT);
571 serv_getln(buf, sizeof buf);
574 else if (bigaction == 2) {
575 serv_printf("MSIV setactive|%s|", bstr("active_script"));
576 serv_getln(buf, sizeof buf);
579 if (num_scripts > 0) {
580 for (i=0; i<num_scripts; ++i) {
582 * We only want to save the scripts from the "manually edited scripts"
583 * screen. The script that WebCit generates from its ruleset will be
584 * auto-generated by parse_fields_from_rule_editor() and saved there.
586 if (strcasecmp(script_names[i], RULES_SCRIPT)) {
587 serv_printf("MSIV putscript|%s|", script_names[i]);
588 serv_getln(buf, sizeof buf);
590 snprintf(this_name, sizeof this_name, "text_%s", script_names[i]);
591 striplt(bstr(this_name));
592 serv_printf("%s", bstr(this_name));
599 strcpy(WC->ImportantMessage, _("Your changes have been saved."));
606 * \brief show a list of available scripts to add/remove them
608 void display_add_remove_scripts(char *message)
611 char script_name[256];
613 output_headers(1, 1, 2, 0, 0, 0);
614 wprintf("<div id=\"banner\">\n");
615 wprintf("<img src=\"static/advanpage2_48x.gif\">");
616 wprintf(_("Add or delete scripts"));
620 wprintf("<div id=\"content\" class=\"service\">\n");
622 if (message != NULL) wprintf(message);
624 wprintf("<table border=0 cellspacing=10><tr valign=top><td>\n");
626 svprintf("BOXTITLE", WCS_STRING, _("Add a new script"));
627 do_template("beginbox");
629 wprintf(_("To create a new script, enter the desired "
630 "script name in the box below and click 'Create'."));
631 wprintf("<br /><br />");
633 wprintf("<center><form method=\"POST\" action=\"create_script\">\n");
634 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
635 wprintf(_("Script name: "));
636 wprintf("<input type=\"text\" name=\"script_name\"><br />\n"
637 "<input type=\"submit\" name=\"create_button\" value=\"%s\">"
638 "</form></center>\n", _("Create"));
640 do_template("endbox");
642 svprintf("BOXTITLE", WCS_STRING, _("Edit scripts"));
643 do_template("beginbox");
644 wprintf("<br /><div align=center><a href=\"display_sieve\">%s</a><br /><br />\n",
645 _("Return to the script editing screen")
647 do_template("endbox");
649 wprintf("</td><td>");
651 svprintf("BOXTITLE", WCS_STRING, _("Delete scripts"));
652 do_template("beginbox");
654 wprintf(_("To delete an existing script, select the script "
655 "name from the list and click 'Delete'."));
656 wprintf("<br /><br />");
659 "<form method=\"POST\" action=\"delete_script\">\n");
660 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
661 wprintf("<select name=\"script_name\" size=10 style=\"width:100%%\">\n");
663 serv_puts("MSIV listscripts");
664 serv_getln(buf, sizeof buf);
666 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
667 extract_token(script_name, buf, 0, '|', sizeof script_name);
668 if ( (extract_int(buf, 1) == 0) && (strcasecmp(script_name, RULES_SCRIPT)) ) {
670 escputs(script_name);
671 wprintf("</option>\n");
675 wprintf("</select><br />\n");
677 wprintf("<input type=\"submit\" name=\"delete_button\" value=\"%s\" "
678 "onClick=\"return confirm('%s');\">", _("Delete script"), _("Delete this script?"));
679 wprintf("</form></center>\n");
680 do_template("endbox");
682 wprintf("</td></tr></table>\n");
690 * \brief delete a script
692 void delete_script(void) {
695 serv_printf("MSIV deletescript|%s", bstr("script_name"));
696 serv_getln(buf, sizeof buf);
697 display_add_remove_scripts(&buf[4]);
703 * \brief create a new script
704 * take the web environment script name and create it on the citadel server
706 void create_script(void) {
709 serv_printf("MSIV getscript|%s", bstr("script_name"));
710 serv_getln(buf, sizeof buf);
712 while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
715 display_add_remove_scripts(_("A script by that name already exists."));
719 serv_printf("MSIV putscript|%s", bstr("script_name"));
720 serv_getln(buf, sizeof buf);
724 display_add_remove_scripts(_("A new script has been created. Return to the script editing screen to edit and activate it."));
728 display_add_remove_scripts(&buf[4]);
734 void display_rules_editor_inner_div(void) {
737 char rules[MAX_RULES][2048];
742 int num_roomnames = 0;
743 int num_roomnames_alloc = 0;
758 memset(rules, 0, sizeof rules);
759 serv_printf("MSIV getscript|%s", RULES_SCRIPT);
760 serv_getln(buf, sizeof buf);
761 if (buf[0] == '1') while(serv_getln(buf, sizeof (buf)), strcmp(buf, "000")) {
762 if (!strncasecmp(buf, "# WEBCIT_RULE|", 14)) {
763 j = extract_int(buf, 1);
764 remove_token(buf, 0, '|');
765 remove_token(buf, 0, '|');
766 CtdlDecodeBase64(rules[j], buf, strlen(buf));
770 /* load the roomnames */
772 serv_getln(buf, sizeof buf);
774 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
776 if (num_roomnames > num_roomnames_alloc) {
777 num_roomnames_alloc += 250;
778 rooms = realloc(rooms, (num_roomnames_alloc * 128));
780 extract_token(rooms[num_roomnames-1].name, buf, 0, '|', 128);
786 * This script should get called by every onChange event...
789 wprintf("<script type=\"text/javascript\"> \n"
791 "var highest_active_rule = (-1); \n"
793 "function UpdateRules() { \n");
795 * Show only the active rows...
797 wprintf(" highest_active_rule = (-1); \n");
798 wprintf(" for (i=0; i<%d; ++i) { \n", MAX_RULES);
799 wprintf(" if ($('active'+i).checked) { \n"
800 " $('rule' + i).style.display = 'block'; \n"
801 " highest_active_rule = i; \n"
804 " $('rule' + i).style.display = 'none'; \n"
808 * Show only the fields relevant to the rules...
810 wprintf(" for (i=0; i<=highest_active_rule; ++i) { \n"
811 " d = ($('movedown'+i)); \n"
812 " if (i < highest_active_rule) { \n"
813 " d.style.display = 'block'; \n"
816 " d.style.display = 'none'; \n"
818 " d = ($('hfield'+i).options[$('hfield'+i).selectedIndex].value); \n"
819 " if (d == 'all') { \n"
820 " $('div_size'+i).style.display = 'none'; \n"
821 " $('div_compare'+i).style.display = 'none'; \n"
822 " $('div_nocompare'+i).style.display = 'block'; \n"
824 " else if (d == 'size') { \n"
825 " $('div_size'+i).style.display = 'block'; \n"
826 " $('div_compare'+i).style.display = 'none'; \n"
827 " $('div_nocompare'+i).style.display = 'none'; \n"
830 " $('div_size'+i).style.display = 'none'; \n"
831 " $('div_compare'+i).style.display = 'block'; \n"
832 " $('div_nocompare'+i).style.display = 'none'; \n"
834 " d = ($('action'+i).options[$('action'+i).selectedIndex].value); \n"
835 " if (d == 'fileinto') { \n"
836 " $('div_fileinto'+i).style.display = 'block'; \n"
837 " $('div_redirect'+i).style.display = 'none'; \n"
838 " $('div_automsg'+i).style.display = 'none'; \n"
839 " } else if (d == 'redirect') { \n"
840 " $('div_fileinto'+i).style.display = 'none'; \n"
841 " $('div_redirect'+i).style.display = 'block'; \n"
842 " $('div_automsg'+i).style.display = 'none'; \n"
843 " } else if ((d == 'reject') || (d == 'vacation')) { \n"
844 " $('div_fileinto'+i).style.display = 'none'; \n"
845 " $('div_redirect'+i).style.display = 'none'; \n"
846 " $('div_automsg'+i).style.display = 'block'; \n"
848 " $('div_fileinto'+i).style.display = 'none'; \n"
849 " $('div_redirect'+i).style.display = 'none'; \n"
850 " $('div_automsg'+i).style.display = 'none'; \n"
852 " if (highest_active_rule < %d) { \n", MAX_RULES-1 );
853 wprintf(" $('div_addrule').style.display = 'block'; \n"
855 " $('div_addrule').style.display = 'none'; \n"
860 * Add a rule (really, just un-hide it)
862 "function AddRule() { \n"
863 " highest_active_rule = highest_active_rule + 1; \n"
864 " $('active'+highest_active_rule).checked = true; \n"
870 "function SwapRules(ra, rb) { \n"
872 " var things = new Array(); \n"
873 " things[0] = 'hfield'; \n"
874 " things[1] = 'compare'; \n"
875 " things[2] = 'htext'; \n"
876 " things[3] = 'action'; \n"
877 " things[4] = 'fileinto'; \n"
878 " things[5] = 'redirect'; \n"
879 " things[6] = 'final'; \n"
880 " things[7] = 'sizecomp'; \n"
881 " things[8] = 'sizeval'; \n"
882 " things[9] = 'automsg'; \n"
884 " for (i=0; i<=9; ++i) { \n"
885 " tempval=$(things[i]+ra).value; \n"
886 " $(things[i]+ra).value = $(things[i]+rb).value; \n"
887 " $(things[i]+rb).value = tempval; \n"
891 * Delete a rule (percolate the deleted rule out to the end, then deactivate it)
893 "function DeleteRule(rd) { \n"
894 " for (j=rd; j<=highest_active_rule; ++j) { \n"
895 " SwapRules(j, (j+1)); \n"
897 " $('active'+highest_active_rule).checked = false; \n"
905 wprintf("<table cellpadding=2 width=100%%>");
907 for (i=0; i<MAX_RULES; ++i) {
909 /* Grab our existing values to populate */
910 active = extract_int(rules[i], 0);
911 extract_token(hfield, rules[i], 1, '|', sizeof hfield);
912 extract_token(compare, rules[i], 2, '|', sizeof compare);
913 extract_token(htext, rules[i], 3, '|', sizeof htext);
914 extract_token(sizecomp, rules[i], 4, '|', sizeof sizecomp);
915 sizeval = extract_int(rules[i], 5);
916 extract_token(action, rules[i], 6, '|', sizeof action);
917 extract_token(fileinto, rules[i], 7, '|', sizeof fileinto);
918 extract_token(redirect, rules[i], 8, '|', sizeof redirect);
919 extract_token(automsg, rules[i], 9, '|', sizeof automsg);
920 extract_token(final, rules[i], 10, '|', sizeof final);
922 /* now generate the table row */
924 wprintf("<tr id=\"rule%d\" bgcolor=\"#%s\">",
926 ((i%2) ? "DDDDDD" : "FFFFFF")
929 wprintf("<td width=5%% align=\"center\">");
931 wprintf("<div style=\"display:none\">");
932 wprintf("<input type=\"checkbox\" name=\"active%d\" id=\"active%d\" %s>",
934 (active ? "checked" : "")
938 if (i>0) wprintf("<a href=\"javascript:SwapRules(%d,%d);UpdateRules();\">"
939 "<img border=\"0\" src=\"static/up_pointer.gif\" "
940 "title=\"%s\"/></a>",
941 i-1, i, _("Move rule up") );
943 wprintf("<a href=\"javascript:SwapRules(%d,%d);UpdateRules();\">"
944 "<img id=\"movedown%d\" border=\"0\" src=\"static/down_pointer.gif\" "
945 "title=\"%s\"/></a>",
946 i, i+1, i, _("Move rule down") );
948 wprintf("<a href=\"javascript:DeleteRule(%d);UpdateRules();\">"
949 "<img id=\"delete%d\" border=\"0\" src=\"static/delete.gif\" "
950 "title=\"%s\"/></a>",
951 i, i, _("Delete rule") );
955 wprintf("<td width=5%% align=\"center\">");
956 wprintf("<font size=+2>%d</font>", i+1);
959 wprintf("<td width=20%%>%s ", _("If") );
961 char *hfield_values[14][2] = {
962 { "from", _("From") },
963 { "tocc", _("To or Cc") },
964 { "subject", _("Subject") },
965 { "replyto", _("Reply-to") },
966 { "sender", _("Sender") },
967 { "resentfrom", _("Resent-From") },
968 { "resentto", _("Resent-To") },
969 { "envfrom", _("Envelope From") },
970 { "envto", _("Envelope To") },
971 { "xmailer", _("X-Mailer") },
972 { "xspamflag", _("X-Spam-Flag") },
973 { "xspamstatus", _("X-Spam-Status") },
974 { "size", _("Message size") },
978 wprintf("<select id=\"hfield%d\" name=\"hfield%d\" size=1 onChange=\"UpdateRules();\">",
980 for (j=0; j<14; ++j) {
981 wprintf("<option %s value=\"%s\">%s</option>",
982 ( (!strcasecmp(hfield, hfield_values[j][0])) ? "selected" : ""),
988 wprintf("</select>");
991 wprintf("<td width=20%%>");
993 char *compare_values[6][2] = {
994 { "contains", _("contains") },
995 { "notcontains", _("does not contain") },
997 { "isnot", _("is not") },
998 { "matches", _("matches") },
999 { "notmatches", _("does not match") }
1002 wprintf("<div id=\"div_compare%d\">", i);
1003 wprintf("<select id=\"compare%d\" name=\"compare%d\" size=1 onChange=\"UpdateRules();\">",
1005 for (j=0; j<6; ++j) {
1006 wprintf("<option %s value=\"%s\">%s</option>",
1007 ( (!strcasecmp(compare, compare_values[j][0])) ? "selected" : ""),
1008 compare_values[j][0],
1009 compare_values[j][1]
1012 wprintf("</select>");
1014 wprintf("<input type=\"text\" id=\"htext%d\" name=\"htext%d\" value=\"", i, i);
1016 wprintf("\"></div>");
1018 wprintf("<div id=\"div_nocompare%d\">", i);
1019 wprintf("%s", _("(All messages)"));
1022 char *sizecomp_values[2][2] = {
1023 { "larger", _("is larger than") },
1024 { "smaller", _("is smaller than") }
1027 wprintf("<div id=\"div_size%d\">", i);
1028 wprintf("<select id=\"sizecomp%d\" name=\"sizecomp%d\" size=1 onChange=\"UpdateRules();\">",
1030 for (j=0; j<2; ++j) {
1031 wprintf("<option %s value=\"%s\">%s</option>",
1032 ( (!strcasecmp(sizecomp, sizecomp_values[j][0])) ? "selected" : ""),
1033 sizecomp_values[j][0],
1034 sizecomp_values[j][1]
1037 wprintf("</select>");
1039 wprintf("<input type=\"text\" id=\"sizeval%d\" name=\"sizeval%d\" value=\"%d\">",
1046 char *action_values[6][2] = {
1047 { "keep", _("Keep") },
1048 { "discard", _("Discard silently") },
1049 { "reject", _("Reject") },
1050 { "fileinto", _("Move message to") },
1051 { "redirect", _("Forward to") },
1052 { "vacation", _("Vacation") }
1055 wprintf("<td width=20%%>");
1056 wprintf("<select id=\"action%d\" name=\"action%d\" size=1 onChange=\"UpdateRules();\">",
1058 for (j=0; j<6; ++j) {
1059 wprintf("<option %s value=\"%s\">%s</option>",
1060 ( (!strcasecmp(action, action_values[j][0])) ? "selected" : ""),
1061 action_values[j][0],
1065 wprintf("</select>");
1067 wprintf("<div id=\"div_fileinto%d\">", i);
1068 wprintf("<select name=\"fileinto%d\" id=\"fileinto%d\">", i, i);
1069 for (j=0; j<num_roomnames; ++j) {
1070 wprintf("<option ");
1071 if (!strcasecmp(rooms[j].name, fileinto)) {
1072 wprintf("selected ");
1074 wprintf("value=\"");
1075 escputs(rooms[j].name);
1077 escputs(rooms[j].name);
1078 wprintf("</option>\n");
1080 wprintf("</select>\n");
1083 wprintf("<div id=\"div_redirect%d\">", i);
1084 wprintf("<input type=\"text\" id=\"redirect%d\" name=\"redirect%d\" value=\"", i, i);
1086 wprintf("\"></div>");
1088 wprintf("<div id=\"div_automsg%d\">", i);
1089 wprintf(_("Message:"));
1091 wprintf("<textarea name=\"automsg%d\" id=\"automsg%d\" wrap=soft rows=5>\n", i, i);
1093 wprintf("</textarea>");
1098 char *final_values[2][2] = {
1099 { "continue", _("continue processing") },
1100 { "stop", _("stop") }
1103 wprintf("<td width=10%% align=\"center\">%s</td>", _("and then") );
1105 wprintf("<td width=20%%>");
1106 wprintf("<select name=\"final%d\" id=\"final%d\" size=1 onChange=\"UpdateRules();\">",
1108 for (j=0; j<2; ++j) {
1109 wprintf("<option %s value=\"%s\">%s</option>",
1110 ( (!strcasecmp(final, final_values[j][0])) ? "selected" : ""),
1115 wprintf("</select>");
1122 wprintf("</table>");
1123 wprintf("<div id=\"div_addrule\"><a href=\"javascript:AddRule();\">%s</a><br /></div>\n",
1127 wprintf("<script type=\"text/javascript\"> \n");
1128 wprintf("UpdateRules(); \n");
1129 wprintf("</script> \n");