]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
mlmmj-maintd now resends the ones that failed. Add listctrl switch to
authormmj <none@none>
Wed, 2 Jun 2004 19:10:11 +0000 (05:10 +1000)
committermmj <none@none>
Wed, 2 Jun 2004 19:10:11 +0000 (05:10 +1000)
do aid with it in mlmmj-send.

src/mlmmj-maintd.c
src/mlmmj-send.c

index 2e44265cf2f240551005bb6fc1dc32869ba22d57..2ad3b3c49adfd1d69159bf7e15830f04b2d00f7e 100644 (file)
@@ -252,17 +252,88 @@ int resend_queue(const char *listdir, const char *mlmmjsend)
 
 int resend_requeue(const char *listdir, const char *mlmmjsend)
 {
-#if 0
        DIR *queuedir;
        struct dirent *dp;
-#endif
+       char *dirname = concatstr(2, listdir, "/requeue/");
+       char *archivefilename, *subfilename, *subnewname;
+       struct stat st;
+       pid_t pid;
+       time_t t;
 
-       /* TODO: Go through all mails sitting in requeue/ and send the mail in the
-        * archive marked by the directory name in requeue/ to the people in
-        * the file subscribers sitting in the same dir.
-        * IMPORTANT: do not forget to *not* archive and *not* delete when
-        * sent.
-        */
+       if(chdir(dirname) < 0) {
+               log_error(LOG_ARGS, "Could not chdir(%s)", dirname);
+               free(dirname);
+               return 1;
+       }
+               
+       if((queuedir = opendir(dirname)) == NULL) {
+               log_error(LOG_ARGS, "Could not opendir(%s)", dirname);
+               free(dirname);
+               return 1;
+       }
+
+       while((dp = readdir(queuedir)) != NULL) {
+               if((strcmp(dp->d_name, "..") == 0) ||
+                       (strcmp(dp->d_name, ".") == 0))
+                               continue;
+
+               if(stat(dp->d_name, &st) < 0) {
+                       log_error(LOG_ARGS, "Could not stat(%s)",dp->d_name);
+                       continue;
+               }
+
+               if(!S_ISDIR(st.st_mode))
+                       continue;
+
+               /* Remove old empty directories */
+               t = time(NULL);
+               if(t - st.st_mtime > (time_t)3600)
+                       if(rmdir(dp->d_name) == 0)
+                               continue;
+
+               archivefilename = concatstr(3, listdir, "/archive/",
+                                               dp->d_name);
+               if(stat(archivefilename, &st) < 0) {
+                       /* Might be it's just not moved to the archive
+                        * yet because it's still getting sent, so just
+                        * continue
+                        */
+                       free(archivefilename);
+                       continue;
+               }
+               subfilename = concatstr(3, dirname, dp->d_name, "/subscribers");
+               if(stat(subfilename, &st) < 0) {
+                       log_error(LOG_ARGS, "Could not stat(%s)", subfilename);
+                       free(archivefilename);
+                       free(subfilename);
+                       continue;
+               }
+
+               subnewname = concatstr(2, subfilename, ".resending");
+
+               if(rename(subfilename, subnewname) < 0) {
+                       log_error(LOG_ARGS, "Could not rename(%s, %s)",
+                                               subfilename, subnewname);
+                       free(archivefilename);
+                       free(subfilename);
+                       free(subnewname);
+                       continue;
+               }
+               free(subfilename);
+               
+               pid = fork();
+
+               if(pid == 0)
+                       execlp(mlmmjsend, mlmmjsend,
+                                       "-l", "3",
+                                       "-L", listdir,
+                                       "-m", archivefilename,
+                                       "-s", subnewname,
+                                       "-a",
+                                       "-D", 0);
+
+
+       }
 
        return 0;
 }
index 969adb2969d967389e3ac52c9b7ee7e4ffa3602c..7c3a8f6da394e9cf6d8883d4516967f14743c3c7 100644 (file)
@@ -108,7 +108,7 @@ int bouncemail(const char *listdir, const char *mlmmjbounce, const char *from)
 
        if((c = strchr(myfrom, '@')) == NULL) {
                free(myfrom);
-               return 0; /* Success when mailformed 'from' */
+               return 0; /* Success when malformed 'from' */
        }
        *c = '\0';
        num = strrchr(myfrom, '-');
