aboutsummaryrefslogtreecommitdiffstats
path: root/uid.c
diff options
context:
space:
mode:
Diffstat (limited to 'uid.c')
-rw-r--r--uid.c103
1 files changed, 95 insertions, 8 deletions
diff --git a/uid.c b/uid.c
index afc49678..91362418 100644
--- a/uid.c
+++ b/uid.c
@@ -63,9 +63,45 @@
* be picked up by the next run. If there are no un-expunged
* messages, the file is deleted.
*
+ * One disadvantage of UIDL is that all the UIDs have to be downloaded
+ * before a search for new messages can be done. Typically, new messages
+ * are appended to mailboxes. Hence, downloading all UIDs just to download
+ * a few new mails is a waste of bandwidth. If new messages are always at
+ * the end of the mailbox, fast UIDL will decrease the time required to
+ * download new mails.
+ *
+ * During fast UIDL, the UIDs of all messages are not downloaded! The first
+ * unseen message is searched for by using a binary search on UIDs. UIDs
+ * after the first unseen message are downloaded as and when needed.
+ *
+ * The advantages of fast UIDL are (this is noticeable only when the
+ * mailbox has too many mails):
+ *
+ * - There is no need to download the UIDs of all mails right at the start.
+ * - There is no need to save all the UIDs in memory separately in
+ * `newsaved' list.
+ * - There is no need to download the UIDs of seen mail (except for the
+ * first binary search).
+ * - The first new mail is downloaded considerably faster.
+ *
+ * The disadvantages are:
+ *
+ * - Since all UIDs are not downloaded, it is not possible to swap old and
+ * new list. The current state of the mailbox is essentially a merged state
+ * of old and new mails.
+ * - If an intermediate mail has been temporarily refused (say, due to 4xx
+ * code from the smtp server), this mail may not get downloaded.
+ * - If 'flush' is used, such intermediate mails will also get deleted.
+ *
+ * The first two disadvantages can be overcome by doing a linear search
+ * once in a while (say, every 10th poll). Also, with flush, fast UIDL
+ * should be disabled.
+ *
* Note: some comparisons (those used for DNS address lists) are caseblind!
*/
+int dofastuidl = 0;
+
/* UIDs associated with un-queried hosts */
static struct idlist *scratchlist;
@@ -305,20 +341,20 @@ void free_str_pair_list(struct idlist **idl)
}
#endif
-int str_in_list(struct idlist **idl, const char *str, const flag caseblind)
+struct idlist *str_in_list(struct idlist **idl, const char *str, const flag caseblind)
/* is a given ID in the given list? (comparison may be caseblind) */
{
struct idlist *walk;
if (caseblind) {
for( walk = *idl; walk; walk = walk->next )
if( strcasecmp( str, (char *)walk->id) == 0 )
- return 1;
+ return walk;
} else {
for( walk = *idl; walk; walk = walk->next )
if( strcmp( str, (char *)walk->id) == 0 )
- return 1;
+ return walk;
}
- return 0;
+ return NULL;
}
int str_nr_in_list( struct idlist **idl, const char *str )
@@ -389,6 +425,16 @@ char *str_find(struct idlist **idl, long number)
return(str_find(&(*idl)->next, number));
}
+struct idlist *id_find(struct idlist **idl, long number)
+/* return the id of the given number in the given list. */
+{
+ struct idlist *idp;
+ for (idp = *idl; idp; idp = idp->next)
+ if (idp->val.status.num == number)
+ return(idp);
+ return(0);
+}
+
char *idpair_find(struct idlist **idl, const char *id)
/* return the id of the given id in the given list (caseblind comparison) */
{
@@ -449,7 +495,7 @@ void expunge_uids(struct query *ctl)
{
struct idlist *idl;
- for (idl = ctl->newsaved; idl; idl = idl->next)
+ for (idl = dofastuidl ? ctl->oldsaved : ctl->newsaved; idl; idl = idl->next)
if (idl->val.status.mark == UID_DELETED)
idl->val.status.mark = UID_EXPUNGED;
}
@@ -462,8 +508,11 @@ void uid_swap_lists(struct query *ctl)
{
struct idlist *idp;
- report_build(stdout, GT_("New UID list from %s:"), ctl->server.pollname);
- for (idp = ctl->newsaved; idp; idp = idp->next)
+ if (dofastuidl)
+ report_build(stdout, GT_("Merged UID list from %s:"), ctl->server.pollname);
+ else
+ report_build(stdout, GT_("New UID list from %s:"), ctl->server.pollname);
+ for (idp = dofastuidl ? ctl->oldsaved : ctl->newsaved; idp; idp = idp->next)
report_build(stdout, " %s = %d", idp->id, idp->val.status.mark);
if (!idp)
report_build(stdout, GT_(" <empty>"));
@@ -495,10 +544,48 @@ void uid_swap_lists(struct query *ctl)
ctl->oldsaved = ctl->newsaved;
ctl->newsaved = (struct idlist *) NULL;
}
- else if (outlevel >= O_DEBUG)
+ /* 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"));
}
+void uid_discard_new_list(struct query *ctl)
+/* finish a query which had errors */
+{
+ /* debugging code */
+ if (ctl->server.uidl && 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)
+ report_build(stdout, " %s = %d", idp->id, idp->val.status.mark);
+ if (!idp)
+ report_build(stdout, GT_(" <empty>"));
+ report_complete(stdout, "\n");
+ }
+
+ if (ctl->newsaved)
+ {
+ /* new state of mailbox is not reliable */
+ if (outlevel >= O_DEBUG)
+ report(stdout, GT_("discarding new UID list\n"));
+ free_str_list(&ctl->newsaved);
+ ctl->newsaved = (struct idlist *) NULL;
+ }
+}
+
+void uid_reset_num(struct query *ctl)
+/* reset the number associated with each id */
+{
+ struct idlist *idp;
+ for (idp = ctl->oldsaved; idp; idp = idp->next)
+ idp->val.status.num = 0;
+}
+
void write_saved_lists(struct query *hostlist, const char *idfile)
/* perform end-of-run write of seen-messages list */
{