+/** Finish a query which had errors */
+void uid_discard_new_list(struct query *ctl)
+{
+ /* debugging code */
+ if (outlevel >= O_DEBUG)
+ {
+ /* this is now a merged list! the mails which were seen in this
+ * poll are marked here. */
+ report_build(stdout, GT_("Merged UID list from %s:"), ctl->server.pollname);
+ dump_uid_db(&ctl->oldsaved);
+ report_complete(stdout, "\n");
+ }
+
+ if (uid_db_n_records(&ctl->newsaved))
+ {
+ /* new state of mailbox is not reliable */
+ if (outlevel >= O_DEBUG)
+ report(stdout, GT_("discarding new UID list\n"));
+ clear_uid_db(&ctl->newsaved);
+ }
+}
+
+/** Reset the number associated with each id */
+void uid_reset_num(struct query *ctl)
+{
+ reset_uid_db_nums(&ctl->oldsaved);
+}
+
+/** Write list of seen messages, at end of run. */
+static int count_seen_deleted(struct uid_db_record *rec, void *arg)
+{
+ if (rec->status == UID_SEEN || rec->status == UID_DELETED)
+ ++*(long *)arg;
+ return 0;
+}
+
+struct write_saved_info {
+ struct query *ctl;
+ FILE *fp;
+};
+
+static int write_uid_db_record(struct uid_db_record *rec, void *arg)
+{
+ struct write_saved_info *info;
+ int rc;
+
+ if (!(rec->status == UID_SEEN || rec->status == UID_DELETED))
+ return 0;
+
+ info = (struct write_saved_info *)arg;
+ rc = fprintf(info->fp, "%s@%s %s\n",
+ info->ctl->remotename, info->ctl->server.queryname,
+ rec->id);
+ return rc < 0 ? -1 : 0;
+}
+
+/** Write new list of UIDs (state) to \a idfile. */