2 * Copyright (c) 1996-2011 by the citadel.org team
4 * This program is open source software. You can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #define MAX_SCRIPTS 100
23 #define RULES_SCRIPT "__WebCit_Generated_Script__"
28 * dummy panel indicating to the user that the server doesn't support Sieve
30 void display_no_sieve(void) {
32 output_headers(1, 1, 2, 0, 0, 0);
34 wc_printf("<div id=\"banner\">\n");
35 wc_printf("<img src=\"static/webcit_icons/essen/32x32/config.png\">");
37 wc_printf(_("View/edit server-side mail filters"));
39 wc_printf("</div>\n");
41 wc_printf("<div id=\"content\" class=\"service\">\n");
43 wc_printf("<table class=\"sieve_background\">"
44 "<tr><td valign=top>\n");
46 wc_printf(_("This installation of Citadel was built without support for server-side mail filtering."
47 "<br>Please contact your system administrator if you require this feature.<br>"));
49 wc_printf("</td></tr></table>\n");
55 * view/edit sieve config
57 void display_sieve(void)
59 char script_names[MAX_SCRIPTS][64];
61 int active_script = (-1);
62 char buf[SIZ]; /* Don't make this buffer smaller or it will restrict line length */
64 int rules_script_is_active = 0;
66 if (!WC->serv_info->serv_supports_sieve) {
71 memset(script_names, 0, sizeof script_names);
73 serv_puts("MSIV listscripts");
74 serv_getln(buf, sizeof(buf));
75 if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
76 if (num_scripts < MAX_SCRIPTS) {
77 extract_token(script_names[num_scripts], buf, 0, '|', 64);
78 if (extract_int(buf, 1) > 0) {
79 active_script = num_scripts;
80 if (!strcasecmp(script_names[num_scripts], RULES_SCRIPT)) {
81 rules_script_is_active = 1;
88 output_headers(1, 1, 2, 0, 0, 0);
90 wc_printf("<script type=\"text/javascript\"> \n"
92 "var previously_active_script; \n"
94 "function ToggleSievePanels() { \n"
95 " d = ($('sieveform').bigaction.options[$('sieveform').bigaction.selectedIndex].value); \n"
96 " for (i=0; i<3; ++i) { \n"
98 " $('sievediv' + i).style.display = 'block'; \n"
101 " $('sievediv' + i).style.display = 'none'; \n"
106 "function ToggleScriptPanels() { \n"
107 " d = ($('sieveform').active_script.options[$('sieveform').active_script.selectedIndex].value); \n"
108 " if ($('script_' + previously_active_script)) { \n"
109 " $('script_' + previously_active_script).style.display = 'none'; \n"
111 " $('script_' + d).style.display = 'block'; \n"
112 " previously_active_script = d; \n"
118 wc_printf("<div id=\"banner\">\n");
119 wc_printf("<img src=\"static/webcit_icons/essen/32x32/config.png\">");
121 wc_printf(_("View/edit server-side mail filters"));
122 wc_printf("</h1>\n");
123 wc_printf("</div>\n");
125 wc_printf("<div id=\"content\" class=\"service\">\n");
127 wc_printf("<table class=\"sieve_background\">"
128 "<tr><td valign=top>\n");
131 wc_printf("<form id=\"sieveform\" method=\"post\" action=\"save_sieve\">\n");
132 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
134 wc_printf(_("When new mail arrives: "));
135 wc_printf("<select name=\"bigaction\" size=1 onChange=\"ToggleSievePanels();\">\n");
137 wc_printf("<option %s value=\"0\">", ((active_script < 0) ? "selected" : ""));
138 wc_printf(_("Leave it in my inbox without filtering"));
139 wc_printf("</option>\n");
141 wc_printf("<option %s value=\"1\">", ((rules_script_is_active) ? "selected" : ""));
142 wc_printf(_("Filter it according to rules selected below"));
143 wc_printf("</option>\n");
145 wc_printf("<option %s value=\"2\">",
146 (((active_script >= 0) && (!rules_script_is_active)) ? "selected" : ""));
147 wc_printf(_("Filter it through a manually edited script (advanced users only)"));
148 wc_printf("</option>\n");
150 wc_printf("</select>");
154 /* The "no filtering" div */
156 wc_printf("<div id=\"sievediv0\" style=\"display:none\">\n");
157 wc_printf("<div align=\"center\"><br><br>");
158 wc_printf(_("Your incoming mail will not be filtered through any scripts."));
159 wc_printf("<br><br></div>\n");
160 wc_printf("</div>\n");
162 /* The "webcit managed scripts" div */
164 wc_printf("<div id=\"sievediv1\" style=\"display:none\">\n");
165 display_rules_editor_inner_div();
166 wc_printf("</div>\n");
168 /* The "I'm smart and can write my own Sieve scripts" div */
170 wc_printf("<div id=\"sievediv2\" style=\"display:none\">\n");
172 if (num_scripts > 0) {
173 wc_printf(_("The currently active script is: "));
174 wc_printf("<select name=\"active_script\" size=1 onChange=\"ToggleScriptPanels();\">\n");
175 for (i=0; i<num_scripts; ++i) {
176 if (strcasecmp(script_names[i], RULES_SCRIPT)) {
177 wc_printf("<option %s value=\"%s\">%s</option>\n",
178 ((active_script == i) ? "selected" : ""),
184 wc_printf("</select>\n");
187 wc_printf(" ");
188 wc_printf("<a href=\"display_add_remove_scripts\">%s</a>\n", _("Add or delete scripts"));
192 if (num_scripts > 0) {
193 for (i=0; i<num_scripts; ++i) {
194 if (strcasecmp(script_names[i], RULES_SCRIPT)) {
195 wc_printf("<div id=\"script_%s\" style=\"display:none\">\n", script_names[i]);
196 wc_printf("<textarea name=\"text_%s\" wrap=soft rows=20 cols=80 width=80>\n",
198 serv_printf("MSIV getscript|%s", script_names[i]);
199 serv_getln(buf, sizeof buf);
200 if (buf[0] == '1') while(serv_getln(buf, sizeof (buf)), strcmp(buf, "000")) {
201 wc_printf("%s\n", buf);
203 wc_printf("</textarea>\n");
204 wc_printf("</div>\n");
209 wc_printf("<script type=\"text/javascript\"> \n"
210 "ToggleScriptPanels(); \n"
214 wc_printf("</div>\n");
217 /* The rest of this is common for all panels... */
219 wc_printf("<div align=\"center\"><br>");
220 wc_printf("<input type=\"submit\" name=\"save_button\" value=\"%s\">", _("Save changes"));
222 wc_printf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
223 wc_printf("</div></form>\n");
225 wc_printf("</td></tr></table>\n");
227 wc_printf("<script type=\"text/javascript\"> \n"
228 "ToggleSievePanels(); \n"
240 >>>>>>> 1423eb9402b934a3f524a9b7bfd593e9b004cc0a
242 * Helper function for output_sieve_rule() to output strings with quotes escaped
244 void osr_sanitize(char *str) {
247 if (str == NULL) return;
249 for (i=0; i<len; ++i) {
253 else if (isspace(str[i])) {
259 void display_add_remove_scripts(char *message);
267 * Output parseable Sieve script code based on rules input
269 void output_sieve_rule(char *hfield, char *compare, char *htext, char *sizecomp, int sizeval,
270 char *action, char *fileinto, char *redirect, char *automsg, char *final,
277 osr_sanitize(fileinto);
278 osr_sanitize(redirect);
279 osr_sanitize(automsg);
281 /* Prepare negation and match operators that will be used iff we apply a conditional */
283 if (!strcasecmp(compare, "contains")) {
287 else if (!strcasecmp(compare, "notcontains")) {
291 else if (!strcasecmp(compare, "is")) {
295 else if (!strcasecmp(compare, "isnot")) {
299 else if (!strcasecmp(compare, "matches")) {
303 else if (!strcasecmp(compare, "notmatches")) {
308 /* Now do the conditional */
310 if (!strcasecmp(hfield, "from")) {
311 serv_printf("if%s header %s \"From\" \"%s\"",
317 else if (!strcasecmp(hfield, "tocc")) {
318 serv_printf("if%s header %s [\"To\", \"Cc\"] \"%s\"",
324 else if (!strcasecmp(hfield, "subject")) {
325 serv_printf("if%s header %s \"Subject\" \"%s\"",
331 else if (!strcasecmp(hfield, "replyto")) {
332 serv_printf("if%s header %s \"Reply-to\" \"%s\"",
338 else if (!strcasecmp(hfield, "sender")) {
339 serv_printf("if%s header %s \"Sender\" \"%s\"",
345 else if (!strcasecmp(hfield, "resentfrom")) {
346 serv_printf("if%s header %s \"Resent-from\" \"%s\"",
352 else if (!strcasecmp(hfield, "resentto")) {
353 serv_printf("if%s header %s \"Resent-to\" \"%s\"",
359 else if (!strcasecmp(hfield, "xmailer")) {
360 serv_printf("if%s header %s \"X-Mailer\" \"%s\"",
366 else if (!strcasecmp(hfield, "xspamflag")) {
367 serv_printf("if%s header %s \"X-Spam-Flag\" \"%s\"",
373 else if (!strcasecmp(hfield, "xspamstatus")) {
374 serv_printf("if%s header %s \"X-Spam-Status\" \"%s\"",
380 else if (!strcasecmp(hfield, "listid")) {
381 serv_printf("if%s header %s \"List-ID\" \"%s\"",
387 else if (!strcasecmp(hfield, "envfrom")) {
388 serv_printf("if%s envelope %s \"From\" \"%s\"",
394 else if (!strcasecmp(hfield, "envto")) {
395 serv_printf("if%s envelope %s \"To\" \"%s\"",
401 else if (!strcasecmp(hfield, "size")) {
402 if (!strcasecmp(sizecomp, "larger")) {
403 serv_printf("if size :over %d", sizeval);
405 else if (!strcasecmp(sizecomp, "smaller")) {
406 serv_printf("if size :under %d", sizeval);
408 else { /* failsafe - should never get here, but just in case... */
409 serv_printf("if size :over 1");
413 /* Open braces if we're in a conditional loop */
415 if (strcasecmp(hfield, "all")) {
422 if (!strcasecmp(action, "keep")) {
423 serv_printf("keep;");
426 else if (!strcasecmp(action, "discard")) {
427 serv_printf("discard;");
430 else if (!strcasecmp(action, "reject")) {
431 serv_printf("reject \"%s\";", automsg);
434 else if (!strcasecmp(action, "fileinto")) {
435 serv_printf("fileinto \"%s\";", fileinto);
438 else if (!strcasecmp(action, "redirect")) {
439 serv_printf("redirect \"%s\";", redirect);
442 else if (!strcasecmp(action, "vacation")) {
443 serv_printf("vacation :addresses [%s]\n\"%s\";", my_addresses, automsg);
447 /* Do 'final' action */
449 if (!strcasecmp(final, "stop")) {
450 serv_printf("stop;");
454 /* Close the braces if we're in a conditional loop */
456 if (strcasecmp(hfield, "all")) {
467 * Translate the fields from the rule editor into something we can save...
469 void parse_fields_from_rule_editor(void) {
486 char encoded_rule[4096];
487 char my_addresses[4096];
489 /* Enumerate my email addresses in case they are needed for a vacation rule */
492 serv_getln(buf, sizeof buf);
493 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
494 if (!IsEmptyStr(my_addresses)) {
495 strcat(my_addresses, ",\n");
497 strcat(my_addresses, "\"");
498 strcat(my_addresses, buf);
499 strcat(my_addresses, "\"");
502 /* Now generate the script and write it to the Citadel server */
503 serv_printf("MSIV putscript|%s|", RULES_SCRIPT);
504 serv_getln(buf, sizeof buf);
509 serv_puts("# THIS SCRIPT WAS AUTOMATICALLY GENERATED BY WEBCIT.");
511 serv_puts("# Do not attempt to manually edit it. If you do so,");
512 serv_puts("# your changes will be overwritten the next time WebCit");
513 serv_puts("# saves its mail filtering rule set. If you really want");
514 serv_puts("# to use these rules as the basis for another script,");
515 serv_puts("# copy them to another script and save that instead.");
517 serv_puts("require \"fileinto\";");
518 serv_puts("require \"reject\";");
519 serv_puts("require \"vacation\";");
520 serv_puts("require \"envelope\";");
523 for (i=0; i<MAX_RULES; ++i) {
527 sprintf(fname, "active%d", i);
528 active = !strcasecmp(BSTR(fname), "on") ;
532 sprintf(fname, "hfield%d", i);
533 safestrncpy(hfield, BSTR(fname), sizeof hfield);
535 sprintf(fname, "compare%d", i);
536 safestrncpy(compare, BSTR(fname), sizeof compare);
538 sprintf(fname, "htext%d", i);
539 safestrncpy(htext, BSTR(fname), sizeof htext);
541 sprintf(fname, "sizecomp%d", i);
542 safestrncpy(sizecomp, BSTR(fname), sizeof sizecomp);
544 sprintf(fname, "sizeval%d", i);
545 sizeval = IBSTR(fname);
547 sprintf(fname, "action%d", i);
548 safestrncpy(action, BSTR(fname), sizeof action);
550 sprintf(fname, "fileinto%d", i);
551 safestrncpy(fileinto, BSTR(fname), sizeof fileinto);
553 sprintf(fname, "redirect%d", i);
554 safestrncpy(redirect, BSTR(fname), sizeof redirect);
556 sprintf(fname, "automsg%d", i);
557 safestrncpy(automsg, BSTR(fname), sizeof automsg);
559 sprintf(fname, "final%d", i);
560 safestrncpy(final, BSTR(fname), sizeof final);
562 snprintf(rule, sizeof rule, "%d|%s|%s|%s|%s|%d|%s|%s|%s|%s|%s",
563 active, hfield, compare, htext, sizecomp, sizeval, action, fileinto,
564 redirect, automsg, final
567 CtdlEncodeBase64(encoded_rule, rule, strlen(rule)+1, 0);
568 serv_printf("# WEBCIT_RULE|%d|%s|", i, encoded_rule);
569 output_sieve_rule(hfield, compare, htext, sizecomp, sizeval,
570 action, fileinto, redirect, automsg, final, my_addresses);
586 void save_sieve(void) {
588 char script_names[MAX_SCRIPTS][64];
590 int active_script = (-1);
595 if (!havebstr("save_button")) {
596 strcpy(WC->ImportantMessage,
597 _("Cancelled. Changes were not saved."));
602 parse_fields_from_rule_editor();
604 serv_puts("MSIV listscripts");
605 serv_getln(buf, sizeof(buf));
606 if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
607 if (num_scripts < MAX_SCRIPTS) {
608 extract_token(script_names[num_scripts], buf, 0, '|', 64);
609 if (extract_int(buf, 1) > 0) {
610 active_script = num_scripts;
616 bigaction = ibstr("bigaction");
618 if (bigaction == 0) {
619 serv_puts("MSIV setactive||");
620 serv_getln(buf, sizeof buf);
623 else if (bigaction == 1) {
624 serv_printf("MSIV setactive|%s|", RULES_SCRIPT);
625 serv_getln(buf, sizeof buf);
628 else if (bigaction == 2) {
629 serv_printf("MSIV setactive|%s|", bstr("active_script"));
630 serv_getln(buf, sizeof buf);
633 if (num_scripts > 0) {
634 for (i=0; i<num_scripts; ++i) {
636 * We only want to save the scripts from the "manually edited scripts"
637 * screen. The script that WebCit generates from its ruleset will be
638 * auto-generated by parse_fields_from_rule_editor() and saved there.
640 if (strcasecmp(script_names[i], RULES_SCRIPT)) {
641 serv_printf("MSIV putscript|%s|", script_names[i]);
642 serv_getln(buf, sizeof buf);
644 snprintf(this_name, sizeof this_name, "text_%s", script_names[i]);
645 striplt((char *)BSTR(this_name)); /* TODO: get rid of typecast*/
646 serv_write(BSTR(this_name), strlen(BSTR(this_name)));
653 strcpy(WC->ImportantMessage, _("Your changes have been saved."));
659 * create a new script
660 * take the web environment script name and create it on the citadel server
662 void create_script(void) {
665 serv_printf("MSIV getscript|%s", bstr("script_name"));
666 serv_getln(buf, sizeof buf);
668 while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
672 display_add_remove_scripts(_("A script by that name already exists."));
677 serv_printf("MSIV putscript|%s", bstr("script_name"));
678 serv_getln(buf, sizeof buf);
683 display_add_remove_scripts(_("A new script has been created. Return to the script editing screen to edit and activate it."));
689 display_add_remove_scripts(&buf[4]);
699 void delete_script(void) {
702 serv_printf("MSIV deletescript|%s", bstr("script_name"));
703 serv_getln(buf, sizeof buf);
705 display_add_remove_scripts(&buf[4]);
712 * dummy panel indicating to the user that the server doesn't support Sieve
714 void display_no_sieve(void) {
716 output_headers(1, 1, 2, 0, 0, 0);
717 do_template("sieve_none");
723 * view/edit sieve config
725 void display_sieve(void)
727 char script_names[MAX_SCRIPTS][64];
729 int active_script = (-1);
730 char buf[SIZ]; /* Don't make this buffer smaller or it will restrict line length */
732 int rules_script_is_active = 0;
734 if (!WC->serv_info->serv_supports_sieve) {
739 memset(script_names, 0, sizeof script_names);
741 serv_puts("MSIV listscripts");
742 serv_getln(buf, sizeof(buf));
743 if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
744 if (num_scripts < MAX_SCRIPTS) {
745 extract_token(script_names[num_scripts], buf, 0, '|', 64);
746 if (extract_int(buf, 1) > 0) {
747 active_script = num_scripts;
748 if (!strcasecmp(script_names[num_scripts], RULES_SCRIPT)) {
749 rules_script_is_active = 1;
756 output_headers(1, 1, 2, 0, 0, 0);
758 wc_printf("<script type=\"text/javascript\"> \n"
760 "var previously_active_script; \n"
762 "function ToggleSievePanels() { \n"
763 " d = ($('sieveform').bigaction.options[$('sieveform').bigaction.selectedIndex].value); \n"
764 " for (i=0; i<3; ++i) { \n"
766 " $('sievediv' + i).style.display = 'block'; \n"
769 " $('sievediv' + i).style.display = 'none'; \n"
774 "function ToggleScriptPanels() { \n"
775 " d = ($('sieveform').active_script.options[$('sieveform').active_script.selectedIndex].value); \n"
776 " if ($('script_' + previously_active_script)) { \n"
777 " $('script_' + previously_active_script).style.display = 'none'; \n"
779 " $('script_' + d).style.display = 'block'; \n"
780 " previously_active_script = d; \n"
786 wc_printf("<div id=\"banner\">\n");
787 wc_printf("<img src=\"static/advanpage2_48x.gif\">");
789 wc_printf(_("View/edit server-side mail filters"));
790 wc_printf("</h1>\n");
791 wc_printf("</div>\n");
793 wc_printf("<div id=\"content\" class=\"service\">\n");
795 wc_printf("<table class=\"sieve_background\">"
796 "<tr><td valign=top>\n");
799 wc_printf("<form id=\"sieveform\" method=\"post\" action=\"save_sieve\">\n");
800 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
802 wc_printf(_("When new mail arrives: "));
803 wc_printf("<select name=\"bigaction\" size=1 onChange=\"ToggleSievePanels();\">\n");
805 wc_printf("<option %s value=\"0\">", ((active_script < 0) ? "selected" : ""));
806 wc_printf(_("Leave it in my inbox without filtering"));
807 wc_printf("</option>\n");
809 wc_printf("<option %s value=\"1\">", ((rules_script_is_active) ? "selected" : ""));
810 wc_printf(_("Filter it according to rules selected below"));
811 wc_printf("</option>\n");
813 wc_printf("<option %s value=\"2\">",
814 (((active_script >= 0) && (!rules_script_is_active)) ? "selected" : ""));
815 wc_printf(_("Filter it through a manually edited script (advanced users only)"));
816 wc_printf("</option>\n");
818 wc_printf("</select>");
822 /* The "no filtering" div */
824 wc_printf("<div id=\"sievediv0\" style=\"display:none\">\n");
825 wc_printf("<div align=\"center\"><br><br>");
826 wc_printf(_("Your incoming mail will not be filtered through any scripts."));
827 wc_printf("<br><br></div>\n");
828 wc_printf("</div>\n");
830 /* The "webcit managed scripts" div */
832 wc_printf("<div id=\"sievediv1\" style=\"display:none\">\n");
833 display_rules_editor_inner_div();
834 wc_printf("</div>\n");
836 /* The "I'm smart and can write my own Sieve scripts" div */
838 wc_printf("<div id=\"sievediv2\" style=\"display:none\">\n");
840 if (num_scripts > 0) {
841 wc_printf(_("The currently active script is: "));
842 wc_printf("<select name=\"active_script\" size=1 onChange=\"ToggleScriptPanels();\">\n");
843 for (i=0; i<num_scripts; ++i) {
844 if (strcasecmp(script_names[i], RULES_SCRIPT)) {
845 wc_printf("<option %s value=\"%s\">%s</option>\n",
846 ((active_script == i) ? "selected" : ""),
852 wc_printf("</select>\n");
855 wc_printf(" ");
856 wc_printf("<a href=\"display_add_remove_scripts\">%s</a>\n", _("Add or delete scripts"));
860 if (num_scripts > 0) {
861 for (i=0; i<num_scripts; ++i) {
862 if (strcasecmp(script_names[i], RULES_SCRIPT)) {
863 wc_printf("<div id=\"script_%s\" style=\"display:none\">\n", script_names[i]);
864 wc_printf("<textarea name=\"text_%s\" wrap=soft rows=20 cols=80 width=80>\n",
866 serv_printf("MSIV getscript|%s", script_names[i]);
867 serv_getln(buf, sizeof buf);
868 if (buf[0] == '1') while(serv_getln(buf, sizeof (buf)), strcmp(buf, "000")) {
869 wc_printf("%s\n", buf);
871 wc_printf("</textarea>\n");
872 wc_printf("</div>\n");
877 wc_printf("<script type=\"text/javascript\"> \n"
878 "ToggleScriptPanels(); \n"
882 wc_printf("</div>\n");
885 /* The rest of this is common for all panels... */
887 wc_printf("<div align=\"center\"><br>");
888 wc_printf("<input type=\"submit\" name=\"save_button\" value=\"%s\">", _("Save changes"));
890 wc_printf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
891 wc_printf("</div></form>\n");
893 wc_printf("</td></tr></table>\n");
895 wc_printf("<script type=\"text/javascript\"> \n"
896 "ToggleSievePanels(); \n"
908 * show a list of available scripts to add/remove them
910 void display_add_remove_scripts(char *message)
913 char script_name[256];
915 output_headers(1, 1, 2, 0, 0, 0);
916 wc_printf("<div id=\"banner\">\n");
917 wc_printf("<img src=\"static/webcit_icons/essen/32x32/config.png\">");
918 wc_printf(_("Add or delete scripts"));
919 wc_printf("</h1>\n");
920 wc_printf("</div>\n");
922 wc_printf("<div id=\"content\" class=\"service\">\n");
924 if (message != NULL) {
925 wc_printf("%s", message);
928 wc_printf("<table border=0 cellspacing=10><tr valign=top><td>\n");
930 do_template("beginbox_1");
931 StrBufAppendBufPlain(WC->WBuf, _("Add a new script"), -1, 0);
932 do_template("beginbox_2");
934 wc_printf(_("To create a new script, enter the desired "
935 "script name in the box below and click 'Create'."));
936 wc_printf("<br><br>");
938 wc_printf("<center><form method=\"POST\" action=\"create_script\">\n");
939 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
940 wc_printf(_("Script name: "));
941 wc_printf("<input type=\"text\" name=\"script_name\"><br>\n"
942 "<input type=\"submit\" name=\"create_button\" value=\"%s\">"
943 "</form></center>\n", _("Create"));
945 do_template("endbox");
947 do_template("beginbox_1");
948 StrBufAppendBufPlain(WC->WBuf, _("Edit scripts"), -1, 0);
949 do_template("beginbox_2");
950 wc_printf("<br><div align=center><a href=\"display_sieve\">%s</a><br><br>\n",
951 _("Return to the script editing screen")
953 do_template("endbox");
955 wc_printf("</td><td>");
957 do_template("beginbox_1");
958 StrBufAppendBufPlain(WC->WBuf, _("Delete scripts"), -1, 0);
959 do_template("beginbox_2");
961 wc_printf(_("To delete an existing script, select the script "
962 "name from the list and click 'Delete'."));
963 wc_printf("<br><br>");
966 "<form method=\"POST\" action=\"delete_script\">\n");
967 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
968 wc_printf("<select name=\"script_name\" size=10 style=\"width:100%%\">\n");
970 serv_puts("MSIV listscripts");
971 serv_getln(buf, sizeof buf);
973 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
974 extract_token(script_name, buf, 0, '|', sizeof script_name);
975 if ( (extract_int(buf, 1) == 0) && (strcasecmp(script_name, RULES_SCRIPT)) ) {
976 wc_printf("<option>");
977 escputs(script_name);
978 wc_printf("</option>\n");
982 wc_printf("</select><br>\n");
984 wc_printf("<input type=\"submit\" name=\"delete_button\" value=\"%s\" "
985 "onClick=\"return confirm('%s');\">", _("Delete script"), _("Delete this script?"));
986 wc_printf("</form></center>\n");
987 do_template("endbox");
989 wc_printf("</td></tr></table>\n");
999 void display_rules_editor_inner_div(void) {
1002 char rules[MAX_RULES][2048];
1007 int num_roomnames = 0;
1008 int num_roomnames_alloc = 0;
1022 /* load the rules */
1023 memset(rules, 0, sizeof rules);
1024 serv_printf("MSIV getscript|%s", RULES_SCRIPT);
1025 serv_getln(buf, sizeof buf);
1026 if (buf[0] == '1') while(serv_getln(buf, sizeof (buf)), strcmp(buf, "000")) {
1027 if (!strncasecmp(buf, "# WEBCIT_RULE|", 14)) {
1028 j = extract_int(buf, 1);
1029 remove_token(buf, 0, '|');
1030 remove_token(buf, 0, '|');
1031 CtdlDecodeBase64(rules[j], buf, strlen(buf));
1035 /* load the roomnames */
1037 serv_getln(buf, sizeof buf);
1038 if (buf[0] == '1') {
1039 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1041 if (num_roomnames > num_roomnames_alloc) {
1042 num_roomnames_alloc += 250;
1043 rooms = realloc(rooms, (num_roomnames_alloc * 128));
1045 extract_token(rooms[num_roomnames-1].name, buf, 0, '|', 128);
1051 * This script should get called by every onChange event...
1054 wc_printf("<script type=\"text/javascript\"> \n"
1056 "var highest_active_rule = (-1); \n"
1058 "function UpdateRules() { \n");
1060 * Show only the active rows...
1062 wc_printf(" highest_active_rule = (-1); \n");
1063 wc_printf(" for (i=0; i<%d; ++i) { \n", MAX_RULES);
1064 wc_printf(" if ($('active'+i).checked) { \n"
1065 " $('rule' + i).style.display = 'block'; \n"
1066 " highest_active_rule = i; \n"
1069 " $('rule' + i).style.display = 'none'; \n"
1073 * Show only the fields relevant to the rules...
1075 wc_printf(" for (i=0; i<=highest_active_rule; ++i) { \n"
1076 " d = ($('movedown'+i)); \n"
1077 " if (i < highest_active_rule) { \n"
1078 " d.style.display = 'block'; \n"
1081 " d.style.display = 'none'; \n"
1083 " d = ($('hfield'+i).options[$('hfield'+i).selectedIndex].value); \n"
1084 " if (d == 'all') { \n"
1085 " $('div_size'+i).style.display = 'none'; \n"
1086 " $('div_compare'+i).style.display = 'none'; \n"
1087 " $('div_nocompare'+i).style.display = 'block'; \n"
1089 " else if (d == 'size') { \n"
1090 " $('div_size'+i).style.display = 'block'; \n"
1091 " $('div_compare'+i).style.display = 'none'; \n"
1092 " $('div_nocompare'+i).style.display = 'none'; \n"
1095 " $('div_size'+i).style.display = 'none'; \n"
1096 " $('div_compare'+i).style.display = 'block'; \n"
1097 " $('div_nocompare'+i).style.display = 'none'; \n"
1099 " d = ($('action'+i).options[$('action'+i).selectedIndex].value); \n"
1100 " if (d == 'fileinto') { \n"
1101 " $('div_fileinto'+i).style.display = 'block'; \n"
1102 " $('div_redirect'+i).style.display = 'none'; \n"
1103 " $('div_automsg'+i).style.display = 'none'; \n"
1104 " } else if (d == 'redirect') { \n"
1105 " $('div_fileinto'+i).style.display = 'none'; \n"
1106 " $('div_redirect'+i).style.display = 'block'; \n"
1107 " $('div_automsg'+i).style.display = 'none'; \n"
1108 " } else if ((d == 'reject') || (d == 'vacation')) { \n"
1109 " $('div_fileinto'+i).style.display = 'none'; \n"
1110 " $('div_redirect'+i).style.display = 'none'; \n"
1111 " $('div_automsg'+i).style.display = 'block'; \n"
1113 " $('div_fileinto'+i).style.display = 'none'; \n"
1114 " $('div_redirect'+i).style.display = 'none'; \n"
1115 " $('div_automsg'+i).style.display = 'none'; \n"
1117 " if (highest_active_rule < %d) { \n", MAX_RULES-1 );
1118 wc_printf(" $('div_addrule').style.display = 'block'; \n"
1120 " $('div_addrule').style.display = 'none'; \n"
1125 * Add a rule (really, just un-hide it)
1127 "function AddRule() { \n"
1128 " highest_active_rule = highest_active_rule + 1; \n"
1129 " $('active'+highest_active_rule).checked = true; \n"
1130 " UpdateRules(); \n"
1135 "function SwapRules(ra, rb) { \n"
1137 " var things = new Array(); \n"
1138 " things[0] = 'hfield'; \n"
1139 " things[1] = 'compare'; \n"
1140 " things[2] = 'htext'; \n"
1141 " things[3] = 'action'; \n"
1142 " things[4] = 'fileinto'; \n"
1143 " things[5] = 'redirect'; \n"
1144 " things[6] = 'final'; \n"
1145 " things[7] = 'sizecomp'; \n"
1146 " things[8] = 'sizeval'; \n"
1147 " things[9] = 'automsg'; \n"
1149 " for (i=0; i<=9; ++i) { \n"
1150 " tempval=$(things[i]+ra).value; \n"
1151 " $(things[i]+ra).value = $(things[i]+rb).value; \n"
1152 " $(things[i]+rb).value = tempval; \n"
1156 * Delete a rule (percolate the deleted rule out to the end, then deactivate it)
1158 "function DeleteRule(rd) { \n"
1159 " for (j=rd; j<=highest_active_rule; ++j) { \n"
1160 " SwapRules(j, (j+1)); \n"
1162 " $('active'+highest_active_rule).checked = false; \n"
1170 wc_printf("<table cellpadding=2 width=100%%>");
1172 for (i=0; i<MAX_RULES; ++i) {
1174 /* Grab our existing values to populate */
1175 active = extract_int(rules[i], 0);
1176 extract_token(hfield, rules[i], 1, '|', sizeof hfield);
1177 extract_token(compare, rules[i], 2, '|', sizeof compare);
1178 extract_token(htext, rules[i], 3, '|', sizeof htext);
1179 extract_token(sizecomp, rules[i], 4, '|', sizeof sizecomp);
1180 sizeval = extract_int(rules[i], 5);
1181 extract_token(action, rules[i], 6, '|', sizeof action);
1182 extract_token(fileinto, rules[i], 7, '|', sizeof fileinto);
1183 extract_token(redirect, rules[i], 8, '|', sizeof redirect);
1184 extract_token(automsg, rules[i], 9, '|', sizeof automsg);
1185 extract_token(final, rules[i], 10, '|', sizeof final);
1187 /* now generate the table row */
1189 wc_printf("<tr id=\"rule%d\" bgcolor=\"#%s\">",
1191 ((i%2) ? "DDDDDD" : "FFFFFF")
1194 wc_printf("<td width=5%% align=\"center\">");
1196 wc_printf("<div style=\"display:none\">");
1197 wc_printf("<input type=\"checkbox\" name=\"active%d\" id=\"active%d\" %s>",
1199 (active ? "checked" : "")
1201 wc_printf("</div>");
1203 if (i>0) wc_printf("<a href=\"javascript:SwapRules(%d,%d);UpdateRules();\">"
1204 "<img border=\"0\" src=\"static/webcit_icons/up_pointer.gif\" "
1205 "title=\"%s\"/></a>",
1206 i-1, i, _("Move rule up") );
1208 wc_printf("<a href=\"javascript:SwapRules(%d,%d);UpdateRules();\">"
1209 "<img id=\"movedown%d\" border=\"0\" src=\"static/webcit_icons/down_pointer.gif\" "
1210 "title=\"%s\"/></a>",
1211 i, i+1, i, _("Move rule down") );
1213 wc_printf("<a href=\"javascript:DeleteRule(%d);UpdateRules();\">"
1214 "<img id=\"delete%d\" border=\"0\" src=\"static/webcit_icons/delete.gif\" "
1215 "title=\"%s\"/></a>",
1216 i, i, _("Delete rule") );
1220 wc_printf("<td width=5%% align=\"center\">");
1221 wc_printf("<font size=+2>%d</font>", i+1);
1224 wc_printf("<td width=20%%>%s ", _("If") );
1226 char *hfield_values[15][2] = {
1227 { "from", _("From") },
1228 { "tocc", _("To or Cc") },
1229 { "subject", _("Subject") },
1230 { "replyto", _("Reply-to") },
1231 { "sender", _("Sender") },
1232 { "resentfrom", _("Resent-From") },
1233 { "resentto", _("Resent-To") },
1234 { "envfrom", _("Envelope From") },
1235 { "envto", _("Envelope To") },
1236 { "xmailer", _("X-Mailer") },
1237 { "xspamflag", _("X-Spam-Flag") },
1238 { "xspamstatus", _("X-Spam-Status") },
1239 { "listid", _("List-ID") },
1240 { "size", _("Message size") },
1244 wc_printf("<select id=\"hfield%d\" name=\"hfield%d\" size=1 onChange=\"UpdateRules();\">",
1246 for (j=0; j<15; ++j) {
1247 wc_printf("<option %s value=\"%s\">%s</option>",
1248 ( (!strcasecmp(hfield, hfield_values[j][0])) ? "selected" : ""),
1249 hfield_values[j][0],
1254 wc_printf("</select>");
1257 wc_printf("<td width=20%%>");
1259 char *compare_values[6][2] = {
1260 { "contains", _("contains") },
1261 { "notcontains", _("does not contain") },
1263 { "isnot", _("is not") },
1264 { "matches", _("matches") },
1265 { "notmatches", _("does not match") }
1268 wc_printf("<div id=\"div_compare%d\">", i);
1269 wc_printf("<select id=\"compare%d\" name=\"compare%d\" size=1 onChange=\"UpdateRules();\">",
1271 for (j=0; j<6; ++j) {
1272 wc_printf("<option %s value=\"%s\">%s</option>",
1273 ( (!strcasecmp(compare, compare_values[j][0])) ? "selected" : ""),
1274 compare_values[j][0],
1275 compare_values[j][1]
1278 wc_printf("</select>");
1280 wc_printf("<input type=\"text\" id=\"htext%d\" name=\"htext%d\" value=\"", i, i);
1282 wc_printf("\"></div>");
1284 wc_printf("<div id=\"div_nocompare%d\">", i);
1285 wc_printf("%s", _("(All messages)"));
1286 wc_printf("</div>");
1288 char *sizecomp_values[2][2] = {
1289 { "larger", _("is larger than") },
1290 { "smaller", _("is smaller than") }
1293 wc_printf("<div id=\"div_size%d\">", i);
1294 wc_printf("<select id=\"sizecomp%d\" name=\"sizecomp%d\" size=1 onChange=\"UpdateRules();\">",
1296 for (j=0; j<2; ++j) {
1297 wc_printf("<option %s value=\"%s\">%s</option>",
1298 ( (!strcasecmp(sizecomp, sizecomp_values[j][0])) ? "selected" : ""),
1299 sizecomp_values[j][0],
1300 sizecomp_values[j][1]
1303 wc_printf("</select>");
1305 wc_printf("<input type=\"text\" id=\"sizeval%d\" name=\"sizeval%d\" value=\"%d\">",
1308 wc_printf("</div>");
1312 char *action_values[6][2] = {
1313 { "keep", _("Keep") },
1314 { "discard", _("Discard silently") },
1315 { "reject", _("Reject") },
1316 { "fileinto", _("Move message to") },
1317 { "redirect", _("Forward to") },
1318 { "vacation", _("Vacation") }
1321 wc_printf("<td width=20%%>");
1322 wc_printf("<select id=\"action%d\" name=\"action%d\" size=1 onChange=\"UpdateRules();\">",
1324 for (j=0; j<6; ++j) {
1325 wc_printf("<option %s value=\"%s\">%s</option>",
1326 ( (!strcasecmp(action, action_values[j][0])) ? "selected" : ""),
1327 action_values[j][0],
1331 wc_printf("</select>");
1333 wc_printf("<div id=\"div_fileinto%d\">", i);
1334 wc_printf("<select name=\"fileinto%d\" id=\"fileinto%d\">", i, i);
1335 for (j=0; j<num_roomnames; ++j) {
1336 wc_printf("<option ");
1337 if (!strcasecmp(rooms[j].name, fileinto)) {
1338 wc_printf("selected ");
1340 wc_printf("value=\"");
1341 escputs(rooms[j].name);
1343 escputs(rooms[j].name);
1344 wc_printf("</option>\n");
1346 wc_printf("</select>\n");
1347 wc_printf("</div>");
1349 wc_printf("<div id=\"div_redirect%d\">", i);
1350 wc_printf("<input type=\"text\" id=\"redirect%d\" name=\"redirect%d\" value=\"", i, i);
1352 wc_printf("\"></div>");
1354 wc_printf("<div id=\"div_automsg%d\">", i);
1355 wc_printf(_("Message:"));
1357 wc_printf("<textarea name=\"automsg%d\" id=\"automsg%d\" wrap=soft rows=5>\n", i, i);
1359 wc_printf("</textarea>");
1360 wc_printf("</div>");
1364 char *final_values[2][2] = {
1365 { "continue", _("continue processing") },
1366 { "stop", _("stop") }
1369 wc_printf("<td width=10%% align=\"center\">%s</td>", _("and then") );
1371 wc_printf("<td width=20%%>");
1372 wc_printf("<select name=\"final%d\" id=\"final%d\" size=1 onChange=\"UpdateRules();\">",
1374 for (j=0; j<2; ++j) {
1375 wc_printf("<option %s value=\"%s\">%s</option>",
1376 ( (!strcasecmp(final, final_values[j][0])) ? "selected" : ""),
1381 wc_printf("</select>");
1384 wc_printf("</tr>\n");
1388 wc_printf("</table>");
1389 wc_printf("<div id=\"div_addrule\"><a href=\"javascript:AddRule();\">%s</a><br></div>\n",
1393 wc_printf("<script type=\"text/javascript\"> \n");
1394 wc_printf("UpdateRules(); \n");
1395 wc_printf("</script> \n");
1399 void _display_add_remove_scripts(void) {display_add_remove_scripts(NULL);}
1403 typedef struct __SieveListing {
1410 int ConditionalSieveScriptIsActive(StrBuf *Target, WCTemplputParams *TP)
1412 SieveListing *SieveList = (SieveListing *)CTX;
1413 return SieveList->IsActive;
1415 int ConditionalSieveScriptIsRulesScript(StrBuf *Target, WCTemplputParams *TP)
1417 SieveListing *SieveList = (SieveListing *)CTX;
1418 return SieveList->IsActive;
1420 void tmplput_SieveScriptName(StrBuf *Target, WCTemplputParams *TP)
1422 SieveListing *SieveList = (SieveListing *)CTX;
1423 StrBufAppendTemplate(Target, TP, SieveList->Name, 0);
1425 void tmplput_SieveScriptContent(StrBuf *Target, WCTemplputParams *TP)
1427 SieveListing *SieveList = (SieveListing *)CTX;
1428 StrBufAppendTemplate(Target, TP, SieveList->Content, 0);
1430 void FreeSieveListing(void *vSieveListing)
1432 SieveListing *List = (SieveListing*) vSieveListing;
1434 FreeStrBuf(&List->Name);
1438 HashList *GetSieveScriptListing(StrBuf *Target, WCTemplputParams *TP)
1440 wcsession *WCC = WC;
1442 int num_scripts = 0;
1443 int rules_script_active = 0;
1444 int have_rules_script = 0;
1448 SieveListing *Ruleset;
1450 if (WCC->KnownSieveScripts != NULL)
1451 return WCC->KnownSieveScripts;
1453 serv_puts("MSIV listscripts");
1455 StrBuf_ServGetln(Line);
1456 if (GetServerStatus(Line, NULL) == 1)
1458 WCC->KnownSieveScripts = NewHash(1, Flathash);
1460 while(!Done && (StrBuf_ServGetln(Line) >= 0) )
1461 if ( (StrLength(Line)==3) &&
1462 !strcmp(ChrPtr(Line), "000"))
1469 Ruleset = (SieveListing *) malloc(sizeof(SieveListing));
1470 Ruleset->Name = NewStrBufPlain(NULL, StrLength(Line));
1471 StrBufExtract_NextToken(Ruleset->Name, Line, &pch, '|');
1472 Ruleset->IsActive = StrBufExtractNext_int(Line, &pch, '|');
1474 if (!strcasecmp(ChrPtr(Ruleset->Name), RULES_SCRIPT))
1476 Ruleset->IsRulesScript = 1;
1477 have_rules_script = 1;
1478 if (Ruleset->IsActive)
1480 rules_script_active = 1;
1481 PutBstr(HKEY("__SIEVE:RULESSCRIPT"), NewStrBufPlain(HKEY("1")));
1484 Put(WCC->KnownSieveScripts, IKEY(num_scripts), Ruleset, FreeSieveListing);
1489 if ((num_scripts > 0) && (rules_script_active == 0))
1490 PutBstr(HKEY("__SIEVE:EXTERNAL_SCRIPT"), NewStrBufPlain(HKEY("1")));
1492 if (num_scripts > have_rules_script)
1500 * ok; we have custom scripts, expose that via bstr, and load the payload.
1502 PutBstr(HKEY("__SIEVE:HAVE_EXTERNAL_SCRIPT"), NewStrBufPlain(HKEY("1")));
1504 it = GetNewHashPos(WCC->KnownSieveScripts, 0);
1505 while (GetNextHashPos(WCC->KnownSieveScripts, it, &len, &Key, &vRuleset) &&
1508 Ruleset = (SieveListing *) vRuleset;
1511 * its the webcit rule? we don't need to load that here.
1513 if (Ruleset->IsRulesScript)
1516 if (!serv_printf("MSIV getscript|%s", ChrPtr(Ruleset->Name)))
1518 StrBuf_ServGetln(Line);
1519 if (GetServerStatus(Line, NULL) == 1)
1521 Ruleset->Content = NewStrBuf();
1522 while(!Done && (rc = StrBuf_ServGetln(Line), rc >= 0) )
1523 if ( (StrLength(Line)==3) &&
1524 !strcmp(ChrPtr(Line), "000"))
1530 if (StrLength(Ruleset->Content)>0)
1531 StrBufAppendBufPlain(Ruleset->Content, HKEY("\n"), 0);
1532 StrBufAppendBuf(Ruleset->Content, Line, 0);
1539 return WCC->KnownSieveScripts;
1543 typedef enum __eSieveHfield
1562 typedef enum __eSieveCompare {
1571 typedef enum __eSieveAction {
1581 typedef enum __eSieveSizeComp {
1586 typedef enum __eSieveFinal {
1592 typedef struct __SieveRule {
1595 eSieveHfield hfield;
1596 eSieveCompare compare;
1598 eSieveSizeComp sizecomp;
1599 eSieveAction Action;
1608 int ConditionalSieveRule_hfield(StrBuf *Target, WCTemplputParams *TP)
1610 SieveRule *Rule = (SieveRule *)CTX;
1612 return GetTemplateTokenNumber(Target,
1619 int ConditionalSieveRule_compare(StrBuf *Target, WCTemplputParams *TP)
1621 SieveRule *Rule = (SieveRule *)CTX;
1622 return GetTemplateTokenNumber(Target,
1629 int ConditionalSieveRule_action(StrBuf *Target, WCTemplputParams *TP)
1631 SieveRule *Rule = (SieveRule *)CTX;
1632 return GetTemplateTokenNumber(Target,
1639 int ConditionalSieveRule_sizecomp(StrBuf *Target, WCTemplputParams *TP)
1641 SieveRule *Rule = (SieveRule *)CTX;
1642 return GetTemplateTokenNumber(Target,
1649 int ConditionalSieveRule_final(StrBuf *Target, WCTemplputParams *TP)
1651 SieveRule *Rule = (SieveRule *)CTX;
1652 return GetTemplateTokenNumber(Target,
1659 int ConditionalSieveRule_ThisRoom(StrBuf *Target, WCTemplputParams *TP)
1661 SieveRule *Rule = (SieveRule *)CTX;
1662 return GetTemplateTokenNumber(Target,
1669 int ConditionalSieveRule_Active(StrBuf *Target, WCTemplputParams *TP)
1671 SieveRule *Rule = (SieveRule *)CTX;
1672 return Rule->active;
1677 void tmplput_SieveRule_hfield(StrBuf *Target, WCTemplputParams *TP)
1679 SieveRule *Rule = (SieveRule *)CTX;
1680 StrBufAppendTemplate(Target, TP, Rule->hfield, 0);
1682 void tmplput_SieveRule_compare(StrBuf *Target, WCTemplputParams *TP)
1684 SieveRule *Rule = (SieveRule *)CTX;
1685 StrBufAppendTemplate(Target, TP, Rule->compare, 0);
1688 void tmplput_SieveRule_htext(StrBuf *Target, WCTemplputParams *TP)
1690 SieveRule *Rule = (SieveRule *)CTX;
1691 StrBufAppendTemplate(Target, TP, Rule->htext, 0);
1694 void tmplput_SieveRule_sizecomp(StrBuf *Target, WCTemplputParams *TP)
1696 SieveRule *Rule = (SieveRule *)CTX;
1697 StrBufAppendTemplate(Target, TP, Rule->sizecomp, 0);
1699 void tmplput_SieveRule_action(StrBuf *Target, WCTemplputParams *TP)
1701 SieveRule *Rule = (SieveRule *)CTX;
1702 StrBufAppendTemplate(Target, TP, Rule->action, 0);
1704 void tmplput_SieveRule_fileinto(StrBuf *Target, WCTemplputParams *TP)
1706 SieveRule *Rule = (SieveRule *)CTX;
1707 StrBufAppendTemplate(Target, TP, Rule->fileinto, 0);
1709 void tmplput_SieveRule_redirect(StrBuf *Target, WCTemplputParams *TP)
1711 SieveRule *Rule = (SieveRule *)CTX;
1712 StrBufAppendTemplate(Target, TP, Rule->redirect, 0);
1714 void tmplput_SieveRule_automsg(StrBuf *Target, WCTemplputParams *TP)
1716 SieveRule *Rule = (SieveRule *)CTX;
1717 StrBufAppendTemplate(Target, TP, Rule->automsg, 0);
1720 void tmplput_SieveRule_final(StrBuf *Target, WCTemplputParams *TP)
1722 SieveRule *Rule = (SieveRule *)CTX;
1723 StrBufAppendTemplate(Target, TP, Rule->final, 0);
1726 void FreeSieveRule(void *vRule)
1728 SieveRule *Rule = (SieveRule*) Rule;
1730 FreeStrBuf(&Rule->htext);
1731 FreeStrBuf(&Rule->fileinto);
1732 FreeStrBuf(&Rule->redirect);
1733 FreeStrBuf(&Rule->automsg);
1738 #define WC_RULE_HEADER "# WEBCIT_RULE|"
1739 HashList *GetSieveRules(StrBuf *Target, WCTemplputParams *TP)
1742 StrBuf *EncodedRule;
1745 HashList *SieveRules = NULL;
1749 serv_printf("MSIV getscript|"RULES_SCRIPT);
1751 EncodedRule = NewStrBuf();
1752 StrBuf_ServGetln(Line);
1753 if (GetServerStatus(Line, NULL) == 1)
1755 SieveRules = NewHash(1, Flathash);
1757 while(!Done && (StrBuf_ServGetln(Line) >= 0) )
1758 if ( (StrLength(Line)==3) &&
1759 !strcmp(ChrPtr(Line), "000"))
1766 /* We just care for our encoded header and skip everything else */
1767 if ((StrLength(Line) > sizeof(WC_RULE_HEADER) - 1) &&
1768 (!strncasecmp(ChrPtr(Line), HKEY(WC_RULE_HEADER))))
1770 StrBufSkip_NTokenS(Line, &pch, '|', 1);
1771 n = StrBufExtractNext_int(Line, &pch, '|');
1772 StrBufExtract_NextToken(EncodedRule, Line, &pch, '|');
1773 StrBufDecodeBase64(EncodedRule);
1775 Rule = (SieveRule*) malloc(sizeof(SieveRule));
1777 Rule->htext = NewStrBufPlain (NULL, StrLength(EncodedRule));
1779 Rule->fileinto = NewStrBufPlain (NULL, StrLength(EncodedRule));
1780 Rule->redirect = NewStrBufPlain (NULL, StrLength(EncodedRule));
1781 Rule->automsg = NewStrBufPlain (NULL, StrLength(EncodedRule));
1783 /* Grab our existing values to populate */
1785 Rule->active = StrBufExtractNext_int(EncodedRule, &pch, '|');
1786 StrBufExtract_NextToken(Line, EncodedRule, &pch, '|');
1788 Rule->hfield = (eSieveHfield) GetTokenDefine(SKEY(Line), tocc);
1789 StrBufExtract_NextToken(Line, EncodedRule, &pch, '|');
1790 Rule->compare = (eSieveCompare) GetTokenDefine(SKEY(Line), contains);
1791 StrBufExtract_NextToken(Rule->htext, EncodedRule, &pch, '|');
1792 StrBufExtract_NextToken(Line, EncodedRule, &pch, '|');
1793 Rule->sizecomp = (eSieveSizeComp) GetTokenDefine(SKEY(Line), larger);
1794 Rule->sizeval = StrBufExtractNext_int(EncodedRule, &pch, '|');
1795 StrBufExtract_NextToken(Line, EncodedRule, &pch, '|');
1796 Rule->Action = (eSieveAction) GetTokenDefine(SKEY(Line), keep);
1797 StrBufExtract_NextToken(Rule->fileinto, EncodedRule, &pch, '|');
1798 StrBufExtract_NextToken(Rule->redirect, EncodedRule, &pch, '|');
1799 StrBufExtract_NextToken(Rule->automsg, EncodedRule, &pch, '|');
1800 StrBufExtract_NextToken(Line, EncodedRule, &pch, '|');
1801 Rule->final = (eSieveFinal) GetTokenDefine(SKEY(Line), econtinue);
1802 Put(SieveRules, IKEY(n), Rule, FreeSieveRule);
1807 FreeStrBuf(&EncodedRule);
1813 SessionDetachModule_SIEVE
1816 DeleteHash(&sess->KnownSieveScripts);
1823 REGISTERTokenParamDefine(from);
1824 REGISTERTokenParamDefine(tocc);
1825 REGISTERTokenParamDefine(subject);
1826 REGISTERTokenParamDefine(replyto);
1827 REGISTERTokenParamDefine(sender);
1828 REGISTERTokenParamDefine(resentfrom);
1829 REGISTERTokenParamDefine(resentto);
1830 REGISTERTokenParamDefine(envfrom);
1831 REGISTERTokenParamDefine(envto);
1832 REGISTERTokenParamDefine(xmailer);
1833 REGISTERTokenParamDefine(xspamflag);
1834 REGISTERTokenParamDefine(xspamstatus);
1835 REGISTERTokenParamDefine(listid);
1836 REGISTERTokenParamDefine(size);
1837 REGISTERTokenParamDefine(all);
1839 REGISTERTokenParamDefine(contains);
1840 REGISTERTokenParamDefine(notcontains);
1841 REGISTERTokenParamDefine(is);
1842 REGISTERTokenParamDefine(isnot);
1843 REGISTERTokenParamDefine(matches);
1844 REGISTERTokenParamDefine(notmatches);
1846 REGISTERTokenParamDefine(keep);
1847 REGISTERTokenParamDefine(discard);
1848 REGISTERTokenParamDefine(reject);
1849 REGISTERTokenParamDefine(fileinto);
1850 REGISTERTokenParamDefine(redirect);
1851 REGISTERTokenParamDefine(vacation);
1853 REGISTERTokenParamDefine(larger);
1854 REGISTERTokenParamDefine(smaller);
1856 /* these are c-keyworads, so do it by hand. */
1857 RegisterTokenParamDefine(HKEY("continue"), econtinue);
1858 RegisterTokenParamDefine(HKEY("stop"), estop);
1860 RegisterIterator("SIEVE:SCRIPTS", 0, NULL, GetSieveRules, NULL, NULL, CTX_SIEVELIST, CTX_NONE, IT_NOFLAG);
1862 RegisterIterator("SIEVE:RULES", 0, NULL, GetSieveRules, NULL, DeleteHash, CTX_SIEVESCRIPT, CTX_NONE, IT_NOFLAG);
1864 RegisterConditional(HKEY("COND:SIEVE:SCRIPT:ACTIVE"), 0, ConditionalSieveScriptIsActive, CTX_SIEVELIST);
1865 RegisterConditional(HKEY("COND:SIEVE:SCRIPT:ISRULES"), 0, ConditionalSieveScriptIsRulesScript, CTX_SIEVELIST);
1866 RegisterNamespace("SIEVE:SCRIPT:NAME", 0, 1, tmplput_SieveScriptName, NULL, CTX_ROOMS);
1867 RegisterNamespace("SIEVE:SCRIPT:CONTENT", 0, 1, tmplput_SieveScriptContent, NULL, CTX_SIEVELIST);
1870 RegisterConditional(HKEY("COND:SIEVE:ACTIVE"), 1, ConditionalSieveRule_Active, CTX_SIEVESCRIPT);
1871 RegisterConditional(HKEY("COND:SIEVE:HFIELD"), 1, ConditionalSieveRule_hfield, CTX_SIEVESCRIPT);
1872 RegisterConditional(HKEY("COND:SIEVE:COMPARE"), 1, ConditionalSieveRule_compare, CTX_SIEVESCRIPT);
1873 RegisterConditional(HKEY("COND:SIEVE:ACTION"), 1, ConditionalSieveRule_action, CTX_SIEVESCRIPT);
1874 RegisterConditional(HKEY("COND:SIEVE:SIZECOMP"), 1, ConditionalSieveRule_sizecomp, CTX_SIEVESCRIPT);
1875 RegisterConditional(HKEY("COND:SIEVE:FINAL"), 1, ConditionalSieveRule_final, CTX_SIEVESCRIPT);
1876 RegisterConditional(HKEY("COND:SIEVE:THISROOM"), 1, ConditionalSieveRule_ThisRoom, CTX_SIEVESCRIPT);
1878 //RegisterNamespace("SIEVE:SCRIPT:HFIELD", 0, 1, tmplput_SieveRule_hfield, NULL, CTX_SIEVESCRIPT);
1879 //RegisterNamespace("SIEVE:SCRIPT:COMPARE", 0, 1, tmplput_SieveRule_compare, NULL, CTX_SIEVESCRIPT);
1880 RegisterNamespace("SIEVE:SCRIPT:HTEXT", 0, 1, tmplput_SieveRule_htext, NULL, CTX_SIEVESCRIPT);
1881 //RegisterNamespace("SIEVE:SCRIPT:SIZECOMP", 0, 1, tmplput_SieveRule_sizecomp, NULL, CTX_SIEVESCRIPT);
1882 ///RegisterNamespace("SIEVE:SCRIPT:ACTION", 0, 1, tmplput_SieveRule_action, NULL, CTX_SIEVESCRIPT);
1883 RegisterNamespace("SIEVE:SCRIPT:FILEINTO", 0, 1, tmplput_SieveRule_fileinto, NULL, CTX_SIEVESCRIPT);
1884 RegisterNamespace("SIEVE:SCRIPT:REDIRECT", 0, 1, tmplput_SieveRule_redirect, NULL, CTX_SIEVESCRIPT);
1885 RegisterNamespace("SIEVE:SCRIPT:AUTOMSG", 0, 1, tmplput_SieveRule_automsg, NULL, CTX_SIEVESCRIPT);
1886 ///RegisterNamespace("SIEVE:SCRIPT:FINAL", 0, 1, tmplput_SieveRule_final, NULL, CTX_SIEVESCRIPT);
1889 WebcitAddUrlHandler(HKEY("display_sieve"), "", 0, display_sieve, 0);
1890 WebcitAddUrlHandler(HKEY("display_add_remove_scripts"), "", 0, _display_add_remove_scripts, 0);
1892 WebcitAddUrlHandler(HKEY("save_sieve"), "", 0, save_sieve, 0);
1894 WebcitAddUrlHandler(HKEY("create_script"), "", 0, create_script, 0);
1895 WebcitAddUrlHandler(HKEY("delete_script"), "", 0, delete_script, 0);