#define MAX_SCRIPTS 100
#define MAX_RULES 25
+#define RULES_SCRIPT "__WebCit_Generated_Script__"
/**
* \brief view/edit sieve config
int active_script = (-1);
char buf[256];
int i;
+ int rules_script_is_active = 0;
memset(script_names, 0, sizeof script_names);
extract_token(script_names[num_scripts], buf, 0, '|', 64);
if (extract_int(buf, 1) > 0) {
active_script = num_scripts;
+ if (!strcasecmp(script_names[num_scripts], RULES_SCRIPT)) {
+ rules_script_is_active = 1;
+ }
}
++num_scripts;
}
wprintf(_("Leave it in my inbox without filtering"));
wprintf("</option>\n");
- wprintf("<option value=\"1\">");
+ wprintf("<option %s value=\"1\">", ((rules_script_is_active) ? "selected" : ""));
wprintf(_("Filter it according to rules selected below"));
wprintf("</option>\n");
- wprintf("<option %s value=\"2\">", ((active_script >= 0) ? "selected" : ""));
+ wprintf("<option %s value=\"2\">",
+ (((active_script >= 0) && (!rules_script_is_active)) ? "selected" : ""));
wprintf(_("Filter it through a manually edited script (advanced users only)"));
wprintf("</option>\n");
wprintf(_("The currently active script is: "));
wprintf("<select name=\"active_script\" size=1 onChange=\"ToggleScriptPanels();\">\n");
for (i=0; i<num_scripts; ++i) {
- wprintf("<option %s value=\"%s\">%s</option>\n",
- ((active_script == i) ? "selected" : ""),
- script_names[i],
- script_names[i]
- );
+ if (strcasecmp(script_names[i], RULES_SCRIPT)) {
+ wprintf("<option %s value=\"%s\">%s</option>\n",
+ ((active_script == i) ? "selected" : ""),
+ script_names[i],
+ script_names[i]
+ );
+ }
}
wprintf("</select>\n");
}
if (num_scripts > 0) {
for (i=0; i<num_scripts; ++i) {
- wprintf("<div id=\"script_%s\" style=\"display:none\">\n", script_names[i]);
- wprintf("<textarea name=\"text_%s\" wrap=soft rows=20 cols=80 width=80>\n",
- script_names[i]);
- serv_printf("MSIV getscript|%s", script_names[i]);
- serv_getln(buf, sizeof buf);
- if (buf[0] == '1') while(serv_getln(buf, sizeof (buf)), strcmp(buf, "000")) {
- wprintf("%s\n", buf);
+ if (strcasecmp(script_names[i], RULES_SCRIPT)) {
+ wprintf("<div id=\"script_%s\" style=\"display:none\">\n", script_names[i]);
+ wprintf("<textarea name=\"text_%s\" wrap=soft rows=20 cols=80 width=80>\n",
+ script_names[i]);
+ serv_printf("MSIV getscript|%s", script_names[i]);
+ serv_getln(buf, sizeof buf);
+ if (buf[0] == '1') while(serv_getln(buf, sizeof (buf)), strcmp(buf, "000")) {
+ wprintf("%s\n", buf);
+ }
+ wprintf("</textarea>\n");
+ wprintf("</div>\n");
}
- wprintf("</textarea>\n");
- wprintf("</div>\n");
}
}
char final[32];
int i;
+ char buf[256];
char fname[256];
char rule[2048];
char encoded_rule[4096];
+ serv_printf("MSIV putscript|%s|", RULES_SCRIPT);
+ serv_getln(buf, sizeof buf);
+ if (buf[0] != '4') {
+ return;
+ }
+
+ serv_puts("# THIS SCRIPT WAS AUTOMATICALLY GENERATED BY WEBCIT.");
+ serv_puts("# ");
+ serv_puts("# Do not attempt to manually edit it. If you do so,");
+ serv_puts("# your changes will be overwritten the next time WebCit");
+ serv_puts("# saves its mail filtering rule set. If you really want");
+ serv_puts("# to use these rules as the basis for another script,");
+ serv_puts("# copy them to another script and save that instead.");
+ serv_puts("");
+
for (i=0; i<MAX_RULES; ++i) {
strcpy(rule, "");
redirect, automsg, final
);
- lprintf(9, "Rule:\n%s\n", rule);
- CtdlEncodeBase64(encoded_rule, rule, strlen(rule)+1);
- lprintf(9, "Encoded rule:\n%s\n", encoded_rule);
+ CtdlEncodeBase64(encoded_rule, rule, strlen(rule)+1, 0);
+ serv_printf("# WEBCIT_RULE|%d|%s|", i, encoded_rule);
+
+ /* FIXME: this is where we need to generate Sieve code based on the rule */
+
+
}
+ serv_puts("000");
+
}
serv_getln(buf, sizeof buf);
}
+ else if (bigaction == 1) {
+ serv_printf("MSIV setactive|%s|", RULES_SCRIPT);
+ serv_getln(buf, sizeof buf);
+ }
+
else if (bigaction == 2) {
serv_printf("MSIV setactive|%s|", bstr("active_script"));
serv_getln(buf, sizeof buf);
if (num_scripts > 0) {
for (i=0; i<num_scripts; ++i) {
- serv_printf("MSIV putscript|%s|", script_names[i]);
- serv_getln(buf, sizeof buf);
- if (buf[0] == '4') {
- snprintf(this_name, sizeof this_name, "text_%s", script_names[i]);
- striplt(bstr(this_name));
- serv_printf("%s", bstr(this_name));
- serv_puts("000");
+ /*
+ * We only want to save the scripts from the "manually edited scripts"
+ * screen. The script that WebCit generates from its ruleset will be
+ * auto-generated by parse_fields_from_rule_editor() and saved there.
+ */
+ if (strcasecmp(script_names[i], RULES_SCRIPT)) {
+ serv_printf("MSIV putscript|%s|", script_names[i]);
+ serv_getln(buf, sizeof buf);
+ if (buf[0] == '4') {
+ snprintf(this_name, sizeof this_name, "text_%s", script_names[i]);
+ striplt(bstr(this_name));
+ serv_printf("%s", bstr(this_name));
+ serv_puts("000");
+ }
}
}
}
if (buf[0] == '1') {
while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
extract_token(script_name, buf, 0, '|', sizeof script_name);
- if (extract_int(buf, 1) == 0) {
+ if ( (extract_int(buf, 1) == 0) && (strcasecmp(script_name, RULES_SCRIPT)) ) {
wprintf("<option>");
escputs(script_name);
wprintf("</option>\n");