2 * $Id: serv_test.c 3850 2005-09-13 14:00:24Z ajc $
15 #include <sys/types.h>
17 #if TIME_WITH_SYS_TIME
18 # include <sys/time.h>
22 # include <sys/time.h>
33 #include "sysdep_decls.h"
34 #include "citserver.h"
37 #include "serv_extensions.h"
47 #include <sieve2_error.h>
48 #include "serv_sieve.h"
50 struct RoomProcList *sieve_list = NULL;
53 * Add a room to the list of those rooms which potentially require sieve processing
55 void sieve_queue_room(struct ctdlroom *which_room) {
56 struct RoomProcList *ptr;
58 ptr = (struct RoomProcList *) malloc(sizeof (struct RoomProcList));
59 if (ptr == NULL) return;
61 safestrncpy(ptr->name, which_room->QRname, sizeof ptr->name);
62 begin_critical_section(S_SIEVELIST);
63 ptr->next = sieve_list;
65 end_critical_section(S_SIEVELIST);
71 * Perform sieve processing for one message (called by sieve_do_room() for each message)
73 void sieve_do_msg(long msgnum, void *userdata) {
74 lprintf(CTDL_DEBUG, "Performing sieve processing on msg <%ld>\n", msgnum);
80 * Perform sieve processing for a single room
81 * FIXME ... actually do this instead of just talking about it
83 void sieve_do_room(char *roomname) {
85 /* FIXME check to see if this room has any sieve scripts to run */
87 lprintf(CTDL_DEBUG, "Performing Sieve processing for <%s>\n", roomname);
89 if (getroom(&CC->room, roomname) != 0) {
90 lprintf(CTDL_CRIT, "ERROR: cannot load <%s>\n", roomname);
94 /* Do something useful */
95 /* CtdlForEachMessage(MSGS_GT, sc.lastsent, NULL, NULL, NULL, */
96 /* FIXME figure out which messages haven't yet been processed by sieve */
97 CtdlForEachMessage(MSGS_LAST, 1, NULL, NULL, NULL,
99 NULL /* data for callback could be the script? */
105 * Perform sieve processing for all rooms which require it
107 void perform_sieve_processing(void) {
108 struct RoomProcList *ptr = NULL;
110 if (sieve_list != NULL) {
111 lprintf(CTDL_DEBUG, "Begin Sieve processing\n");
112 while (sieve_list != NULL) {
113 char spoolroomname[ROOMNAMELEN];
114 safestrncpy(spoolroomname, sieve_list->name, sizeof spoolroomname);
115 begin_critical_section(S_SIEVELIST);
117 /* pop this record off the list */
119 sieve_list = sieve_list->next;
122 /* invalidate any duplicate entries to prevent double processing */
123 for (ptr=sieve_list; ptr!=NULL; ptr=ptr->next) {
124 if (!strcasecmp(ptr->name, spoolroomname)) {
129 end_critical_section(S_SIEVELIST);
130 if (spoolroomname[0] != 0) {
131 sieve_do_room(spoolroomname);
140 * We don't really care about dumping the entire credits to the log
141 * every time the server is initialized. The documentation will suffice
142 * for that purpose. We are making a call to sieve2_credits() in order
143 * to demonstrate that we have successfully linked in to libsieve.
145 void log_the_sieve2_credits(void) {
148 cred = strdup(sieve2_credits());
149 if (cred == NULL) return;
151 if (strlen(cred) > 60) {
152 strcpy(&cred[55], "...");
155 lprintf(CTDL_INFO, "%s\n",cred);
160 char *serv_sieve_init(void)
162 log_the_sieve2_credits();
163 return "$Id: serv_sieve.c 3850 2005-09-13 14:00:24Z ajc $";
166 #else /* HAVE_LIBSIEVE */
168 char *serv_sieve_init(void)
170 lprintf(CTDL_INFO, "This server is missing libsieve. Mailbox filtering will be disabled.\n");
171 return "$Id: serv_sieve.c 3850 2005-09-13 14:00:24Z ajc $";
174 #endif /* HAVE_LIBSIEVE */