]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
Make resend_queue more robust
authormmj <none@none>
Mon, 20 Jun 2005 12:40:39 +0000 (22:40 +1000)
committermmj <none@none>
Mon, 20 Jun 2005 12:40:39 +0000 (22:40 +1000)
ChangeLog
VERSION
src/mlmmj-maintd.c
src/mlmmj-send.c
src/mlmmj-sub.c
src/mlmmj-unsub.c

index faf42859b2df902ea2693225274307f310bef1ef..7ea3fda461d116374b3c24e5aacabfec03241e27 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+1.2.8
+ o Make sure the resend of queue files will not loop indefinately
+ o Make Date: header RFC2822 compliant (Jakob Hirsch)
+ o Add -s switch to mlmmj-{,un}sub to control whether or not to send a mail
+   telling about already subscribed, or not subscribed when trying to
+   subscribe or unsubscribe (Christian Laursen)
 1.2.7
  o Remove old superflous cruft in the smtpreply reader function, making
    mlmmj-send not segfault in rare cases when SIGTERM was sent
diff --git a/VERSION b/VERSION
index c04c650a7ad4df822a872530c268e13aa3f3d4dc..9100c0cffae9258dc89109945b241e35455ce163 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.2.7
+1.2.8-rc1
index 4835d185e87cac071ef4cf26d83d4f63b926fdbf..327addff366bdeaa0521c2072665d81e35061c1d 100644 (file)
@@ -212,7 +212,7 @@ int resend_queue(const char *listdir, const char *mlmmjsend)
        char *bouncelifestr;
        pid_t childpid, pid;
        struct stat st;
