X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fsieve.c;h=cce70574ae927c451f165af0488e47215e27ac8c;hb=HEAD;hp=ab6050ce1f0862b7c53b89b34f4d6da8985e5169;hpb=55f834c5de07386ad55948e8ec2cc605799d6c1e;p=citadel.git
diff --git a/webcit/sieve.c b/webcit/sieve.c
index ab6050ce1..2e3d61585 100644
--- a/webcit/sieve.c
+++ b/webcit/sieve.c
@@ -1,495 +1,644 @@
-/*
- * $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 8
+#define MAX_RULES 50
+#define RULES_SCRIPT "__WebCit_Generated_Script__"
+
-/**
- * \brief view/edit sieve config
+/*
+ * Translate the fields from the rule editor into something we can save...
*/
-void display_sieve(void)
-{
- char script_names[MAX_SCRIPTS][64];
- int num_scripts = 0;
- int active_script = (-1);
- char buf[256];
+void parse_fields_from_rule_editor(void) {
+
+ int active;
+ char hfield[256];
+ char compare[32];
+ char htext[256];
+ char sizecomp[32];
+ int sizeval;
+ char action[32];
+ char fileinto[128];
+ 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];
-
- 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;
- }
- ++num_scripts;
+ /* 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, "\"");
}
- output_headers(1, 1, 2, 0, 0, 0);
-
- wprintf(" \n"
- );
-
- 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];
-
- 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;
- }
+typedef struct __SieveListing {
+ int IsActive;
+ int IsRulesScript;
+ StrBuf *Name;
+ StrBuf *Content;
+} SieveListing;
- 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);
+
+ ++num_scripts;
+ }
+ }
-void display_rules_editor_inner_div(void) {
- int i;
-
-/*
- * This script should get called by every onChange event...
- *
- */
- wprintf(" \n"
- );
-
-
-/*
- * Show/hide alternating rows. This is obviously bogus, it's just here to test the show/hide logic.
- wprintf(" for (i=0; i<%d; ++i) { \n", MAX_RULES);
- wprintf(" if ( (i % 2) == 0 ) { \n"
- " $('rule' + i).style.display = 'block'; \n"
- " } \n"
- " else { \n"
- " $('rule' + i).style.display = 'none'; \n"
- " } \n"
- " } \n"
- "} \n"
- " \n"
-*/
-
-
- wprintf(" ");
- wprintf("