@@ -358,20 +358,21 @@ static void print_help(const char *prg)
 {
         printf("Usage: %s [-L /path/to/list || -l listctrl] -m /path/to/mail "
               "[-a] [-D] [-F]\n"
-              "       [-h] [-r] [-R] [-T] [-V]\n"
+              "       [-h] [-r] [-R] [-s] [-T] [-V]\n"
               " -a: Don't archive the mail\n"
               " -D: Don't delete the mail after it's sent\n"
               " -F: What to use as MAIL FROM:\n"
               " -h: This help\n"
-              " -l: List control variable:\n"
-              "    '1' means 'send a single mail'\n"
+              " -l: List control variable:\n", prg);
+       printf("    '1' means 'send a single mail'\n"
               "    '2' means 'mail to moderators'\n"
               " -L: Full path to list directory\n"
               " -m: Full path to mail file\n"
               " -r: Relayhost (defaults to localhost)\n"
               " -R: What to use as Reply-To: header\n"
+              " -s: Subscribers file name\n"
               " -T: What to use as RCPT TO:\n"
-              " -V: Print version\n", prg);
+              " -V: Print version\n");
        exit(EXIT_SUCCESS);
 }
 
@@ -397,7 +398,7 @@ int main(int argc, char **argv)
        mlmmjbounce = concatstr(2, bindir, "/mlmmj-bounce");
        free(bindir);
        
-       while ((opt = getopt(argc, argv, "aVDhm:l:L:R:F:T:r:")) != -1){
+       while ((opt = getopt(argc, argv, "aVDhm:l:L:R:F:T:r:s:")) != -1){
                switch(opt) {
                case 'a':
                        archive = 0;
@@ -426,6 +427,9 @@ int main(int argc, char **argv)
                case 'R':
                        replyto = optarg;
                        break;
+               case 's':
+                       subfilename = optarg;
+                       break;
                case 'T':
                        to_addr = optarg;
                        break;
@@ -456,7 +460,7 @@ int main(int argc, char **argv)
                exit(EXIT_FAILURE);
        }
 
-       if(listctrl[0] == '1' || listctrl[0] == '2')
+       if(listctrl[0] == '1' || listctrl[0] == '2' || listctrl[0] == '3')
                archive = 0;
 
        if(listdir)
@@ -484,6 +488,13 @@ int main(int argc, char **argv)
                        exit(EXIT_SUCCESS);
                }
                break;
+       case '3': /* resending earlier failed mails */
+               if((subfile = fopen(subfilename, "r")) == NULL) {
+                       log_error(LOG_ARGS, "Could not open '%s':",
+                                           subfilename);
+                       exit(EXIT_FAILURE);
+               }
+
        default: /* normal list mail -- now handled when forking */
                break;
        }
@@ -536,6 +547,13 @@ int main(int argc, char **argv)
                               NULL, NULL, listdir, NULL);
                endsmtp(&sockfd);
                break;
+       case '3': /* resending earlier failed mails */
+               initsmtp(&sockfd, relayhost);
+               send_mail_many(sockfd, NULL, NULL, mailfile, subfile,
+                               listaddr, mailfilename, listdir, mlmmjbounce);
+               endsmtp(&sockfd);
+               unlink(subfilename);
+               break;
        default: /* normal list mail */
                subddirname = concatstr(2, listdir, "/subscribers.d/");
                if((subddir = opendir(subddirname)) == NULL) {
@@ -589,11 +607,8 @@ int main(int argc, char **argv)
                                free(newsockfd);
                                fclose(subfile);
                                exit(EXIT_SUCCESS);
-                       } else {
-                               syslog(LOG_INFO, "%d/%d connections open",
-                                               conncount, MAX_CONNECTIONS);
+                       } else
                                fclose(subfile);
-                       }
                }
                closedir(subddir);
                break;