2 * $Id: serv_sieve.c 3850 2005-09-13 14:00:24Z ajc $
4 * This module glues libSieve to the Citadel server in order to implement
5 * the Sieve mailbox filtering language (RFC 3028).
7 * This code is released under the terms of the GNU General Public License.
18 #include <sys/types.h>
20 #if TIME_WITH_SYS_TIME
21 # include <sys/time.h>
25 # include <sys/time.h>
36 #include "sysdep_decls.h"
37 #include "citserver.h"
40 #include "serv_extensions.h"
45 #include "internet_addressing.h"
50 #include "serv_sieve.h"
52 struct RoomProcList *sieve_list = NULL;
56 * Callback function to send libSieve trace messages to Citadel log facility
57 * Set ctdl_libsieve_debug=1 to see extremely verbose libSieve trace
59 int ctdl_debug(sieve2_context_t *s, void *my)
61 static int ctdl_libsieve_debug = 0;
63 if (ctdl_libsieve_debug) {
64 lprintf(CTDL_DEBUG, "Sieve: level [%d] module [%s] file [%s] function [%s]\n",
65 sieve2_getvalue_int(s, "level"),
66 sieve2_getvalue_string(s, "module"),
67 sieve2_getvalue_string(s, "file"),
68 sieve2_getvalue_string(s, "function"));
69 lprintf(CTDL_DEBUG, " message [%s]\n",
70 sieve2_getvalue_string(s, "message"));
77 * Callback function to log script parsing errors
79 int ctdl_errparse(sieve2_context_t *s, void *my)
81 lprintf(CTDL_WARNING, "Error in script, line %d: %s\n",
82 sieve2_getvalue_int(s, "lineno"),
83 sieve2_getvalue_string(s, "message")
90 * Callback function to log script execution errors
92 int ctdl_errexec(sieve2_context_t *s, void *my)
94 lprintf(CTDL_WARNING, "Error executing script: %s\n",
95 sieve2_getvalue_string(s, "message")
102 * Callback function to redirect a message to a different folder
104 int ctdl_redirect(sieve2_context_t *s, void *my)
106 struct ctdl_sieve *cs = (struct ctdl_sieve *)my;
107 struct CtdlMessage *msg = NULL;
108 struct recptypes *valid = NULL;
111 safestrncpy(recp, sieve2_getvalue_string(s, "address"), sizeof recp);
113 lprintf(CTDL_DEBUG, "Action is REDIRECT, recipient <%s>\n", recp);
115 valid = validate_recipients(recp);
117 lprintf(CTDL_WARNING, "REDIRECT failed: bad recipient <%s>\n", recp);
118 return SIEVE2_ERROR_BADARGS;
120 if (valid->num_error > 0) {
121 lprintf(CTDL_WARNING, "REDIRECT failed: bad recipient <%s>\n", recp);
123 return SIEVE2_ERROR_BADARGS;
126 msg = CtdlFetchMessage(cs->msgnum, 1);
128 lprintf(CTDL_WARNING, "REDIRECT failed: unable to fetch msg %ld\n", cs->msgnum);
130 return SIEVE2_ERROR_BADARGS;
133 CtdlSubmitMsg(msg, valid, NULL);
136 CtdlFreeMessage(msg);
142 * Callback function to indicate that a message *will* be kept in the inbox
144 int ctdl_keep(sieve2_context_t *s, void *my)
146 struct ctdl_sieve *cs = (struct ctdl_sieve *)my;
148 lprintf(CTDL_DEBUG, "Action is KEEP\n");
157 * Callback function to file a message into a different mailbox
159 int ctdl_fileinto(sieve2_context_t *s, void *my)
161 struct ctdl_sieve *cs = (struct ctdl_sieve *)my;
162 const char *dest_folder = sieve2_getvalue_string(s, "mailbox");
164 char foldername[256];
165 char original_room_name[ROOMNAMELEN];
167 lprintf(CTDL_DEBUG, "Action is FILEINTO, destination is <%s>\n", dest_folder);
169 /* FILEINTO 'INBOX' is the same thing as KEEP */
170 if ( (!strcasecmp(dest_folder, "INBOX")) || (!strcasecmp(dest_folder, MAILROOM)) ) {
176 /* Remember what room we came from */
177 safestrncpy(original_room_name, CC->room.QRname, sizeof original_room_name);
179 /* First try a mailbox name match (check personal mail folders first) */
180 snprintf(foldername, sizeof foldername, "%010ld.%s", cs->usernum, dest_folder);
181 c = getroom(&CC->room, foldername);
183 /* Then a regular room name match (public and private rooms) */
185 safestrncpy(foldername, dest_folder, sizeof foldername);
186 c = getroom(&CC->room, foldername);
190 lprintf(CTDL_WARNING, "FILEINTO failed: target <%s> does not exist\n", dest_folder);
191 return SIEVE2_ERROR_BADARGS;
194 /* Yes, we actually have to go there */
195 usergoto(NULL, 0, 0, NULL, NULL);
197 c = CtdlSaveMsgPointersInRoom(NULL, &cs->msgnum, 1, 0, NULL);
199 /* Go back to the room we came from */
200 if (strcasecmp(original_room_name, CC->room.QRname)) {
201 usergoto(original_room_name, 0, 0, NULL, NULL);
209 return SIEVE2_ERROR_BADARGS;
215 * Callback function to indicate that a message should be rejected
216 * FIXME implement this
218 int ctdl_reject(sieve2_context_t *s, void *my)
220 lprintf(CTDL_DEBUG, "Action is REJECT\n");
221 return SIEVE2_ERROR_UNSUPPORTED;
226 * Callback function to indicate that the user should be notified
227 * FIXME implement this
229 int ctdl_notify(sieve2_context_t *s, void *my)
231 lprintf(CTDL_DEBUG, "Action is NOTIFY\n");
232 return SIEVE2_ERROR_UNSUPPORTED;
237 * Callback function to indicate that a vacation message should be generated
238 * FIXME implement this
240 int ctdl_vacation(sieve2_context_t *s, void *my)
242 lprintf(CTDL_DEBUG, "Action is VACATION\n");
243 return SIEVE2_ERROR_UNSUPPORTED;
248 * Callback function to parse addresses per local system convention
250 int ctdl_getsubaddress(sieve2_context_t *s, void *my)
252 struct ctdl_sieve *cs = (struct ctdl_sieve *)my;
255 * Citadel doesn't support subaddresses, so just give up.
257 return SIEVE2_ERROR_UNSUPPORTED;
259 /* libSieve does not take ownership of the memory used here. But, since we
260 * are just pointing to locations inside a struct which we are going to free
263 sieve2_setvalue_string(s, "user", cs->recp_user);
264 sieve2_setvalue_string(s, "detail", ""); /* we don't support user+detail@domain yet */
265 sieve2_setvalue_string(s, "localpart", cs->recp_user);
266 sieve2_setvalue_string(s, "domain", cs->recp_node);
272 * Callback function to parse message envelope
273 * FIXME implement this
275 int ctdl_getenvelope(sieve2_context_t *s, void *my)
277 return SIEVE2_ERROR_UNSUPPORTED;
282 * Callback function to fetch message body
283 * FIXME implement this
285 int ctdl_getbody(sieve2_context_t *s, void *my)
287 return SIEVE2_ERROR_UNSUPPORTED;
292 * Callback function to fetch message size
293 * FIXME implement this
295 int ctdl_getsize(sieve2_context_t *s, void *my)
297 return SIEVE2_ERROR_UNSUPPORTED;
302 * Callback function to indicate that a message should be discarded.
304 int ctdl_discard(sieve2_context_t *s, void *my)
306 struct ctdl_sieve *cs = (struct ctdl_sieve *)my;
308 lprintf(CTDL_DEBUG, "Action is DISCARD\n");
310 /* Yes, this is really all there is to it. Since we are not setting "keep" to 1,
311 * the message will be discarded because "some other action" was successfully taken.
320 * Callback function to retrieve the sieve script
322 int ctdl_getscript(sieve2_context_t *s, void *my) {
323 struct sdm_script *sptr;
324 struct ctdl_sieve *cs = (struct ctdl_sieve *)my;
326 for (sptr=cs->u->first_script; sptr!=NULL; sptr=sptr->next) {
327 if (sptr->script_active > 0) {
328 lprintf(CTDL_DEBUG, "ctdl_getscript() is using script '%s'\n", sptr->script_name);
329 sieve2_setvalue_string(s, "script", sptr->script_content);
334 lprintf(CTDL_DEBUG, "ctdl_getscript() found no active script\n");
335 return SIEVE2_ERROR_GETSCRIPT;
339 * Callback function to retrieve message headers
341 int ctdl_getheaders(sieve2_context_t *s, void *my) {
343 struct ctdl_sieve *cs = (struct ctdl_sieve *)my;
345 lprintf(CTDL_DEBUG, "ctdl_getheaders() was called\n");
347 sieve2_setvalue_string(s, "allheaders", cs->rfc822headers);
354 * Add a room to the list of those rooms which potentially require sieve processing
356 void sieve_queue_room(struct ctdlroom *which_room) {
357 struct RoomProcList *ptr;
359 ptr = (struct RoomProcList *) malloc(sizeof (struct RoomProcList));
360 if (ptr == NULL) return;
362 safestrncpy(ptr->name, which_room->QRname, sizeof ptr->name);
363 begin_critical_section(S_SIEVELIST);
364 ptr->next = sieve_list;
366 end_critical_section(S_SIEVELIST);
372 * Perform sieve processing for one message (called by sieve_do_room() for each message)
374 void sieve_do_msg(long msgnum, void *userdata) {
375 struct sdm_userdata *u = (struct sdm_userdata *) userdata;
376 sieve2_context_t *sieve2_context = u->sieve2_context;
377 struct ctdl_sieve my;
379 struct CtdlMessage *msg;
381 lprintf(CTDL_DEBUG, "Performing sieve processing on msg <%ld>\n", msgnum);
383 msg = CtdlFetchMessage(msgnum, 0);
384 if (msg == NULL) return;
386 CC->redirect_buffer = malloc(SIZ);
387 CC->redirect_len = 0;
388 CC->redirect_alloc = SIZ;
389 CtdlOutputPreLoadedMsg(msg, MT_RFC822, HEADERS_ONLY, 0, 1);
390 my.rfc822headers = CC->redirect_buffer;
391 CC->redirect_buffer = NULL;
392 CC->redirect_len = 0;
393 CC->redirect_alloc = 0;
395 my.keep = 0; /* Don't keep a copy in the inbox unless a callback tells us to do so */
396 my.actiontaken = 0; /* Keep track of whether any actions were successfully taken */
397 my.usernum = atol(CC->room.QRname); /* Keep track of the owner of the room's namespace */
398 my.msgnum = msgnum; /* Keep track of the message number in our local store */
399 my.u = u; /* Hand off a pointer to the rest of this info */
401 /* Keep track of the recipient so we can do handling based on it later */
402 process_rfc822_addr(msg->cm_fields['R'], my.recp_user, my.recp_node, my.recp_name);
406 sieve2_setvalue_string(sieve2_context, "allheaders", my.rfc822headers);
408 lprintf(CTDL_DEBUG, "Calling sieve2_execute()\n");
409 res = sieve2_execute(sieve2_context, &my);
410 if (res != SIEVE2_OK) {
411 lprintf(CTDL_CRIT, "sieve2_execute() returned %d: %s\n", res, sieve2_errstr(res));
414 free(my.rfc822headers);
415 my.rfc822headers = NULL;
418 * Delete the message from the inbox unless either we were told not to, or
419 * if no other action was successfully taken.
421 if ( (!my.keep) && (my.actiontaken) ) {
422 lprintf(CTDL_DEBUG, "keep is 0 -- deleting message from inbox\n");
423 CtdlDeleteMessages(CC->room.QRname, &msgnum, 1, "", 0);
426 lprintf(CTDL_DEBUG, "Completed sieve processing on msg <%ld>\n", msgnum);
427 u->lastproc = msgnum;
435 * Given the on-disk representation of our Sieve config, load
436 * it into an in-memory data structure.
438 void parse_sieve_config(char *conf, struct sdm_userdata *u) {
442 struct sdm_script *sptr;
445 while (c = ptr, ptr = bmstrcasestr(ptr, CTDLSIEVECONFIGSEPARATOR), ptr != NULL) {
447 ptr += strlen(CTDLSIEVECONFIGSEPARATOR);
449 extract_token(keyword, c, 0, '|', sizeof keyword);
451 if (!strcasecmp(keyword, "lastproc")) {
452 u->lastproc = extract_long(c, 1);
455 else if (!strcasecmp(keyword, "script")) {
456 sptr = malloc(sizeof(struct sdm_script));
457 extract_token(sptr->script_name, c, 1, '|', sizeof sptr->script_name);
458 sptr->script_active = extract_int(c, 2);
459 remove_token(c, 0, '|');
460 remove_token(c, 0, '|');
461 remove_token(c, 0, '|');
462 sptr->script_content = strdup(c);
463 sptr->next = u->first_script;
464 u->first_script = sptr;
467 /* ignore unknown keywords */
472 * We found the Sieve configuration for this user.
473 * Now do something with it.
475 void get_sieve_config_backend(long msgnum, void *userdata) {
476 struct sdm_userdata *u = (struct sdm_userdata *) userdata;
477 struct CtdlMessage *msg;
480 u->config_msgnum = msgnum;
481 msg = CtdlFetchMessage(msgnum, 1);
483 u->config_msgnum = (-1) ;
487 conf = msg->cm_fields['M'];
488 msg->cm_fields['M'] = NULL;
489 CtdlFreeMessage(msg);
492 parse_sieve_config(conf, u);
500 * Write our citadel sieve config back to disk
502 void rewrite_ctdl_sieve_config(struct sdm_userdata *u) {
504 struct sdm_script *sptr;
509 "Content-type: application/x-citadel-sieve-config\n"
511 CTDLSIEVECONFIGSEPARATOR
513 CTDLSIEVECONFIGSEPARATOR
518 while (u->first_script != NULL) {
519 text = realloc(text, strlen(text) + strlen(u->first_script->script_content) + 256);
520 sprintf(&text[strlen(text)], "script|%s|%d|%s" CTDLSIEVECONFIGSEPARATOR,
521 u->first_script->script_name,
522 u->first_script->script_active,
523 u->first_script->script_content
525 sptr = u->first_script;
526 u->first_script = u->first_script->next;
527 free(sptr->script_content);
531 /* Save the config */
532 quickie_message("Citadel", NULL, u->config_roomname,
535 "Sieve configuration"
538 /* And delete the old one */
539 if (u->config_msgnum > 0) {
540 CtdlDeleteMessages(u->config_roomname, &u->config_msgnum, 1, "", 0);
548 * Perform sieve processing for a single room
550 void sieve_do_room(char *roomname) {
552 struct sdm_userdata u;
553 sieve2_context_t *sieve2_context = NULL; /* Context for sieve parser */
554 int res; /* Return code from libsieve calls */
555 long orig_lastproc = 0;
557 memset(&u, 0, sizeof u);
560 * This is our callback registration table for libSieve.
562 sieve2_callback_t ctdl_sieve_callbacks[] = {
563 { SIEVE2_ACTION_REJECT, ctdl_reject },
564 { SIEVE2_ACTION_NOTIFY, ctdl_notify },
565 { SIEVE2_ACTION_VACATION, ctdl_vacation },
566 { SIEVE2_ERRCALL_PARSE, ctdl_errparse },
567 { SIEVE2_ERRCALL_RUNTIME, ctdl_errexec },
568 { SIEVE2_ACTION_FILEINTO, ctdl_fileinto },
569 { SIEVE2_ACTION_REDIRECT, ctdl_redirect },
570 { SIEVE2_ACTION_DISCARD, ctdl_discard },
571 { SIEVE2_ACTION_KEEP, ctdl_keep },
572 { SIEVE2_SCRIPT_GETSCRIPT, ctdl_getscript },
573 { SIEVE2_DEBUG_TRACE, ctdl_debug },
574 { SIEVE2_MESSAGE_GETALLHEADERS, ctdl_getheaders },
575 { SIEVE2_MESSAGE_GETSUBADDRESS, ctdl_getsubaddress },
576 { SIEVE2_MESSAGE_GETENVELOPE, ctdl_getenvelope },
577 { SIEVE2_MESSAGE_GETBODY, ctdl_getbody },
578 { SIEVE2_MESSAGE_GETSIZE, ctdl_getsize },
582 /* See if the user who owns this 'mailbox' has any Sieve scripts that
585 snprintf(u.config_roomname, sizeof u.config_roomname, "%010ld.%s", atol(roomname), SIEVERULES);
586 if (getroom(&CC->room, u.config_roomname) != 0) {
587 lprintf(CTDL_DEBUG, "<%s> does not exist. No processing is required.\n", u.config_roomname);
592 * Find the sieve scripts and control record and do something
594 u.config_msgnum = (-1);
595 CtdlForEachMessage(MSGS_LAST, 1, NULL, SIEVECONFIG, NULL,
596 get_sieve_config_backend, (void *)&u );
598 if (u.config_msgnum < 0) {
599 lprintf(CTDL_DEBUG, "No Sieve rules exist. No processing is required.\n");
603 lprintf(CTDL_DEBUG, "Rules found. Performing Sieve processing for <%s>\n", roomname);
605 if (getroom(&CC->room, roomname) != 0) {
606 lprintf(CTDL_CRIT, "ERROR: cannot load <%s>\n", roomname);
610 /* Initialize the Sieve parser */
612 res = sieve2_alloc(&sieve2_context);
613 if (res != SIEVE2_OK) {
614 lprintf(CTDL_CRIT, "sieve2_alloc() returned %d: %s\n", res, sieve2_errstr(res));
618 res = sieve2_callbacks(sieve2_context, ctdl_sieve_callbacks);
619 if (res != SIEVE2_OK) {
620 lprintf(CTDL_CRIT, "sieve2_callbacks() returned %d: %s\n", res, sieve2_errstr(res));
624 /* Validate the script */
626 struct ctdl_sieve my; /* dummy ctdl_sieve struct just to pass "u" slong */
627 memset(&my, 0, sizeof my);
629 res = sieve2_validate(sieve2_context, &my);
630 if (res != SIEVE2_OK) {
631 lprintf(CTDL_CRIT, "sieve2_validate() returned %d: %s\n", res, sieve2_errstr(res));
635 /* Do something useful */
636 u.sieve2_context = sieve2_context;
637 orig_lastproc = u.lastproc;
638 CtdlForEachMessage(MSGS_GT, u.lastproc, NULL, NULL, NULL,
644 res = sieve2_free(&sieve2_context);
645 if (res != SIEVE2_OK) {
646 lprintf(CTDL_CRIT, "sieve2_free() returned %d: %s\n", res, sieve2_errstr(res));
649 /* Rewrite the config if we have to */
650 if (u.lastproc > orig_lastproc) {
651 rewrite_ctdl_sieve_config(&u);
657 * Perform sieve processing for all rooms which require it
659 void perform_sieve_processing(void) {
660 struct RoomProcList *ptr = NULL;
662 if (sieve_list != NULL) {
663 lprintf(CTDL_DEBUG, "Begin Sieve processing\n");
664 while (sieve_list != NULL) {
665 char spoolroomname[ROOMNAMELEN];
666 safestrncpy(spoolroomname, sieve_list->name, sizeof spoolroomname);
667 begin_critical_section(S_SIEVELIST);
669 /* pop this record off the list */
671 sieve_list = sieve_list->next;
674 /* invalidate any duplicate entries to prevent double processing */
675 for (ptr=sieve_list; ptr!=NULL; ptr=ptr->next) {
676 if (!strcasecmp(ptr->name, spoolroomname)) {
681 end_critical_section(S_SIEVELIST);
682 if (spoolroomname[0] != 0) {
683 sieve_do_room(spoolroomname);
690 void msiv_load(struct sdm_userdata *u) {
691 char hold_rm[ROOMNAMELEN];
693 strcpy(hold_rm, CC->room.QRname); /* save current room */
695 /* Take a spin through the user's personal address book */
696 if (getroom(&CC->room, SIEVERULES) == 0) {
698 u->config_msgnum = (-1);
699 strcpy(u->config_roomname, CC->room.QRname);
700 CtdlForEachMessage(MSGS_LAST, 1, NULL, SIEVECONFIG, NULL,
701 get_sieve_config_backend, (void *)u );
705 if (strcmp(CC->room.QRname, hold_rm)) {
706 getroom(&CC->room, hold_rm); /* return to saved room */
710 void msiv_store(struct sdm_userdata *u) {
711 rewrite_ctdl_sieve_config(u);
716 * Select the active script.
717 * (Set script_name to an empty string to disable all scripts)
719 * Returns 0 on success or nonzero for error.
721 int msiv_setactive(struct sdm_userdata *u, char *script_name) {
723 struct sdm_script *s;
725 /* First see if the supplied value is ok */
727 if (strlen(script_name) == 0) {
731 for (s=u->first_script; s!=NULL; s=s->next) {
732 if (!strcasecmp(s->script_name, script_name)) {
740 /* Now set the active script */
741 for (s=u->first_script; s!=NULL; s=s->next) {
742 if (!strcasecmp(s->script_name, script_name)) {
743 s->script_active = 1;
746 s->script_active = 0;
755 * Fetch a script by name.
757 * Returns NULL if the named script was not found, or a pointer to the script
758 * if it was found. NOTE: the caller does *not* own the memory returned by
759 * this function. Copy it if you need to keep it.
761 char *msiv_getscript(struct sdm_userdata *u, char *script_name) {
762 struct sdm_script *s;
764 for (s=u->first_script; s!=NULL; s=s->next) {
765 if (!strcasecmp(s->script_name, script_name)) {
766 if (s->script_content != NULL) {
767 return (s->script_content);
777 * Delete a script by name.
779 * Returns 0 if the script was deleted.
780 * 1 if the script was not found.
781 * 2 if the script cannot be deleted because it is active.
783 int msiv_deletescript(struct sdm_userdata *u, char *script_name) {
784 struct sdm_script *s = NULL;
785 struct sdm_script *script_to_delete = NULL;
787 for (s=u->first_script; s!=NULL; s=s->next) {
788 if (!strcasecmp(s->script_name, script_name)) {
789 script_to_delete = s;
790 if (s->script_active) {
796 if (script_to_delete == NULL) return(1);
798 if (u->first_script == script_to_delete) {
799 u->first_script = u->first_script->next;
801 else for (s=u->first_script; s!=NULL; s=s->next) {
802 if (s->next == script_to_delete) {
803 s->next = s->next->next;
807 free(script_to_delete->script_content);
808 free(script_to_delete);
814 * Add or replace a new script.
815 * NOTE: after this function returns, "u" owns the memory that "script_content"
818 void msiv_putscript(struct sdm_userdata *u, char *script_name, char *script_content) {
820 struct sdm_script *s, *sptr;
822 for (s=u->first_script; s!=NULL; s=s->next) {
823 if (!strcasecmp(s->script_name, script_name)) {
824 if (s->script_content != NULL) {
825 free(s->script_content);
827 s->script_content = script_content;
833 sptr = malloc(sizeof(struct sdm_script));
834 safestrncpy(sptr->script_name, script_name, sizeof sptr->script_name);
835 sptr->script_content = script_content;
836 sptr->script_active = 0;
837 sptr->next = u->first_script;
838 u->first_script = sptr;
844 * Citadel protocol to manage sieve scripts.
845 * This is basically a simplified (read: doesn't resemble IMAP) version
846 * of the 'managesieve' protocol.
848 void cmd_msiv(char *argbuf) {
850 struct sdm_userdata u;
851 char script_name[256];
852 char *script_content = NULL;
853 struct sdm_script *s;
856 memset(&u, 0, sizeof(struct sdm_userdata));
858 if (CtdlAccessCheck(ac_logged_in)) return;
859 extract_token(subcmd, argbuf, 0, '|', sizeof subcmd);
862 if (!strcasecmp(subcmd, "putscript")) {
863 extract_token(script_name, argbuf, 1, '|', sizeof script_name);
864 if (strlen(script_name) > 0) {
865 cprintf("%d Transmit script now\n", SEND_LISTING);
866 script_content = CtdlReadMessageBody("000", config.c_maxmsglen, NULL, 0);
867 msiv_putscript(&u, script_name, script_content);
870 cprintf("%d Invalid script name.\n", ERROR + ILLEGAL_VALUE);
874 else if (!strcasecmp(subcmd, "listscripts")) {
875 cprintf("%d Scripts:\n", LISTING_FOLLOWS);
876 for (s=u.first_script; s!=NULL; s=s->next) {
877 if (s->script_content != NULL) {
878 cprintf("%s|%d|\n", s->script_name, s->script_active);
884 else if (!strcasecmp(subcmd, "setactive")) {
885 extract_token(script_name, argbuf, 1, '|', sizeof script_name);
886 if (msiv_setactive(&u, script_name) == 0) {
887 cprintf("%d ok\n", CIT_OK);
890 cprintf("%d Script '%s' does not exist.\n",
891 ERROR + ILLEGAL_VALUE,
897 else if (!strcasecmp(subcmd, "getscript")) {
898 extract_token(script_name, argbuf, 1, '|', sizeof script_name);
899 script_content = msiv_getscript(&u, script_name);
900 if (script_content != NULL) {
901 cprintf("%d Script:\n", SEND_LISTING);
902 cprintf("%s000\n", script_content);
905 cprintf("%d Invalid script name.\n", ERROR + ILLEGAL_VALUE);
909 else if (!strcasecmp(subcmd, "deletescript")) {
910 extract_token(script_name, argbuf, 1, '|', sizeof script_name);
911 i = msiv_deletescript(&u, script_name);
913 cprintf("%d ok\n", CIT_OK);
916 cprintf("%d Script '%s' does not exist.\n",
917 ERROR + ILLEGAL_VALUE,
922 cprintf("%d Script '%s' is active and cannot be deleted.\n",
923 ERROR + ILLEGAL_VALUE,
928 cprintf("%d unknown error\n", ERROR);
933 cprintf("%d Invalid subcommand\n", ERROR + CMD_NOT_SUPPORTED);
942 * We don't really care about dumping the entire credits to the log
943 * every time the server is initialized. The documentation will suffice
944 * for that purpose. We are making a call to sieve2_credits() in order
945 * to demonstrate that we have successfully linked in to libsieve.
947 void log_the_sieve2_credits(void) {
950 cred = strdup(sieve2_credits());
951 if (cred == NULL) return;
953 if (strlen(cred) > 60) {
954 strcpy(&cred[55], "...");
957 lprintf(CTDL_INFO, "%s\n",cred);
963 char *serv_sieve_init(void)
965 log_the_sieve2_credits();
966 CtdlRegisterProtoHook(cmd_msiv, "MSIV", "Manage Sieve scripts");
967 return "$Id: serv_sieve.c 3850 2005-09-13 14:00:24Z ajc $";
970 #else /* HAVE_LIBSIEVE */
972 char *serv_sieve_init(void)
974 lprintf(CTDL_INFO, "This server is missing libsieve. Mailbox filtering will be disabled.\n");
975 return "$Id: serv_sieve.c 3850 2005-09-13 14:00:24Z ajc $";
978 #endif /* HAVE_LIBSIEVE */