]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_inetcfg.c
* Configuration for spam filter
[citadel.git] / citadel / serv_inetcfg.c
index 99ad26586869b6b7a43a707ae2aa7aaa253c7910..cb11d8322eebccab53d153eb6282a3dc666b532e 100644 (file)
 #include "genstamp.h"
 #include "domain.h"
 
+
+
+
 void inetcfg_setTo(struct CtdlMessage *msg) {
        char *conf;
        char buf[SIZ];
-
+       
        if (msg->cm_fields['M']==NULL) return;
        conf = strdoop(msg->cm_fields['M']);
 
@@ -68,6 +71,37 @@ void inetcfg_setTo(struct CtdlMessage *msg) {
 }
 
 
+void spamstrings_setTo(struct CtdlMessage *msg) {
+       char buf[SIZ];
+       char *conf;
+       struct spamstrings_t *sptr;
+       int i, n;
+
+       /* Clear out the existing list */
+       while (spamstrings != NULL) {
+               sptr = spamstrings;
+               spamstrings = spamstrings->next;
+               phree(sptr->string);
+               phree(sptr);
+       }
+
+       /* Read in the new list */
+       if (msg->cm_fields['M']==NULL) return;
+       conf = strdoop(msg->cm_fields['M']);
+       if (conf == NULL) return;
+
+       n = num_tokens(conf, '\n');
+       for (i=0; i<n; ++i) {
+               extract_token(buf, conf, i, '\n');
+               sptr = mallok(sizeof(struct spamstrings_t));
+               sptr->string = strdoop(buf);
+               sptr->next = spamstrings;
+               spamstrings = sptr;
+       }
+
+}
+
+
 /*
  * This handler detects changes being made to the system's Internet
  * configuration.
@@ -88,12 +122,15 @@ int inetcfg_aftersave(struct CtdlMessage *msg) {
                linelen = strcspn(ptr, "\n");
                if (linelen == 0) return(0);    /* end of headers */    
                
-               if ( (!strncasecmp(ptr, "Content-type: ", 14))
-                  && (!strncasecmp(&ptr[14], INTERNETCFG,
-                  strlen(INTERNETCFG) )) ) {
-                       /* Bingo!  The user is changing configs.
-                        */
-                       inetcfg_setTo(msg);
+               if (!strncasecmp(ptr, "Content-type: ", 14)) {
+                       if (!strncasecmp(&ptr[14], INTERNETCFG,
+                          strlen(INTERNETCFG))) {
+                               inetcfg_setTo(msg);     /* changing configs */
+                       }
+                       if (!strncasecmp(&ptr[14], SPAMSTRINGS,
+                          strlen(INTERNETCFG))) {
+                               spamstrings_setTo(msg); /* changing configs */
+                       }
                }
 
                ptr = strchr((char *)ptr, '\n');
@@ -115,10 +152,23 @@ void inetcfg_init_backend(long msgnum, void *userdata) {
 }
 
 
+void spamstrings_init_backend(long msgnum, void *userdata) {
+       struct CtdlMessage *msg;
+
+               msg = CtdlFetchMessage(msgnum);
+               if (msg != NULL) {
+               spamstrings_setTo(msg);
+                       CtdlFreeMessage(msg);
+       }
+}
+
+
 void inetcfg_init(void) {
        if (getroom(&CC->quickroom, SYSCONFIGROOM) != 0) return;
        CtdlForEachMessage(MSGS_LAST, 1, INTERNETCFG, NULL,
                inetcfg_init_backend, NULL);
+       CtdlForEachMessage(MSGS_LAST, 1, SPAMSTRINGS, NULL,
+               spamstrings_init_backend, NULL);
 }