X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fsieve.c;h=cce70574ae927c451f165af0488e47215e27ac8c;hb=HEAD;hp=4cf8afdb3ec4a8370b31ba6a89e12d0d43c00f8d;hpb=bd5cad8b9b88376f40a564696061b9ffe845c5b9;p=citadel.git
diff --git a/webcit/sieve.c b/webcit/sieve.c
index 4cf8afdb3..2e3d61585 100644
--- a/webcit/sieve.c
+++ b/webcit/sieve.c
@@ -1,199 +1,33 @@
-/*
- * $Id: $
- */
-/**
- * \defgroup Sieve view/edit sieve config
- * \ingroup WebcitDisplayItems
+/*
+ * Copyright (c) 1996-2020 by the citadel.org team
+ *
+ * This program is open source software. You can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ *
+ * Implementation note: this was kind of hacked up when we switched from Sieve to custom rules.
+ * As a result there's probably some cruft in here...
+ * ajc 2020jul12
+ *
*/
-/*@{*/
+
#include "webcit.h"
+CtxType CTX_SIEVELIST = CTX_NONE;
+CtxType CTX_SIEVESCRIPT = CTX_NONE;
+
#define MAX_SCRIPTS 100
-#define MAX_RULES 25
+#define MAX_RULES 50
#define RULES_SCRIPT "__WebCit_Generated_Script__"
-/**
- * \brief view/edit sieve config
- */
-void display_sieve(void)
-{
- char script_names[MAX_SCRIPTS][64];
- int num_scripts = 0;
- int active_script = (-1);
- char buf[256];
- int i;
- int rules_script_is_active = 0;
-
-
- memset(script_names, 0, sizeof script_names);
-
- serv_puts("MSIV listscripts");
- serv_getln(buf, sizeof(buf));
- if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
- if (num_scripts < MAX_SCRIPTS) {
- 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;
- }
- }
-
- output_headers(1, 1, 2, 0, 0, 0);
-
- wprintf(" \n"
- );
-
- wprintf("
\n");
-
- wprintf(" \n"
- );
-
- wDumpContent(1);
-}
-
-
-
-/**
- * \brief Translate the fields from the rule editor into something we can save...
+/*
+ * Translate the fields from the rule editor into something we can save...
*/
void parse_fields_from_rule_editor(void) {
@@ -208,592 +42,603 @@ void parse_fields_from_rule_editor(void) {
char redirect[256];
char automsg[1024];
char final[32];
-
int i;
char buf[256];
char fname[256];
char rule[2048];
char encoded_rule[4096];
+ char my_addresses[4096];
+
+ /* Enumerate my email addresses in case they are needed for a vacation rule */
+ my_addresses[0] = 0;
+ serv_puts("GVEA");
+ serv_getln(buf, sizeof buf);
+ if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
+ if (!IsEmptyStr(my_addresses)) {
+ strcat(my_addresses, ",\n");
+ }
+ strcat(my_addresses, "\"");
+ strcat(my_addresses, buf);
+ strcat(my_addresses, "\"");
+ }
- serv_printf("MSIV putscript|%s|", RULES_SCRIPT);
+ /* Now generate the script and write it to the Citadel server */
+ serv_printf("PIBR");
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; iImportantMessage,
- _("Cancelled. Changes were not saved."));
+ if (!havebstr("save_button")) {
+ AppendImportantMessage(_("Cancelled. Changes were not saved."), -1);
display_main_menu();
return;
}
parse_fields_from_rule_editor();
- serv_puts("MSIV listscripts");
- serv_getln(buf, sizeof(buf));
- if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
- if (num_scripts < MAX_SCRIPTS) {
- extract_token(script_names[num_scripts], buf, 0, '|', 64);
- if (extract_int(buf, 1) > 0) {
- active_script = num_scripts;
- }
- ++num_scripts;
- }
- }
-
- bigaction = atoi(bstr("bigaction"));
-
- if (bigaction == 0) {
- serv_puts("MSIV setactive||");
- 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; iImportantMessage, _("Your changes have been saved."));
+ AppendImportantMessage(_("Your changes have been saved."), -1);
display_main_menu();
return;
}
-/**
- * \brief show a list of available scripts to add/remove them
- */
-void display_add_remove_scripts(char *message)
-{
- char buf[256];
- char script_name[256];
-
+void display_sieve_add_or_delete(void) {
output_headers(1, 1, 2, 0, 0, 0);
- wprintf("
\n");
-
- svprintf("BOXTITLE", WCS_STRING, _("Add a new script"));
- do_template("beginbox");
-
- wprintf(_("To create a new script, enter the desired "
- "script name in the box below and click 'Create'."));
- wprintf("
\n",
- _("Return to the script editing screen")
- );
- do_template("endbox");
-
- wprintf("
");
-
- svprintf("BOXTITLE", WCS_STRING, _("Delete scripts"));
- do_template("beginbox");
-
- wprintf(_("To delete an existing script, select the script "
- "name from the list and click 'Delete'."));
- wprintf("
");
-
- wprintf("
"
- "
\n");
- do_template("endbox");
-
- wprintf("
\n");
-
+ do_template("sieve_add");
wDumpContent(1);
}
-/**
- * \brief delete a script
+/*
+ * dummy panel indicating to the user that the server doesn't support Sieve
*/
-void delete_script(void) {
- char buf[256];
+void display_no_sieve(void) {
- serv_printf("MSIV deletescript|%s", bstr("script_name"));
- serv_getln(buf, sizeof buf);
- display_add_remove_scripts(&buf[4]);
+ output_headers(1, 1, 1, 0, 0, 0);
+ do_template("sieve_none");
+ wDumpContent(1);
}
-
-/**
- * \brief create a new script
- * take the web environment script name and create it on the citadel server
- */
-void create_script(void) {
- char buf[256];
+typedef struct __SieveListing {
+ int IsActive;
+ int IsRulesScript;
+ StrBuf *Name;
+ StrBuf *Content;
+} SieveListing;
- serv_printf("MSIV getscript|%s", bstr("script_name"));
- serv_getln(buf, sizeof buf);
- if (buf[0] == '1') {
- while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
- /* flush */
- }
- display_add_remove_scripts(_("A script by that name already exists."));
- return;
- }
-
- serv_printf("MSIV putscript|%s", bstr("script_name"));
- serv_getln(buf, sizeof buf);
- if (buf[0] == '4') {
- serv_puts("keep;");
- serv_puts("000");
- display_add_remove_scripts(_("A new script has been created. Return to the script editing screen to edit and activate it."));
- return;
- }
-
- display_add_remove_scripts(&buf[4]);
+int ConditionalSieveScriptIsActive(StrBuf *Target, WCTemplputParams *TP)
+{
+ SieveListing *SieveList = (SieveListing *)CTX(CTX_SIEVELIST);
+ return SieveList->IsActive;
}
+int ConditionalSieveScriptIsRulesScript(StrBuf *Target, WCTemplputParams *TP)
+{
+ SieveListing *SieveList = (SieveListing *)CTX(CTX_SIEVELIST);
+ return SieveList->IsActive;
+}
+void tmplput_SieveScriptName(StrBuf *Target, WCTemplputParams *TP)
+{
+ SieveListing *SieveList = (SieveListing *)CTX(CTX_SIEVELIST);
+ StrBufAppendTemplate(Target, TP, SieveList->Name, 0);
+}
+void tmplput_SieveScriptContent(StrBuf *Target, WCTemplputParams *TP)
+{
+ SieveListing *SieveList = (SieveListing *)CTX(CTX_SIEVELIST);
+ StrBufAppendTemplate(Target, TP, SieveList->Content, 0);
+}
+void FreeSieveListing(void *vSieveListing)
+{
+ SieveListing *List = (SieveListing*) vSieveListing;
+ FreeStrBuf(&List->Name);
+ free(List);
+}
+HashList *GetSieveScriptListing(StrBuf *Target, WCTemplputParams *TP)
+{
+ wcsession *WCC = WC;
+ StrBuf *Line;
+ int num_scripts = 0;
+ int rules_script_active = 0;
+ int have_rules_script = 0;
+ const char *pch;
+ HashPos *it;
+ int Done = 0;
+ SieveListing *Ruleset;
+
+ if (WCC->KnownSieveScripts != NULL) {
+ return WCC->KnownSieveScripts;
+ }
+ serv_puts("MSIV listscripts");
+ Line = NewStrBuf();
+ StrBuf_ServGetln(Line);
+ if (GetServerStatus(Line, NULL) == 1)
+ {
+ WCC->KnownSieveScripts = NewHash(1, Flathash);
+
+ while(!Done && (StrBuf_ServGetln(Line) >= 0) )
+ if ( (StrLength(Line)==3) &&
+ !strcmp(ChrPtr(Line), "000"))
+ {
+ Done = 1;
+ }
+ else
+ {
+ pch = NULL;
+ Ruleset = (SieveListing *) malloc(sizeof(SieveListing));
+ Ruleset->Name = NewStrBufPlain(NULL, StrLength(Line));
+ StrBufExtract_NextToken(Ruleset->Name, Line, &pch, '|');
+ Ruleset->IsActive = StrBufExtractNext_int(Line, &pch, '|');
+ Ruleset->Content = NULL;
+
+ if (!strcasecmp(ChrPtr(Ruleset->Name), RULES_SCRIPT))
+ {
+ Ruleset->IsRulesScript = 1;
+ have_rules_script = 1;
+ if (Ruleset->IsActive)
+ {
+ rules_script_active = 1;
+ PutBstr(HKEY("__SIEVE:RULESSCRIPT"), NewStrBufPlain(HKEY("1")));
+ }
+ }
+ Put(WCC->KnownSieveScripts, IKEY(num_scripts), Ruleset, FreeSieveListing);
-void display_rules_editor_inner_div(void) {
- int i, j;
- char buf[256];
-
- struct {
- char name[128];
- } *rooms = NULL;
- int num_roomnames = 0;
- int num_roomnames_alloc = 0;
-
-
- /* load the roomnames */
- serv_puts("LKRA");
- serv_getln(buf, sizeof buf);
- if (buf[0] == '1') {
- while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
- ++num_roomnames;
- if (num_roomnames > num_roomnames_alloc) {
- num_roomnames_alloc += 250;
- rooms = realloc(rooms, (num_roomnames_alloc * 128));
+ ++num_scripts;
}
- extract_token(rooms[num_roomnames-1].name, buf, 0, '|', 128);
- }
}
+ if ((num_scripts > 0) && (rules_script_active == 0)) {
+ PutBstr(HKEY("__SIEVE:EXTERNAL_SCRIPT"), NewStrBufPlain(HKEY("1")));
+ }
-/*
- * This script should get called by every onChange event...
- *
- */
- wprintf(" \n"
- );
-
-
- wprintf(" ");
-
- wprintf("
");
-
- for (i=0; i",
- i,
- ((i%2) ? "DDDDDD" : "FFFFFF")
- );
-
- wprintf("
");
-
- wprintf("
");
- wprintf("", i);
- wprintf("
");
-
- if (i>0) wprintf(""
- "",
- i-1, i, _("Move rule up") );
-
- wprintf(""
- "",
- i, i+1, i, _("Move rule down") );
-
- wprintf(""
- "",
- i, i, _("Delete rule") );
-
- wprintf("