-       int fromfd, tofd, fd, discarded = 0, status;
+       int fromfd, tofd, fd, status, err = 0;
        time_t t, bouncelife = 0;
 
        if(chdir(dirname) < 0) {
@@ -229,8 +229,10 @@ int resend_queue(const char *listdir, const char *mlmmjsend)
        myfree(dirname);
 
        while((dp = readdir(queuedir)) != NULL) {
-               if(stat(dp->d_name, &st) < 0) {
-                       log_error(LOG_ARGS, "Could not stat(%s)",dp->d_name);
+               mailname = concatstr(3, listdir, "/queue/", dp->d_name);
+
+               if(stat(mailname, &st) < 0) {
+                       log_error(LOG_ARGS, "Could not stat(%s)", mailname);
                        continue;
                }
 
@@ -238,49 +240,51 @@ int resend_queue(const char *listdir, const char *mlmmjsend)
                        continue;
 
                if(strchr(dp->d_name, '.')) {
-                       mailname = mystrdup(dp->d_name);
-                       ch = strchr(mailname, '.');
+                       ch = strrchr(mailname, '.');
                        *ch = '\0';
-                       if(stat(mailname, &st) < 0)
-                               if(errno == ENOENT)
-                                       unlink(dp->d_name);
+                       if(stat(mailname, &st) < 0) {
+                               if(errno == ENOENT) {
+                                       *ch = '.';
+                                       unlink(mailname);
+                               }
+                       }
                        myfree(mailname);
                        continue;
                }
 
-               mailname = concatstr(3, listdir, "/queue/", dp->d_name);
-
                fromname = concatstr(2, mailname, ".mailfrom");
                toname = concatstr(2, mailname, ".reciptto");
                reptoname = concatstr(2, mailname, ".reply-to");
 
                fromfd = open(fromname, O_RDONLY);
+               if(fromfd < 0)
+                       err = errno;
                tofd = open(toname, O_RDONLY);
 
-               if(fromfd < 0 || tofd < 0) {
-                       if(discarded) {
-                               unlink(fromname);
-                               unlink(toname);
-                               unlink(reptoname);
-                       }
+               if((fromfd < 0 && err == ENOENT) ||
+                  (tofd < 0 && errno == ENOENT)) {
+                       unlink(mailname);
+                       unlink(fromname);
+                       unlink(toname);
+                       unlink(reptoname);
                        myfree(mailname);
                        myfree(fromname);
                        myfree(toname);
                        myfree(reptoname);
                        if(fromfd >= 0)
                                close(fromfd);
+                       if(tofd >= 0)
+                               close(tofd);
                        continue;
                }
 
                from = mygetline(fromfd);
                chomp(from);
                close(fromfd);
-               unlink(fromname);
                myfree(fromname);
                to = mygetline(tofd);
                chomp(to);
                close(tofd);
-               unlink(toname);
                myfree(toname);
                fd = open(reptoname, O_RDONLY);
                if(fd < 0) {
@@ -290,7 +294,6 @@ int resend_queue(const char *listdir, const char *mlmmjsend)
                        repto = mygetline(fd);
                        chomp(repto);
                        close(fd);
-                       unlink(reptoname);
                        myfree(reptoname);
                }
 
index edb87ff3f071ef6dc1c51c17e8f66970bffacb35..57f920e300209782356a3939847b676158c35177 100644 (file)
@@ -927,8 +927,13 @@ int main(int argc, char **argv)
                if(sendres) {
                        /* error, so keep it in the queue */
                        deletewhensent = 0;
-                       /* dump date we want when resending */
+                       /* dump data we want when resending first check
+                        * if it already exists. In that case continue */
                        tmpstr = concatstr(2, mailfilename, ".mailfrom");
+                       if(stat(tmpstr, &st) == 0) {
+                               myfree(tmpstr);
+                               break;
+                       }
                        tmpfd = open(tmpstr, O_WRONLY|O_CREAT|O_TRUNC,
                                                S_IRUSR|S_IWUSR);
                        myfree(tmpstr);
@@ -938,6 +943,10 @@ int main(int argc, char **argv)
                        }
                        close(tmpfd);
                        tmpstr = concatstr(2, mailfilename, ".reciptto");
+                       if(stat(tmpstr, &st) == 0) {
+                               myfree(tmpstr);
+                               break;
+                       }
                        tmpfd = open(tmpstr, O_WRONLY|O_CREAT|O_TRUNC,
                                                S_IRUSR|S_IWUSR);
                        myfree(tmpstr);
@@ -949,6 +958,10 @@ int main(int argc, char **argv)
                        if(replyto) {
                                tmpstr = concatstr(2, mailfilename,
                                                      ".reply-to");
+                               if(stat(tmpstr, &st) == 0) {
+                                       myfree(tmpstr);
+                                       break;
+                               }
                                tmpfd = open(tmpstr, O_WRONLY|O_CREAT|O_TRUNC,
                                                        S_IRUSR|S_IWUSR);
                                myfree(tmpstr);
index 53a23ac1d21954c3036a4c491562d19e0c35d9e1..d2656445299897d09e5f608bdeb4d69b28964202 100644 (file)
@@ -225,7 +225,7 @@ void generate_subconfirm(const char *listdir, const char *listaddr,
 static void print_help(const char *prg)
 {
        printf("Usage: %s -L /path/to/list -a john@doe.org "
-              "[-c] [-C] [-h]\n       [-L] [-d | -n] [-U] [-V]\n"
+              "[-c] [-C] [-h]\n       [-L] [-d | -n] [-s] [-U] [-V]\n"
               " -a: Email address to subscribe \n"
               " -c: Send welcome mail\n"
               " -C: Request mail confirmation\n"
@@ -233,6 +233,7 @@ static void print_help(const char *prg)
               " -h: This help\n"
               " -L: Full path to list directory\n"
               " -n: Subscribe to no mail version of list\n"
+              " -s: Don't send a mail to the subscriber if already subscribed\n"
               " -U: Don't switch to the user id of the listdir owner\n"
               " -V: Print version\n"
               "When no options are specified, subscription silently "
@@ -276,7 +277,7 @@ int main(int argc, char **argv)
        char *sublockname;
        int subconfirm = 0, confirmsub = 0, opt, subfilefd, lock, notifysub;
        int changeuid = 1, status, digest = 0, nomail = 0;
-       int groupwritable = 0, sublock, sublockfd;
+       int groupwritable = 0, sublock, sublockfd, nogensubscribed = 0;
        size_t len;
        off_t suboff;
        struct stat st;
@@ -292,7 +293,7 @@ int main(int argc, char **argv)
        mlmmjsend = concatstr(2, bindir, "/mlmmj-send");
        myfree(bindir);
 
-       while ((opt = getopt(argc, argv, "hcCdnVUL:a:")) != -1) {
+       while ((opt = getopt(argc, argv, "hcCdnsVUL:a:")) != -1) {
                switch(opt) {
                case 'a':
                        address = optarg;
@@ -315,6 +316,9 @@ int main(int argc, char **argv)
                case 'n':
                        nomail = 1;
                        break;
+               case 's':
+                       nogensubscribed = 1;
+                       break;
                case 'U':
                        changeuid = 0;
                        break;
@@ -460,7 +464,8 @@ int main(int argc, char **argv)
                unlink(sublockname);
                myfree(sublockname);
 
-               generate_subscribed(listdir, address, mlmmjsend);
+               if(!nogensubscribed)
+                       generate_subscribed(listdir, address, mlmmjsend);
                
                return EXIT_SUCCESS;
        }
index e5e04bda7cfe1f60beb810f1f9566f0c307cd38a..29f7a78417f369851f7e8b6b1f47139ccf4a2c39 100644 (file)
@@ -269,7 +269,7 @@ ssize_t unsubscribe(int subreadfd, int subwritefd, const char *address)
 static void print_help(const char *prg)
 {
        printf("Usage: %s -L /path/to/list -a john@doe.org "
-              "[-c] [-C] [-h] [-L] [-d | -n] [-V]\n"
+              "[-c] [-C] [-h] [-L] [-d | -n] [-s] [-V]\n"
               " -a: Email address to unsubscribe \n"
               " -c: Send goodbye mail\n"
               " -C: Request mail confirmation\n"
@@ -277,6 +277,7 @@ static void print_help(const char *prg)
               " -h: This help\n"
               " -L: Full path to list directory\n"
               " -n: Subscribe to no mail version of list\n"
+              " -s: Don't send a mail to the address if not subscribed\n"
               " -U: Don't switch to the user id of the listdir owner\n"
               " -V: Print version\n"
               "When no options are specified, unsubscription silently "
@@ -319,6 +320,7 @@ int main(int argc, char **argv)
        int subread, subwrite, rlock, wlock, opt, unsubres, status, nomail = 0;
        int confirmunsub = 0, unsubconfirm = 0, notifysub = 0, digest = 0;
        int changeuid = 1, groupwritable = 0, sublock, sublockfd;
+       int nogennotsubscribed = 0;
        char *listaddr, *listdir = NULL, *address = NULL, *subreadname = NULL;
        char *subwritename, *mlmmjsend, *bindir, *subdir;
        char *subddirname, *sublockname;
@@ -338,7 +340,7 @@ int main(int argc, char **argv)
        mlmmjsend = concatstr(2, bindir, "/mlmmj-send");
        myfree(bindir);
 
-       while ((opt = getopt(argc, argv, "hcCdnVUL:a:")) != -1) {
+       while ((opt = getopt(argc, argv, "hcCdnVUL:a:s")) != -1) {
                switch(opt) {
                case 'L':
                        listdir = optarg;
@@ -361,6 +363,9 @@ int main(int argc, char **argv)
                case 'h':
                        print_help(argv[0]);
                        break;
+               case 's':
+                       nogennotsubscribed = 1;
+                       break;
                case 'U':
                        changeuid = 0;
                        break;
@@ -434,7 +439,9 @@ int main(int argc, char **argv)
                myfree(subddirname);
                myfree(listaddr);
 
-               generate_notsubscribed(listdir, address, mlmmjsend);
+               if(!nogennotsubscribed) {
+                       generate_notsubscribed(listdir, address, mlmmjsend);
+               }
 
                exit(EXIT_SUCCESS);
        }