X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=uid.c;h=8a775b9c63f48b60997f834f2d0f4f86f92bbe20;hb=ecade79a63e9abad933e3705a02533620ddc92b5;hp=de9160a11bb765e7a2f750bf9053a39dc52e86ca;hpb=bc3cb35033c8b90f2a3a03a0616ae02378d80f58;p=~andy%2Ffetchmail diff --git a/uid.c b/uid.c index de9160a1..8a775b9c 100644 --- a/uid.c +++ b/uid.c @@ -162,7 +162,7 @@ void initialize_saved_lists(struct query *hostlist, const char *idfile) * the rightmost '@'. This is not correct, as InterMail puts an * '@' in the UIDL. */ - + /* first, skip leading spaces */ user = buf + strspn(buf, " \t"); @@ -177,7 +177,7 @@ void initialize_saved_lists(struct query *hostlist, const char *idfile) * may contain ' ' in the user part, at least in * the lotus notes case. * So we start looking for the '@' after which the - * host will follow with the ' ' seperator finaly id. + * host will follow with the ' ' separator with the id. * * XXX FIXME: There is a case this code cannot handle: * the user name cannot have blanks after a '@'. @@ -243,36 +243,31 @@ void initialize_saved_lists(struct query *hostlist, const char *idfile) if (outlevel >= O_DEBUG) { struct idlist *idp; - int uidlcount = 0; for (ctl = hostlist; ctl; ctl = ctl->next) - if (ctl->server.uidl) { report_build(stdout, GT_("Old UID list from %s:"), ctl->server.pollname); - for (idp = ctl->oldsaved; idp; idp = idp->next) { - char *t = sdump(idp->id, strlen(idp->id)); - report_build(stdout, " %s", t); - free(t); - } + idp = ctl->oldsaved; if (!idp) report_build(stdout, GT_(" ")); + else for (idp = ctl->oldsaved; idp; idp = idp->next) { + char *t = sdump(idp->id, strlen(idp->id)-1); + report_build(stdout, " %s\n", t); + free(t); + } report_complete(stdout, "\n"); - uidlcount++; } - if (uidlcount) - { - report_build(stdout, GT_("Scratch list of UIDs:")); - for (idp = scratchlist; idp; idp = idp->next) { - char *t = sdump(idp->id, strlen(idp->id)); - report_build(stdout, " %s", t); - free(t); - } - if (!idp) + report_build(stdout, GT_("Scratch list of UIDs:")); + if (!scratchlist) report_build(stdout, GT_(" ")); - report_complete(stdout, "\n"); + else for (idp = scratchlist; idp; idp = idp->next) { + char *t = sdump(idp->id, strlen(idp->id)-1); + report_build(stdout, " %s\n", t); + free(t); } + report_complete(stdout, "\n"); } } @@ -287,25 +282,52 @@ void expunge_uids(struct query *ctl) idl->val.status.mark = UID_EXPUNGED; } +static const char *str_uidmark(int mark) +{ + static char buf[20]; + + switch(mark) { + case UID_UNSEEN: + return "UNSEEN"; + case UID_SEEN: + return "SEEN"; + case UID_EXPUNGED: + return "EXPUNGED"; + case UID_DELETED: + return "DELETED"; + default: + if (snprintf(buf, sizeof(buf), "MARK=%d", mark) < 0) + return "ERROR"; + else + return buf; + } +} + +static void dump_list(const struct idlist *idp) +{ + if (!idp) { + report_build(stdout, GT_(" ")); + } else while (idp) { + char *t = sdump(idp->id, strlen(idp->id)); + report_build(stdout, " %s = %s%s", t, str_uidmark(idp->val.status.mark), idp->next ? "," : ""); + free(t); + idp = idp->next; + } +} + /* finish a query */ void uid_swap_lists(struct query *ctl) { /* debugging code */ - if (ctl->server.uidl && outlevel >= O_DEBUG) + if (outlevel >= O_DEBUG) { - struct idlist *idp; - - if (dofastuidl) + if (dofastuidl) { report_build(stdout, GT_("Merged UID list from %s:"), ctl->server.pollname); - else + dump_list(ctl->oldsaved); + } else { report_build(stdout, GT_("New UID list from %s:"), ctl->server.pollname); - for (idp = dofastuidl ? ctl->oldsaved : ctl->newsaved; idp; idp = idp->next) { - char *t = sdump(idp->id, strlen(idp->id)); - report_build(stdout, " %s = %d", t, idp->val.status.mark); - free(t); - } - if (!idp) - report_build(stdout, GT_(" ")); + dump_list(ctl->newsaved); + } report_complete(stdout, "\n"); } @@ -345,20 +367,12 @@ void uid_swap_lists(struct query *ctl) void uid_discard_new_list(struct query *ctl) { /* debugging code */ - if (ctl->server.uidl && outlevel >= O_DEBUG) + if (outlevel >= O_DEBUG) { - struct idlist *idp; - /* 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); - for (idp = ctl->oldsaved; idp; idp = idp->next) { - char *t = sdump(idp->id, strlen(idp->id)); - report_build(stdout, " %s = %d", t, idp->val.status.mark); - free(t); - } - if (!idp) - report_build(stdout, GT_(" ")); + dump_list(ctl->oldsaved); report_complete(stdout, "\n"); } @@ -414,18 +428,30 @@ void write_saved_lists(struct query *hostlist, const char *idfile) report(stdout, GT_("Writing fetchids file.\n")); (void)unlink(newnam); /* remove file/link first */ if ((tmpfp = fopen(newnam, "w")) != (FILE *)NULL) { - int errflg; + int errflg = 0; for (ctl = hostlist; ctl; ctl = ctl->next) { for (idp = ctl->oldsaved; idp; idp = idp->next) if (idp->val.status.mark == UID_SEEN || idp->val.status.mark == UID_DELETED) - fprintf(tmpfp, "%s@%s %s\n", - ctl->remotename, ctl->server.queryname, idp->id); + if (fprintf(tmpfp, "%s@%s %s\n", + ctl->remotename, ctl->server.queryname, idp->id) < 0) { + int e = errno; + report(stderr, GT_("Write error on fetchids file %s: %s\n"), newnam, strerror(e)); + errflg = 1; + goto bailout; + } } for (idp = scratchlist; idp; idp = idp->next) - fputs(idp->id, tmpfp); - fflush(tmpfp); - errflg = ferror(tmpfp); + if (EOF == fputs(idp->id, tmpfp)) { + int e = errno; + report(stderr, GT_("Write error on fetchids file %s: %s\n"), newnam, strerror(e)); + errflg = 1; + goto bailout; + } + +bailout: + (void)fflush(tmpfp); /* return code ignored, we check ferror instead */ + errflg |= ferror(tmpfp); fclose(tmpfp); /* if we could write successfully, move into place; * otherwise, drop */