Added an elastic string buffer class to libcitadel. Why do I have a feeling I'm...
[citadel.git] / citadel / modules / listdeliver / serv_listdeliver.c
index 793291b44d16cdd9000d32660533ffabaaa065f9..7dd34630a0750c5fc5977fcf4f663163a50d18b9 100644 (file)
@@ -53,17 +53,40 @@ struct lddata {
 
 void listdeliver_do_msg(long msgnum, void *userdata) {
        struct lddata *ld = (struct lddata *) userdata;
-       ld->msgnum = msgnum;
+       if (!ld) return;
        char buf[SIZ];
 
-       struct CtdlMessage *TheMessage = CtdlFetchMessage(msgnum, 1);
+       ld->msgnum = msgnum;
+       if (msgnum <= 0) return;
 
-       int config_lines = num_tokens(ld->netconf, '\n');
-       for (int i=0; i<config_lines; ++i) {
-               extract_token(buf, ld->netconf, i, '\n', sizeof buf);
-               if ( (!strncasecmp(buf, "listrecp|", 9)) || (!strncasecmp(buf, "digestrecp|", 11)) ) {
-                       syslog(LOG_DEBUG, "\033[32mDeliver %ld to %s\033[0m", msgnum, buf);
-                       // FIXME
+       struct CtdlMessage *TheMessage = CtdlFetchMessage(msgnum, 1);
+       if (!TheMessage) return;
+
+       char *recipients = malloc(strlen(ld->netconf));
+       if (recipients) {
+               recipients[0] = 0;
+
+               int config_lines = num_tokens(ld->netconf, '\n');
+               for (int i=0; i<config_lines; ++i) {
+                       extract_token(buf, ld->netconf, i, '\n', sizeof buf);
+                       if (!strncasecmp(buf, "listrecp|", 9)) {
+                               if (recipients[0] != 0) {
+                                       strcat(recipients, ",");
+                               }
+                               strcat(recipients, &buf[9]);
+                       }
+                       if (!strncasecmp(buf, "digestrecp|", 11)) {
+                               if (recipients[0] != 0) {
+                                       strcat(recipients, ",");
+                               }
+                               strcat(recipients, &buf[11]);
+                       }
+               }
+               syslog(LOG_DEBUG, "\033[33m%s\033[0m", recipients);
+               struct recptypes *valid = validate_recipients(recipients, NULL, 0);
+               if (valid) {
+                       long new_msgnum = CtdlSubmitMsg(TheMessage, valid, "");
+                       free_recipients(valid);
                }
        }
        CM_Free(TheMessage);