From 38528f8329458e9faf675677bc7a2e4524af3aa4 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Tue, 17 Feb 1998 22:58:54 +0000 Subject: Fix bad UID/fetchlimit interaction. svn path=/trunk/; revision=1645 --- NEWS | 1 + driver.c | 6 ++++++ fetchmail.h | 15 +++++++++++---- uid.c | 25 ++++++++++++------------- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/NEWS b/NEWS index f5d2afd2..9cba63db 100644 --- a/NEWS +++ b/NEWS @@ -51,6 +51,7 @@ fetchmail-4.3.7 () * Minor port patches from Philippe De Muyter. * Patch by Chun-Chung Chen to handle quotes in .netrc * IPv6 and IPSEC support patches from Craig Metz. +* Fix bad interaction between UID handling and fetchmail. fetchmail-4.3.6 (Fri Jan 23 00:25:57 EST 1998) * Improved RPM packaging with correct grouping and an icon. diff --git a/driver.c b/driver.c index cdfa866d..7afe9d3d 100644 --- a/driver.c +++ b/driver.c @@ -2069,6 +2069,12 @@ const struct method *proto; /* protocol method table */ * now. */ + /* tell the UID code we've seen this */ + if (ctl->newsaved) + for (idp = ctl->newsaved; idp; idp = idp->next) + if (idp->val.num == num) + MARK_SEEN(idp->val.num); + /* maybe we delete this message now? */ if (retained) { diff --git a/fetchmail.h b/fetchmail.h index 50ce5640..3347889f 100644 --- a/fetchmail.h +++ b/fetchmail.h @@ -159,10 +159,6 @@ struct query int batchlimit; /* max # msgs to pass in single SMTP session */ int expunge; /* max # msgs to pass between expunges */ - /* unseen, previous state of mailbox (initially from .fetchids) */ -#define UID_KEPT 0 /* this was remembered from a previous run */ -#define UID_DELETED -1 /* this message has been deleted */ -#define UID_EXPUNGED -2 /* this message has been expunged */ struct idlist *oldsaved, *newsaved; /* internal use */ @@ -174,6 +170,17 @@ struct query struct query *next; /* next query control block in chain */ }; +/* + * UID-index information. If the sign bit is on, this means the + * message UID has been seen or expunged and should be written + * out to .fetchids at end of run. + */ +#define UID_KEPT 0 /* remembered from a previous run */ +#define UID_DELETED INT_MIN /* this message has been deleted */ +#define UID_EXPUNGED INT_MAX /* this message has been expunged */ +#define SAVE_UID(n) ((n) < 0) /* must this UID be saved? */ +#define MARK_SEEN(n) n *= -1 /* mark a UID seen */ + /* * Numeric option handling. Numeric option value of zero actually means * it's unspecified. Value less than zero is zero. diff --git a/uid.c b/uid.c index 54d41589..1a904656 100644 --- a/uid.c +++ b/uid.c @@ -7,6 +7,7 @@ #include "config.h" #include +#include #if defined(STDC_HEADERS) #include #include @@ -44,6 +45,8 @@ * Each time a message is fetched, we can check its UID against the * `oldsaved' list to see if it is old. * + * Each time a message-id is seen, we mark it with MARK_SEEN. + * * Each time a message is deleted, we mark its id UID_DELETED in the * `newsaved' member. When we want to assert that an expunge has been * done on the server, we call expunge_uid() to register that all @@ -52,13 +55,9 @@ * At the end of the query, the `newsaved' member becomes the * `oldsaved' list. The old `oldsaved' list is freed. * - * At the end of the fetchmail run, non-EXPUNGED members of all + * At the end of the fetchmail run, seen and non-EXPUNGED members of all * current `oldsaved' lists are flushed out to the .fetchids file to - * be picked up by the next run. (The UID_EXPUNGED test means that a - * message marked UID_DELETED may still have its ID go to disk if - * there has been no intervening expunge operation. This typically - * comes up if the query was aborted by a line hit before a quit or - * expunge was sent to the server.) If there are no un-expunged + * be picked up by the next run. If there are no un-expunged * messages, the file is deleted. * * Note: all comparisons are caseblind! @@ -195,8 +194,8 @@ int str_nr_in_list( struct idlist **idl, const char *str ) return -1; } -int str_nr_last_in_list( struct idlist **idl, const char *str ) - /* return the last position of str in idl */ +int str_nr_last_in_list( struct idlist **idl, const char *str) +/* return the last position of str in idl */ { int nr, ret = -1; struct idlist *walk; @@ -208,16 +207,16 @@ int str_nr_last_in_list( struct idlist **idl, const char *str ) return ret; } -int count_list( struct idlist **idl ) - /* count the number of elements in the list */ +int count_list( struct idlist **idl) +/* count the number of elements in the list */ { if( !*idl ) return 0; return 1 + count_list( &(*idl)->next ); } -char* str_from_nr_list( struct idlist **idl, int number ) - /* return the number'th string in idl */ +char *str_from_nr_list(struct idlist **idl, int number) +/* return the number'th string in idl */ { if( !*idl || number < 0) return 0; @@ -331,7 +330,7 @@ void write_saved_lists(struct query *hostlist, const char *idfile) if ((tmpfp = fopen(idfile, "w")) != (FILE *)NULL) { for (ctl = hostlist; ctl; ctl = ctl->next) { for (idp = ctl->oldsaved; idp; idp = idp->next) - if (idp->val.num != UID_EXPUNGED) + if (SAVE_UID(idp->val.num)) fprintf(tmpfp, "%s@%s %s\n", ctl->remotename, ctl->server.truename, idp->id); } -- cgit v1.2.3