]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
Fixed requeue for lists with noarchive enabled
authorxi <none@none>
Tue, 14 Nov 2006 13:15:54 +0000 (00:15 +1100)
committerxi <none@none>
Tue, 14 Nov 2006 13:15:54 +0000 (00:15 +1100)
ChangeLog
src/mlmmj-maintd.c
src/mlmmj-send.c

index 492ecdbfaf82b32f296c54c9ef60cce6a3c769d8..10a9636ceb267dd4a612bf7c94def51d1bae2352 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+ o Fixed requeue for lists with noarchive enabled
 1.2.12
  o Fixed memory corruption in cleanquotedp()
  o Fixed bug in gethdrline() introduced in 1.2.12-RC3
index c08e1f1d991a9c8274b800212c462cae0593f866..e5925c18975272d3dc49590f6b4658abf7a5cc5d 100644 (file)
@@ -371,7 +371,7 @@ int resend_requeue(const char *listdir, const char *mlmmjsend)
        struct stat st;
        pid_t childpid, pid;
        time_t t;
-       int status;
+       int status, fromrequeuedir = 0;
 
        if(chdir(dirname) < 0) {
                log_error(LOG_ARGS, "Could not chdir(%s)", dirname);
@@ -412,10 +412,22 @@ int resend_requeue(const char *listdir, const char *mlmmjsend)
                         * continue
                         */
                        myfree(archivefilename);
-                       continue;
+
+                       /* If the list is set not to archive we want to look
+                        * in /requeue/ for a mailfile
+                        */
+                       archivefilename = concatstr(4, listdir, "/requeue/",
+                                                       dp->d_name, "/mailfile");
+                       if(stat(archivefilename, &st) < 0) {
+                               myfree(archivefilename);
+                               continue;
+                       }
+                       fromrequeuedir = 1;
                }
                subfilename = concatstr(3, dirname, dp->d_name, "/subscribers");
                if(stat(subfilename, &st) < 0) {
+                       if (fromrequeuedir)
+                               unlink(archivefilename);
                        myfree(archivefilename);
                        myfree(subfilename);
                        continue;
index 73f8c1e2f4495896ba8aaaaa80a922d4a5f80137..42005253fe0d93539e5e68bc90e80cd2cdcc09a5 100644 (file)
@@ -73,6 +73,34 @@ void catch_sig_term(int sig)
        gotsigterm = 1;
 }
 
+char *get_index_from_filename(const char *filename)
+{
+       char *myfilename, *indexstr, *ret;
+       size_t len;
+
+       myfilename = mystrdup(filename);
+       if (!myfilename) {
+               return NULL;
+       }
+
+       len = strlen(myfilename);
+       if (len > 9 && (strcmp(myfilename + len - 9, "/mailfile") == 0)) {
+               myfilename[len - 9] = '\0';
+       }
+
+       indexstr = strrchr(myfilename, '/');
+       if (indexstr) {
+               indexstr++;  /* skip the slash */
+       } else {
+               indexstr = myfilename;
+       }
+
+       ret = mystrdup(indexstr);
+       myfree(myfilename);
+
+       return ret;
+}
+
 char *bounce_from_adr(const char *recipient, const char *listadr,
                      const char *listdelim, const char *mailfilename)
 {
@@ -85,12 +113,7 @@ char *bounce_from_adr(const char *recipient, const char *listadr,
                return NULL;
        }
 
-       indexstr = strrchr(mymailfilename, '/');
-       if (indexstr) {
-               indexstr++;  /* skip the slash */
-       } else {
-               indexstr = mymailfilename;
-       }
+       indexstr = get_index_from_filename(mymailfilename);
 
        myrecipient = mystrdup(recipient);
        if (!myrecipient) {
@@ -142,6 +165,7 @@ char *bounce_from_adr(const char *recipient, const char *listadr,
        myfree(myrecipient);
        myfree(mylistadr);
        myfree(mylistdelim);
+       myfree(indexstr);
        myfree(mymailfilename);
 
        return bounceaddr;
@@ -579,7 +603,7 @@ int send_mail_many_list(int sockfd, const char *from, const char *replyto,
                   const char *mlmmjbounce, const char *hdrs, size_t hdrslen,
                   const char *body, size_t bodylen)
 {
-       int res = 0, i;
+       int res = 0, i, status;
        char *bounceaddr, *addr, *index;
 
        for(i = 0; i < addrs->count; i++) {
@@ -594,8 +618,10 @@ int send_mail_many_list(int sockfd, const char *from, const char *replyto,
                        /* we got SIGTERM, so save the addresses and bail */
                        log_error(LOG_ARGS, "TERM signal recieved, "
                                                "shutting down.");
-                       index = mybasename(archivefilename);
-                       return requeuemail(listdir, index, addrs, i);
+                       index = get_index_from_filename(archivefilename);
+                       status = requeuemail(listdir, index, addrs, i);
+                       myfree(index);
+                       return status;
                }
                if(from) {
                        res = send_mail(sockfd, from, addr, replyto,
@@ -611,8 +637,10 @@ int send_mail_many_list(int sockfd, const char *from, const char *replyto,
                }
                if(res && listaddr && archivefilename) {
                        /* we failed, so save the addresses and bail */
-                       index = mybasename(archivefilename);
-                       return requeuemail(listdir, index, addrs, i);
+                       index = get_index_from_filename(archivefilename);
+                       status = requeuemail(listdir, index, addrs, i);
+                       myfree(index);
+                       return status;
                }
        }
        return 0;
@@ -659,7 +687,7 @@ int main(int argc, char **argv)
        char *mlmmjbounce = NULL, *bindir, *mailmap, *probefile, *a;
        char *body = NULL, *hdrs = NULL, *memmailsizestr = NULL, *verp = NULL;
        char relay[16], *listname, *listfqdn, *verpfrom, *maxverprecipsstr;
-       char strindex[32], *reply, *strport;
+       char strindex[32], *reply, *strport, *requeuefilename;
        ssize_t memmailsize = 0;
        DIR *subddir;
        struct dirent *dp;
@@ -1227,7 +1255,13 @@ int main(int argc, char **argv)
                                                archivefilename);
                        }
                } else {
-                       unlink(mailfilename);
+                       len = strlen(listdir) + 9 + 20 + 9;
+                       requeuefilename = mymalloc(len);
+                       snprintf(requeuefilename, len, "%s/requeue/%d/mailfile", listdir,
+                               mindex);
+                       if (rename(mailfilename, requeuefilename) < 0)
+                               unlink(mailfilename);
+                       myfree(requeuefilename);
                }
                myfree(archivefilename);
        } else if(deletewhensent)