From: Ben Schmidt Date: Sun, 2 Feb 2014 23:02:12 +0000 (+1100) Subject: Avoid deleting mail currently being sent. X-Git-Tag: RELEASE_1_2_18_1~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fc7acbf8a05e18a8ec3c0d2a4e807b18db8385c4;p=thirdparty%2Fmlmmj.git Avoid deleting mail currently being sent. --- diff --git a/src/mlmmj-maintd.c b/src/mlmmj-maintd.c index d10ad433..66297219 100644 --- a/src/mlmmj-maintd.c +++ b/src/mlmmj-maintd.c @@ -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);