diff options
-rw-r--r-- | driver.c | 53 | ||||
-rw-r--r-- | imap.c | 6 | ||||
-rw-r--r-- | pop2.c | 8 | ||||
-rw-r--r-- | pop3.c | 26 |
4 files changed, 43 insertions, 50 deletions
@@ -491,7 +491,7 @@ struct method *proto; #ifdef HAVE_RRESVPORT_H int privport = -1; #endif /* HAVE_RRESVPORT_H */ - int first, num, count; + int num, count, deletions = 0; tagnum = 0; protocol = proto; @@ -534,24 +534,18 @@ struct method *proto; if (ok != 0) goto cleanUp; - /* compute count and first, and get UID list if possible */ - if ((*protocol->getrange)(socket, queryctl, &count, &first) != 0) + /* compute count, and get UID list if possible */ + if ((*protocol->getrange)(socket, queryctl, &count) != 0) goto cleanUp; - /* show user how many messages we'll be downloading */ + /* show user how many messages we downloaded */ if (outlevel > O_SILENT && outlevel < O_VERBOSE) if (count == 0) fprintf(stderr, "No mail from %s\n", queryctl->servername); - else if (first > 1) - fprintf(stderr, - "%d message%s from %s, %d new messages.\n", - count, count > 1 ? "s" : "", - queryctl->servername, count - first + 1); else fprintf(stderr, - "%d %smessage%s from %s.\n", - count, ok ? "" : "new ", - count > 1 ? "s" : "", + "%d message%s from %s.\n", + count, count > 1 ? "s" : "", queryctl->servername); if (count > 0) @@ -575,17 +569,15 @@ struct method *proto; } /* read, forward, and delete messages */ - for (num = queryctl->flush ? 1 : first; num <= count; num++) + for (num = 1; num <= count; num++) { - if (queryctl->flush && num < first && !queryctl->fetchall) - ok = 0; /* retrieval suppressed */ - else - { - /* we may want to reject this message based on its UID */ - if (!queryctl->fetchall && *protocol->is_old) - if ((*protocol->is_old)(socket, queryctl, num)) - continue; + int treat_as_new = + !*protocol->is_old + || !(*protocol->is_old)(socket, queryctl, num); + /* we may want to reject this message if it's old */ + if (treat_as_new || queryctl->fetchall) + { /* request a message */ (*protocol->fetch)(socket, num, &len); if (outlevel == O_VERBOSE) @@ -615,20 +607,21 @@ struct method *proto; } /* maybe we delete this message now? */ - if (protocol->delete) + if (protocol->delete + && !queryctl->keep + && (treat_as_new || queryctl->flush)) { - if ((num < first && queryctl->flush) || !queryctl->keep) { - if (outlevel > O_SILENT && outlevel < O_VERBOSE) - fprintf(stderr,"flushing message %d\n", num); - ok = (protocol->delete)(socket, queryctl, num); - if (ok != 0) - goto cleanUp; - } + deletions++; + if (outlevel > O_SILENT && outlevel < O_VERBOSE) + fprintf(stderr,"flushing message %d\n", num); + ok = (protocol->delete)(socket, queryctl, num); + if (ok != 0) + goto cleanUp; } } /* remove all messages flagged for deletion */ - if (!queryctl->keep && protocol->expunge_cmd) + if (protocol->expunge_cmd && deletions > 0) { ok = gen_transact(socket, protocol->expunge_cmd); if (ok != 0) @@ -90,12 +90,11 @@ char *buf; queryctl->remotename, queryctl->password)); } -static imap_getrange(socket, queryctl, countp, firstp) +static imap_getrange(socket, queryctl, countp) /* get range of messages to be fetched */ int socket; struct hostrec *queryctl; int *countp; -int *firstp; { int ok; @@ -107,7 +106,6 @@ int *firstp; return(ok); *countp = count; - *firstp = 1; return(0); } @@ -173,7 +171,7 @@ int number; return(gen_transact(socket, "STORE %d +FLAGS (\\Deleted)", number)); } -static struct method imap = +const static struct method imap = { "IMAP", /* Internet Message Access Protocol */ 143, /* standard IMAP2bis/IMAP4 port */ @@ -68,12 +68,11 @@ char *buf; queryctl->remotename, queryctl->password)); } -static pop2_getrange(socket, queryctl, countp, firstp) +static pop2_getrange(socket, queryctl, countp) /* get range of messages to be fetched */ int socket; struct hostrec *queryctl; int *countp; -int *firstp; { /* * We should have picked up a count of messages in the user's @@ -93,7 +92,6 @@ int *firstp; return(PS_ERROR); } - *firstp = 1; *countp = pound_arg; return(0); @@ -127,7 +125,7 @@ int number; return(gen_transact(socket, queryctl->keep ? "ACKS" : "ACKD")); } -static struct method pop2 = +const static struct method pop2 = { "POP2", /* Post Office Protocol v2 */ 109, /* standard POP2 port */ @@ -136,7 +134,7 @@ static struct method pop2 = pop2_ok, /* parse command response */ pop2_getauth, /* get authorization */ pop2_getrange, /* query range of messages */ - NULL, /* no UID check */ + NULL, /* messages are always new */ pop2_fetch, /* request given message */ pop2_trail, /* eat message trailer */ NULL, /* no POP2 delete method */ @@ -17,6 +17,8 @@ #include "socket.h" #include "fetchmail.h" +static int last; + int pop3_ok (argbuf,socket) /* parse command response */ char *argbuf; @@ -138,12 +140,11 @@ badAuth: return(PS_ERROR); } -static pop3_getrange(socket, queryctl, countp, firstp) +static pop3_getrange(socket, queryctl, countp) /* get range of messages to be fetched */ int socket; struct hostrec *queryctl; int *countp; -int *firstp; { int ok; char buf [POPBUFSIZE+1]; @@ -159,25 +160,28 @@ int *firstp; /* * Newer, RFC-1725-conformant POP servers may not have the LAST command. */ - *firstp = 1; + last = 0; if (*countp > 0 && !queryctl->fetchall) { char id [IDLEN+1]; - int num; gen_send(socket,"LAST"); ok = pop3_ok(buf,socket); - if (ok == 0 && sscanf(buf, "%d", &num) == 0) + if (ok == 0 && sscanf(buf, "%d", &last) == 0) return(PS_ERROR); - - /* crucial fork in the road here */ - if (ok != 0) - *firstp = num + 1; } return(0); } +static int pop3_is_old(socket, queryctl, num) +int socket; +struct hostrec *queryctl; +int num; +{ + return (num <= last); +} + static int pop3_fetch(socket, number, lenp) /* request nth message */ int socket; @@ -201,7 +205,7 @@ int number; return(ok); } -static struct method pop3 = +const static struct method pop3 = { "POP3", /* Post Office Protocol v3 */ 110, /* standard POP3 port */ @@ -210,7 +214,7 @@ static struct method pop3 = pop3_ok, /* parse command response */ pop3_getauth, /* get authorization */ pop3_getrange, /* query range of messages */ - NULL, /* can't check for recent */ + pop3_is_old, /* how do we tell a message is old? */ pop3_fetch, /* request given message */ NULL, /* no message trailer */ pop3_delete, /* how to delete a message */ |