-/*
- * Given the on-disk representation of our Sieve config, load
- * it into an in-memory data structure.
- */
-void parse_sieve_config(char *conf, struct sdm_userdata *u) {
- char *ptr;
- char *c, *vacrec;
- char keyword[256];
- struct sdm_script *sptr;
- struct sdm_vacation *vptr;
-
- ptr = conf;
- while (c = ptr, ptr = bmstrcasestr(ptr, CTDLSIEVECONFIGSEPARATOR), ptr != NULL) {
- *ptr = 0;
- ptr += strlen(CTDLSIEVECONFIGSEPARATOR);
-
- extract_token(keyword, c, 0, '|', sizeof keyword);
-
- if (!strcasecmp(keyword, "lastproc")) {
- u->lastproc = extract_long(c, 1);
- }
-
- else if (!strcasecmp(keyword, "script")) {
- sptr = malloc(sizeof(struct sdm_script));
- extract_token(sptr->script_name, c, 1, '|', sizeof sptr->script_name);
- sptr->script_active = extract_int(c, 2);
- remove_token(c, 0, '|');
- remove_token(c, 0, '|');
- remove_token(c, 0, '|');
- sptr->script_content = strdup(c);
- sptr->next = u->first_script;
- u->first_script = sptr;
- }
-
- else if (!strcasecmp(keyword, "vacation")) {
-
- if (c != NULL) while (vacrec=c, c=strchr(c, '\n'), (c != NULL)) {
-
- *c = 0;
- ++c;
-
- if (strncasecmp(vacrec, "vacation|", 9)) {
- vptr = malloc(sizeof(struct sdm_vacation));
- extract_token(vptr->fromaddr, vacrec, 0, '|', sizeof vptr->fromaddr);
- vptr->timestamp = extract_long(vacrec, 1);
- vptr->next = u->first_vacation;
- u->first_vacation = vptr;
- }
- }
- }
-
- /* ignore unknown keywords */
- }
-}
-
-
-
-
-
-/*
- * Write our citadel sieve config back to disk
- *
- * (Set yes_write_to_disk to nonzero to make it actually write the config;
- * otherwise it just frees the data structures.)
- */
-void rewrite_ctdl_sieve_config(struct sdm_userdata *u, int yes_write_to_disk) {
- StrBuf *text;
- struct sdm_script *sptr;
- struct sdm_vacation *vptr;
-
- text = NewStrBufPlain(NULL, SIZ);
- StrBufPrintf(text,
- "Content-type: application/x-citadel-sieve-config\n"
- "\n"
- CTDLSIEVECONFIGSEPARATOR
- "lastproc|%ld"
- CTDLSIEVECONFIGSEPARATOR
- ,
- u->lastproc
- );
-
- while (u->first_script != NULL) {
- StrBufAppendPrintf(text,
- "script|%s|%d|%s" CTDLSIEVECONFIGSEPARATOR,
- u->first_script->script_name,
- u->first_script->script_active,
- u->first_script->script_content
- );
- sptr = u->first_script;
- u->first_script = u->first_script->next;
- free(sptr->script_content);
- free(sptr);
- }
-
- if (u->first_vacation != NULL) {
-
- StrBufAppendPrintf(text, "vacation|\n");
- while (u->first_vacation != NULL) {
- if ( (time(NULL) - u->first_vacation->timestamp) < (MAX_VACATION * 86400)) {
- StrBufAppendPrintf(text, "%s|%ld\n",
- u->first_vacation->fromaddr,
- u->first_vacation->timestamp
- );
- }
- vptr = u->first_vacation;
- u->first_vacation = u->first_vacation->next;
- free(vptr);
- }
- StrBufAppendPrintf(text, CTDLSIEVECONFIGSEPARATOR);
- }
-
- if (yes_write_to_disk)
- {
- /* Save the config */
- quickie_message("Citadel", NULL, NULL, u->config_roomname,
- ChrPtr(text),
- 4,
- "Sieve configuration"
- );
-
- /* And delete the old one */
- if (u->config_msgnum > 0) {
- CtdlDeleteMessages(u->config_roomname, &u->config_msgnum, 1, "");
- }
- }
-
- FreeStrBuf (&text);
-
-}
-