]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
Avoid deleting mail currently being sent.
authorBen Schmidt <none@none>
Sun, 2 Feb 2014 23:02:12 +0000 (10:02 +1100)
committerBen Schmidt <none@none>
Sun, 2 Feb 2014 23:02:12 +0000 (10:02 +1100)
src/mlmmj-maintd.c

index d10ad4339c3565485adaefb67b46ee4d77319d61..66297219011a84f7a16afec73165d35d8f92e0cf 100644 (file)
@@ -247,6 +247,7 @@ int resend_queue(const char *listdir, const char *mlmmjsend)
                        ch = strrchr(mailname, '.');
                        MY_ASSERT(ch);
                        *ch = '\0';
+                       /* delete orphaned sidecar files */
                        if(stat(mailname, &st) < 0) {
                                if(errno == ENOENT) {
                                        *ch = '.';
@@ -267,11 +268,19 @@ int resend_queue(const char *listdir, const char *mlmmjsend)
                tofd = open(toname, O_RDONLY);
 
                if((fromfd < 0 && err == ENOENT) ||
-                  (tofd < 0 && errno == ENOENT)) {
-                       unlink(mailname);
-                       unlink(fromname);
-                       unlink(toname);
-                       unlink(reptoname);
+                               (tofd < 0 && errno == ENOENT)) {
+                       /* only delete old files to avoid deleting
+                          mail currently being sent */
+                       t = time(NULL);
+                       if(stat(mailname, &st) == 0) {
+                               if(t - st.st_mtime > (time_t)36000) {
+                                       unlink(mailname);
+                                       /* avoid leaving orphans */
+                                       unlink(fromname);
+                                       unlink(toname);
+                                       unlink(reptoname);
+                               }
+                       }
                        myfree(mailname);
                        myfree(fromname);
                        myfree(toname);