From 582012e400e28648a602804eeea6d701f2295306 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Mon, 6 Mar 2000 19:52:57 +0000 Subject: Try to prevent .fetchids from being randomly nuked. svn path=/trunk/; revision=2799 --- driver.c | 6 ++++++ fetchmail.h | 1 + uid.c | 23 ++++++++++++++++++----- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/driver.c b/driver.c index b10a1dd4..9c163d1d 100644 --- a/driver.c +++ b/driver.c @@ -1458,6 +1458,9 @@ const int maxfetch; /* maximum number of messages to fetch */ alrmsave = signal(SIGALRM, timeout_handler); mytimeout = ctl->server.timeout; + /* no UIDLs seen yet */ + ctl->have_uids = TRUE; + /* set up the broken-pipe timeout */ pipesave = signal(SIGPIPE, sigpipe_handler); @@ -1767,6 +1770,9 @@ const int maxfetch; /* maximum number of messages to fetch */ if (ok != 0) goto cleanUp; + /* we've now seen any UIDs that will be coming up the link */ + ctl->have_uids = TRUE; + /* show user how many messages we downloaded */ if (idp->id) (void) sprintf(buf, _("%s at %s (folder %s)"), diff --git a/fetchmail.h b/fetchmail.h index 76ec4a79..02cc3b9b 100644 --- a/fetchmail.h +++ b/fetchmail.h @@ -282,6 +282,7 @@ struct query unsigned int uid; /* UID of user to deliver to */ struct idlist *skipped; /* messages skipped on the mail server */ struct idlist *oldsaved, *newsaved; + flag have_uids; /* have we seen UIDs during this query? */ char *lastid; /* last Message-ID seen on this connection */ /* internal use -- per-message state */ diff --git a/uid.c b/uid.c index ba99fd5f..2f388a23 100644 --- a/uid.c +++ b/uid.c @@ -424,11 +424,24 @@ void uid_end_query(struct query *ctl) report_complete(stdout, "\n"); } - /* old state of mailbox may now be irrelevant */ - free_str_list(&ctl->oldsaved); - free_str_list(&scratchlist); - ctl->oldsaved = ctl->newsaved; - ctl->newsaved = (struct idlist *) NULL; + /* + * Don't swap UID lists unless we've actually seen UIDLs. + * This is necessary in order to keep UIDL information + * from being heedlessly deleted later on. + */ + if (ctl->have_uids) + { + /* old state of mailbox may now be irrelevant */ + if (outlevel >= O_DEBUG) + report(stdout, "swapping UID lists\n"); + free_str_list(&ctl->oldsaved); + free_str_list(&scratchlist); + ctl->oldsaved = ctl->newsaved; + ctl->newsaved = (struct idlist *) NULL; + ctl->have_uids = FALSE; + } + else if (outlevel >= O_DEBUG) + report(stdout, "not swapping UID lists, no UIDs seen this query\n"); } void write_saved_lists(struct query *hostlist, const char *idfile) -- cgit v1.2.3