- if (*idl == (struct idlist *) 0)
- return((char *) 0);
- else if (strcmp(id, (*idl)->id) == 0)
- return((*idl)->val.id2 ? (*idl)->val.id2 : (*idl)->id);
- else
- return(idpair_find(&(*idl)->next, id));
+ /* debugging code */
+ if (outlevel >= O_DEBUG)
+ {
+ if (dofastuidl) {
+ report_build(stdout, GT_("Merged UID list from %s:"), ctl->server.pollname);
+ dump_uid_db(&ctl->oldsaved);
+ } else {
+ report_build(stdout, GT_("New UID list from %s:"), ctl->server.pollname);
+ dump_uid_db(&ctl->newsaved);
+ }
+ report_complete(stdout, "\n");
+ }
+
+ /*
+ * 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.
+ *
+ * Older versions of fetchmail did
+ *
+ * free_str_list(&scratchlist);
+ *
+ * after swap. This was wrong; we need to preserve the UIDL information
+ * from unqueried hosts. Unfortunately, not doing this means that
+ * under some circumstances UIDLs can end up being stored forever --
+ * specifically, if a user description is removed from .fetchmailrc
+ * with UIDLs from that account in .fetchids, there is no way for
+ * them to ever get garbage-collected.
+ */
+ if (uid_db_n_records(&ctl->newsaved))
+ {
+ swap_uid_db_data(&ctl->newsaved, &ctl->oldsaved);
+ clear_uid_db(&ctl->newsaved);
+ }
+ /* in fast uidl, there is no need to swap lists: the old state of
+ * mailbox cannot be discarded! */
+ else if (outlevel >= O_DEBUG && !dofastuidl)
+ report(stdout, GT_("not swapping UID lists, no UIDs seen this query\n"));