]> Pileus Git - ~andy/fetchmail/blobdiff - uid.c
LynxOS support.
[~andy/fetchmail] / uid.c
diff --git a/uid.c b/uid.c
index 000c02330f3e38abe5fcc7fd6aae1c12d8dfc8c6..4f92f47006d54d9b472ea01a9489b5579f141d4d 100644 (file)
--- a/uid.c
+++ b/uid.c
@@ -7,6 +7,7 @@
 #include "config.h"
 
 #include <stdio.h>
+#include <limits.h>
 #if defined(STDC_HEADERS)
 #include <stdlib.h>
 #include <string.h>
  * not respond to the request for a UID listing.
  *
  * Each time a message is fetched, we can check its UID against the
- * `oldsaved' list to see if it is old.  If not, it should be downloaded
- * (and possibly deleted).  It should be downloaded anyway if --all
- * is on.  It should not be deleted if --keep is on.
+ * `oldsaved' list to see if it is old.
  *
- * Each time a message is deleted, we mark its id UID_DELETED from the
+ * Each time a message-id is seen, we mark it with MARK_SEEN.
+ *
+ * Each time a message is deleted, we mark its id UID_DELETED in the
  * `newsaved' member.  When we want to assert that an expunge has been
  * done on the server, we call expunge_uid() to register that all
  * deleted messages are gone by marking them UID_EXPUNGED.
  * At the end of the query, the `newsaved' member becomes the
  * `oldsaved' list.  The old `oldsaved' list is freed.
  *
- * At the end of the fetchmail run, non-EXPUNGED members of all
+ * At the end of the fetchmail run, seen and non-EXPUNGED members of all
  * current `oldsaved' lists are flushed out to the .fetchids file to
- * be picked up by the next run.  (The UID_EXPUNGED test means that a
- * message marked UID_DELETED may still have its ID go to disk if
- * there has been no intervening expunge operation.  This typically
- * comes up if the query was aborted by a line hit before a quit or
- * expunge was sent to the server.)  If there are no un-expunged
+ * 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 */
@@ -79,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) {
@@ -96,14 +93,14 @@ 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, UID_KEPT, id);
+                       save_str(&ctl->oldsaved, id, UID_SEEN);
                        break;
                    }
                }
 
                /* if it's not in a host we're querying, save it anyway */
                if (ctl == (struct query *)NULL)
-                   save_str(&scratchlist, UID_KEPT, buf);
+                   save_str(&scratchlist, buf, UID_SEEN);
            }
        }
        fclose(tmpfp);
@@ -111,7 +108,7 @@ void initialize_saved_lists(struct query *hostlist, const char *idfile)
 }
 #endif /* POP3_ENABLE */
 
-struct idlist *save_str(struct idlist **idl, int num, const char *str)
+struct idlist *save_str(struct idlist **idl, const char *str, flag status)
 /* save a number/UID pair on the given UID list */
 {
     struct idlist **end;
@@ -121,7 +118,7 @@ struct idlist *save_str(struct idlist **idl, int num, const char *str)
        continue;
 
     *end = (struct idlist *)xmalloc(sizeof(struct idlist));
-    (*end)->val.num = num;
+    (*end)->val.status.mark = status;
     (*end)->id = str ? xstrdup(str) : (char *)NULL;
     (*end)->next = NULL;
 
@@ -173,15 +170,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 )
@@ -192,21 +191,46 @@ 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;
 }
 
-int count_list( struct idlist **idl )
-  /* count the number of elements in the list */
+int str_nr_last_in_list( struct idlist **idl, const char *str)
+/* return the last position of str in idl */
+{
+    int nr, ret = -1;
+    struct idlist *walk;
+    if ( !str )
+        return -1;
+    for( walk = *idl, nr = 0; walk; nr ++, walk = walk->next )
+        if( strcmp( str, walk->id) == 0 )
+           ret = nr;
+    return ret;
+}
+
+void str_set_mark( struct idlist **idl, const char *str, const flag val)
+/* update the mark on an of an id to given value */
+{
+    int nr;
+    struct idlist *walk;
+    if (!str)
+        return;
+    for(walk = *idl, nr = 0; walk; nr ++, walk = walk->next)
+        if (strcmp(str, walk->id) == 0)
+           walk->val.status.mark = val;
+}
+
+int count_list( struct idlist **idl)
+/* count the number of elements in the list */
 {
   if( !*idl )
     return 0;
   return 1 + count_list( &(*idl)->next );
 }
 
-char* str_from_nr_list( struct idlist **idl, int number )
-  /* return the number'th string in idl */
+char *str_from_nr_list(struct idlist **idl, int number)
+/* return the number'th string in idl */
 {
     if( !*idl  || number < 0)
         return 0;
@@ -221,7 +245,7 @@ char *str_find(struct idlist **idl, int number)
 {
     if (*idl == (struct idlist *) 0)
        return((char *) 0);
-    else if (number == (*idl)->val.num)
+    else if (number == (*idl)->val.status.num)
        return((*idl)->id);
     else
        return(str_find(&(*idl)->next, number));
@@ -241,37 +265,23 @@ char *idpair_find(struct idlist **idl, const char *id)
 int delete_str(struct idlist **idl, int num)
 /* delete given message from given list */
 {
-#ifdef HARD_DELETE     /* not used */
-    if (*idl == (struct idlist *)NULL)
-       return(0);
-    else if ((*idl)->val.num == num)
-    {
-       struct idlist   *next = (*idl)->next;
-
-       free ((*idl)->id);
-       free(*idl);
-       *idl = next;
-       return(1);
-    }
-    else
-       return(delete_str(&(*idl)->next, num));
-#else
     struct idlist      *idp;
 
     for (idp = *idl; idp; idp = idp->next)
-       if (idp->val.num == num)
+       if (idp->val.status.num == num)
        {
-           idp->val.num = UID_DELETED;
+           idp->val.status.mark = UID_DELETED;
            return(1);
        }
     return(0);
-#endif /* HARD_DELETE */
 }
 
 void append_str_list(struct idlist **idl, struct idlist **nidl)
 /* append nidl to idl (does not copy *) */
 {
-    if ((*idl) == (struct idlist *)NULL)
+    if ((*nidl) == (struct idlist *)NULL || *nidl == *idl)
+       return;
+    else if ((*idl) == (struct idlist *)NULL)
        *idl = *nidl;
     else if ((*idl)->next == (struct idlist *)NULL)
        (*idl)->next = *nidl;
@@ -286,8 +296,8 @@ void expunge_uids(struct query *ctl)
     struct idlist *idl;
 
     for (idl = ctl->newsaved; idl; idl = idl->next)
-       if (idl->val.num == UID_DELETED)
-           idl->val.num = UID_EXPUNGED;
+       if (idl->val.status.mark == UID_DELETED)
+           idl->val.status.mark = UID_EXPUNGED;
 }
 
 void update_str_lists(struct query *ctl)
@@ -320,7 +330,8 @@ void write_saved_lists(struct query *hostlist, const char *idfile)
        if ((tmpfp = fopen(idfile, "w")) != (FILE *)NULL) {
            for (ctl = hostlist; ctl; ctl = ctl->next) {
                for (idp = ctl->oldsaved; idp; idp = idp->next)
-                   if (idp->val.num != UID_EXPUNGED)
+                   if (idp->val.status.mark == UID_SEEN
+                               || idp->val.status.mark == UID_DELETED)
                        fprintf(tmpfp, "%s@%s %s\n", 
                            ctl->remotename, ctl->server.truename, idp->id);
            }