-#if 0
-
-/*
- * Callback function to redirect a message to a different folder
- */
-int ctdl_redirect(void)
-{
- struct ctdl_sieve *cs = (struct ctdl_sieve *)my;
- struct CtdlMessage *msg = NULL;
- recptypes *valid = NULL;
- char recp[256];
-
- safestrncpy(recp, sieve2_getvalue_string(s, "address"), sizeof recp);
-
- syslog(LOG_DEBUG, "Action is REDIRECT, recipient <%s>", recp);
-
- valid = validate_recipients(recp, NULL, 0);
- if (valid == NULL) {
- syslog(LOG_WARNING, "REDIRECT failed: bad recipient <%s>", recp);
- return SIEVE2_ERROR_BADARGS;
- }
- if (valid->num_error > 0) {
- syslog(LOG_WARNING, "REDIRECT failed: bad recipient <%s>", recp);
- free_recipients(valid);
- return SIEVE2_ERROR_BADARGS;
- }
-
- msg = CtdlFetchMessage(cs->msgnum, 1);
- if (msg == NULL) {
- syslog(LOG_WARNING, "REDIRECT failed: unable to fetch msg %ld", cs->msgnum);
- free_recipients(valid);
- return SIEVE2_ERROR_BADARGS;
- }
-
- CtdlSubmitMsg(msg, valid, NULL, 0);
- cs->cancel_implicit_keep = 1;
- free_recipients(valid);
- CM_Free(msg);
- return SIEVE2_OK;
-}
-
-
-
-
-/*
- * Callback function to file a message into a different mailbox
- */
-int ctdl_fileinto(sieve2_context_t *s, void *my)
-{
- struct ctdl_sieve *cs = (struct ctdl_sieve *)my;
- const char *dest_folder = sieve2_getvalue_string(s, "mailbox");
- int c;
- char foldername[256];
- char original_room_name[ROOMNAMELEN];
-
- syslog(LOG_DEBUG, "Action is FILEINTO, destination is <%s>", dest_folder);
-
- /* FILEINTO 'INBOX' is the same thing as KEEP */
- if ( (!strcasecmp(dest_folder, "INBOX")) || (!strcasecmp(dest_folder, MAILROOM)) ) {
- cs->keep = 1;
- cs->cancel_implicit_keep = 1;
- return SIEVE2_OK;
- }
-
- /* Remember what room we came from */
- safestrncpy(original_room_name, CC->room.QRname, sizeof original_room_name);
-
- /* First try a mailbox name match (check personal mail folders first) */
- snprintf(foldername, sizeof foldername, "%010ld.%s", cs->usernum, dest_folder);
- c = CtdlGetRoom(&CC->room, foldername);
-
- /* Then a regular room name match (public and private rooms) */
- if (c != 0) {
- safestrncpy(foldername, dest_folder, sizeof foldername);
- c = CtdlGetRoom(&CC->room, foldername);
- }
-
- if (c != 0) {
- syslog(LOG_WARNING, "FILEINTO failed: target <%s> does not exist", dest_folder);
- return SIEVE2_ERROR_BADARGS;
- }
-
- /* Yes, we actually have to go there */
- CtdlUserGoto(NULL, 0, 0, NULL, NULL, NULL, NULL);
-
- c = CtdlSaveMsgPointersInRoom(NULL, &cs->msgnum, 1, 0, NULL, 0);
-
- /* Go back to the room we came from */
- if (strcasecmp(original_room_name, CC->room.QRname)) {
- CtdlUserGoto(original_room_name, 0, 0, NULL, NULL, NULL, NULL);
- }
-
- if (c == 0) {
- cs->cancel_implicit_keep = 1;
- return SIEVE2_OK;
- }
- else {
- return SIEVE2_ERROR_BADARGS;
- }
-}
-
-
-/*
- * Callback function to indicate that a message should be discarded.
- */
-int ctdl_discard(sieve2_context_t *s, void *my)
-{
- struct ctdl_sieve *cs = (struct ctdl_sieve *)my;
-
- syslog(LOG_DEBUG, "Action is DISCARD");
-
- /* Cancel the implicit keep. That's all there is to it. */
- cs->cancel_implicit_keep = 1;
- return SIEVE2_OK;
-}
-
-
-
-
-
-
-
-
-
-
-/*
- * Callback function to indicate that a vacation message should be generated
- */
-int ctdl_vacation(sieve2_context_t *s, void *my)
-{
- struct ctdl_sieve *cs = (struct ctdl_sieve *)my;
- struct sdm_vacation *vptr;
- int days = 1;
- const char *message;
- char *vacamsg_text = NULL;
- char vacamsg_subject[1024];
-
- syslog(LOG_DEBUG, "Action is VACATION");
-
- message = sieve2_getvalue_string(s, "message");
- if (message == NULL) return SIEVE2_ERROR_BADARGS;
-
- if (sieve2_getvalue_string(s, "subject") != NULL) {
- safestrncpy(vacamsg_subject, sieve2_getvalue_string(s, "subject"), sizeof vacamsg_subject);
- }
- else {
- snprintf(vacamsg_subject, sizeof vacamsg_subject, "Re: %s", cs->subject);
- }
-
- days = sieve2_getvalue_int(s, "days");
- if (days < 1) days = 1;
- if (days > MAX_VACATION) days = MAX_VACATION;
-
- /* Check to see whether we've already alerted this sender that we're on vacation. */
- for (vptr = cs->u->first_vacation; vptr != NULL; vptr = vptr->next) {
- if (!strcasecmp(vptr->fromaddr, cs->sender)) {
- if ( (time(NULL) - vptr->timestamp) < (days * 86400) ) {
- syslog(LOG_DEBUG, "Already alerted <%s> recently.", cs->sender);
- return SIEVE2_OK;
- }
- }
- }
-
- /* Assemble the reject message. */
- vacamsg_text = malloc(strlen(message) + 1024);
- if (vacamsg_text == NULL) {
- return SIEVE2_ERROR_FAIL;
- }
-
- sprintf(vacamsg_text,
- "Content-type: text/plain charset=utf-8\n"
- "\n"
- "%s\n"
- "\n"
- ,
- message
- );
-
- quickie_message( /* This delivers the message */
- NULL,
- cs->envelope_to,
- cs->sender,
- NULL,
- vacamsg_text,
- FMT_RFC822,
- vacamsg_subject
- );
-
- free(vacamsg_text);
-
- /* Now update the list to reflect the fact that we've alerted this sender.
- * If they're already in the list, just update the timestamp.
- */
- for (vptr = cs->u->first_vacation; vptr != NULL; vptr = vptr->next) {
- if (!strcasecmp(vptr->fromaddr, cs->sender)) {
- vptr->timestamp = time(NULL);
- return SIEVE2_OK;
- }
- }
-
- /* If we get to this point, create a new record.
- */
- vptr = malloc(sizeof(struct sdm_vacation));
- memset(vptr, 0, sizeof(struct sdm_vacation));
- vptr->timestamp = time(NULL);
- safestrncpy(vptr->fromaddr, cs->sender, sizeof vptr->fromaddr);
- vptr->next = cs->u->first_vacation;
- cs->u->first_vacation = vptr;
-
- return SIEVE2_OK;
-}
-
-
-/*
- * Callback function to parse message envelope
- */
-int ctdl_getenvelope(sieve2_context_t *s, void *my)
-{
- struct ctdl_sieve *cs = (struct ctdl_sieve *)my;
-
- syslog(LOG_DEBUG, "Action is GETENVELOPE");
- syslog(LOG_DEBUG, "EnvFrom: %s", cs->envelope_from);
- syslog(LOG_DEBUG, "EnvTo: %s", cs->envelope_to);
-
- if (cs->envelope_from != NULL) {
- if ((cs->envelope_from[0] != '@')&&(cs->envelope_from[strlen(cs->envelope_from)-1] != '@')) {
- sieve2_setvalue_string(s, "from", cs->envelope_from);
- }
- else {
- sieve2_setvalue_string(s, "from", "invalid_envelope_from@example.org");
- }
- }
- else {
- sieve2_setvalue_string(s, "from", "null_envelope_from@example.org");
- }
-
-
- if (cs->envelope_to != NULL) {
- if ((cs->envelope_to[0] != '@') && (cs->envelope_to[strlen(cs->envelope_to)-1] != '@')) {
- sieve2_setvalue_string(s, "to", cs->envelope_to);
- }
- else {
- sieve2_setvalue_string(s, "to", "invalid_envelope_to@example.org");
- }
- }
- else {
- sieve2_setvalue_string(s, "to", "null_envelope_to@example.org");
- }
-
- return SIEVE2_OK;
-}
-
-
-
-
-/*
- * 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);
-
-}
-
-
-#endif
-
-