]> Pileus Git - ~andy/fetchmail/blobdiff - uid.c
Instrument the UID code.
[~andy/fetchmail] / uid.c
diff --git a/uid.c b/uid.c
index 93fabcbdcffc9a8124dbaf1409a63b35a6b2624a..106068e16ef0ef1238bc9e91031def3b5b8bca52 100644 (file)
--- a/uid.c
+++ b/uid.c
@@ -33,7 +33,7 @@
  * considered seen in `oldsaved'.  These are messages that were left in
  * the mailbox and *not deleted* on previous queries (we don't need to
  * remember the UIDs of deleted messages because ... well, they're gone!)
- * This list is initially set up by initialized_saved_list() from the
+ * This list is initially set up by initialize_saved_list() from the
  * .fetchids file.
  *
  * Early in the query, during the execution of the protocol-specific 
@@ -60,7 +60,7 @@
  * be picked up by the next run.  If there are no un-expunged
  * messages, the file is deleted.
  *
- * Note: all comparisons are caseblind!
+ * Note: some comparisons (those used for DNS address lists) are caseblind!  
  */
 
 /* UIDs associated with un-queried hosts */
@@ -76,7 +76,7 @@ void initialize_saved_lists(struct query *hostlist, const char *idfile)
 
     /* make sure lists are initially empty */
     for (ctl = hostlist; ctl; ctl = ctl->next)
-       ctl->oldsaved = ctl->newsaved = (struct idlist *)NULL;
+       ctl->skipped = ctl->oldsaved = ctl->newsaved = (struct idlist *)NULL;
 
     /* let's get stored message UIDs from previous queries */
     if ((tmpfp = fopen(idfile, "r")) != (FILE *)NULL) {
@@ -93,7 +93,7 @@ void initialize_saved_lists(struct query *hostlist, const char *idfile)
                        strcasecmp(host, ctl->server.truename) == 0
                                && strcasecmp(user, ctl->remotename) == 0)
                    {
-                       save_str(&ctl->oldsaved, id, UID_UNSEEN);
+                       save_str(&ctl->oldsaved, id, UID_SEEN);
                        break;
                    }
                }
@@ -105,6 +105,28 @@ void initialize_saved_lists(struct query *hostlist, const char *idfile)
        }
        fclose(tmpfp);
     }
+
+    if (outlevel >= O_DEBUG)
+    {
+       struct idlist   *idp;
+
+       for (ctl = hostlist; ctl; ctl = ctl->next)
+       {
+           report(stdout, "Old UID list from %s:", ctl->server.truename);
+           for (idp = ctl->oldsaved; idp; idp = idp->next)
+               report(stdout, " %s", idp->id);
+           if (!idp)
+               report(stdout, "<empty>");
+           report(stdout, "\n");
+       }
+
+       report(stdout, "Scratch list of UIDs:");
+       for (idp = scratchlist; idp; idp = idp->next)
+           report(stdout, " %s", idp->id);
+       if (!idp)
+           report(stdout, "<empty>");
+       report(stdout, "\n");
+    }
 }
 #endif /* POP3_ENABLE */
 
@@ -170,15 +192,17 @@ void free_str_pair_list(struct idlist **idl)
 }
 #endif
 
-int str_in_list(struct idlist **idl, const char *str)
-/* is a given ID in the given list? (comparison is caseblind) */
+int str_in_list(struct idlist **idl, const char *str, const flag caseblind)
+/* is a given ID in the given list? (comparison may be caseblind) */
 {
     if (*idl == (struct idlist *)NULL || str == (char *) NULL)
        return(0);
-    else if (strcasecmp(str, (*idl)->id) == 0)
+    else if (!caseblind && strcmp(str, (*idl)->id) == 0)
+       return(1);
+    else if (caseblind && strcasecmp(str, (*idl)->id) == 0)
        return(1);
     else
-       return(str_in_list(&(*idl)->next, str));
+       return(str_in_list(&(*idl)->next, str, caseblind));
 }
 
 int str_nr_in_list( struct idlist **idl, const char *str )
@@ -189,7 +213,7 @@ int str_nr_in_list( struct idlist **idl, const char *str )
     if ( !str )
         return -1;
     for( walk = *idl, nr = 0; walk; nr ++, walk = walk->next )
-        if( strcasecmp( str, walk->id) == 0 )
+        if( strcmp( str, walk->id) == 0 )
            return nr;
     return -1;
 }
@@ -202,7 +226,7 @@ int str_nr_last_in_list( struct idlist **idl, const char *str)
     if ( !str )
         return -1;
     for( walk = *idl, nr = 0; walk; nr ++, walk = walk->next )
-        if( strcasecmp( str, walk->id) == 0 )
+        if( strcmp( str, walk->id) == 0 )
            ret = nr;
     return ret;
 }
@@ -215,7 +239,7 @@ void str_set_mark( struct idlist **idl, const char *str, const flag val)
     if (!str)
         return;
     for(walk = *idl, nr = 0; walk; nr ++, walk = walk->next)
-        if (strcasecmp(str, walk->id) == 0)
+        if (strcmp(str, walk->id) == 0)
            walk->val.status.mark = val;
 }
 
@@ -304,6 +328,18 @@ void update_str_lists(struct query *ctl)
     free_str_list(&ctl->oldsaved);
     ctl->oldsaved = ctl->newsaved;
     ctl->newsaved = (struct idlist *) NULL;
+
+    if (outlevel >= O_DEBUG)
+    {
+       struct idlist *idp;
+
+       report(stdout, "New UID list from %s:", ctl->server.truename);
+       for (idp = ctl->oldsaved; idp; idp = idp->next)
+           report(stdout, " %s = %d", idp->id, idp->val.status.mark);
+       if (!idp)
+           report(stdout, "<empty>");
+       report(stdout, "\n");
+    }
 }
 
 void write_saved_lists(struct query *hostlist, const char *idfile)
@@ -323,7 +359,11 @@ void write_saved_lists(struct query *hostlist, const char *idfile)
 
     /* either nuke the file or write updated last-seen IDs */
     if (!idcount)
+    {
+       if (outlevel >= O_DEBUG)
+           report(stdout, "Deleting fetchids file.");
        unlink(idfile);
+    }
     else
        if ((tmpfp = fopen(idfile, "w")) != (FILE *)NULL) {
            for (ctl = hostlist; ctl; ctl = ctl->next) {