commit 87016f16033ef66dd4b13ee44262d843a326df76
parent 65c3199cd26a559956ac0b377a0422d1c5bfe21e
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Sun, 14 May 2023 05:59:47 +0000
Don't return immediately after failing to get a message
Instead of returing immediately if a message cannot be retrieved
or deleted in getmail(), continue on marking the message for deletion.
At the end, the number of messages which failed to be retrieved is
returned. In this way, one bad message doesn't prevent the whole
maildrop from being fetched. If it is a persistent error unrelated
to the message's content though, it just wastes resources.
Diffstat:
M | pop3.c | | | 18 | ++++++++++-------- |
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/pop3.c b/pop3.c
@@ -1,4 +1,4 @@
-/* $Id: pop3.c,v 1.13 2023/05/14 05:23:33 jacob Exp $ */
+/* $Id: pop3.c,v 1.14 2023/05/14 05:59:47 jacob Exp $ */
/*
* Copyright (c) 2022, 2023 Jacob R. Edwards <jacob@jacobedwards.org>
@@ -480,24 +480,24 @@ int
getmail(FILE *fp, int delete, char **mailer)
{
int len, i;
+ int fails;
struct scanlisting *listings;
int (*sendmail)(FILE *, char *, char **);
listings = pop_list(fp, &len);
if (listings == NULL)
- return 1;
+ return -1;
+ fails = 0;
sendmail = mailer ? mail : mbox;
for (i = 0; i < len; ++i) {
if (sendmail(fp, listings[i].msg, mailer) ||
- (delete && pop_dele(fp, listings[i].msg))) {
- free(listings);
- return 1;
- }
+ (delete && pop_dele(fp, listings[i].msg)))
+ ++fails;
}
free(listings);
- return 0;
+ return fails;
}
int
@@ -588,8 +588,10 @@ main(int argc, char *argv[])
if (stat(fp, stdout))
die("unable to stat");
} else {
- if (getmail(fp, delete, mailer))
+ if (getmail(fp, delete, mailer)) {
+ pop_quit(fp);
die("unable to get mail");
+ }
if (verbose && stat(fp, stderr))
die("unable to stat");
}