]> code.citadel.org Git - citadel.git/commitdiff
* FETCH now works for ranges *and* sets, and with sequence numbers *and* UID's
authorArt Cancro <ajc@citadel.org>
Wed, 25 Oct 2000 19:20:37 +0000 (19:20 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 25 Oct 2000 19:20:37 +0000 (19:20 +0000)
citadel/ChangeLog
citadel/imap_fetch.c
citadel/imap_fetch.h
citadel/serv_imap.c

index 7fc87ffa82f6a9d7fa569a30cdc9798f506e6c98..900d092d7cdcb9625c1ec4d5426c70d8447d6144 100644 (file)
@@ -1,4 +1,7 @@
  $Log$
+ Revision 573.16  2000/10/25 19:20:37  ajc
+ * FETCH now works for ranges *and* sets, and with sequence numbers *and* UID's
+
  Revision 573.15  2000/10/24 20:39:59  ajc
  * Added RFC822, RFC822.HEADER, RFC822.SIZE, RFC822.TEXT fetch keys to IMAP
 
@@ -2103,4 +2106,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import 
-
index 2bdcacb00a99d1155854bf02b779d10ffde2dd55..e32fb34491b4c7e81fa9279979be5f417eea6809 100644 (file)
@@ -369,8 +369,10 @@ int imap_extract_data_items(char **argv, char *items) {
  *
  * This function clears out the IMAP_FETCHED bits, then sets that bit for each
  * message included in the specified range.
+ *
+ * Set is_uid to 1 to fetch by UID instead of sequence number.
  */
-void imap_pick_range(char *range) {
+void imap_pick_range(char *range, int is_uid) {
        int i;
        int num_sets;
        int s;
@@ -394,6 +396,7 @@ void imap_pick_range(char *range) {
                extract_token(lostr, setstr, 0, ':');
                if (num_tokens(setstr, ':') >= 2) {
                        extract_token(histr, setstr, 1, ':');
+                       if (!strcmp(histr, "*")) sprintf(histr, "%d", INT_MAX);
                } 
                else {
                        strcpy(histr, lostr);
@@ -401,10 +404,20 @@ void imap_pick_range(char *range) {
                lo = atoi(lostr);
                hi = atoi(histr);
 
+               /* Loop through the array, flipping bits where appropriate */
                for (i = 1; i <= IMAP->num_msgs; ++i) {
-                       if ( (i>=lo) && (i<=hi)) {
-                               IMAP->flags[i-1] =
-                                       IMAP->flags[i-1] | IMAP_FETCHED;
+                       if (is_uid) {   /* fetch by sequence number */
+                               if ( (IMAP->msgids[i-1]>=lo)
+                                  && (IMAP->msgids[i-1]<=hi)) {
+                                       IMAP->flags[i-1] =
+                                               IMAP->flags[i-1] | IMAP_FETCHED;
+                               }
+                       }
+                       else {          /* fetch by uid */
+                               if ( (i>=lo) && (i<=hi)) {
+                                       IMAP->flags[i-1] =
+                                               IMAP->flags[i-1] | IMAP_FETCHED;
+                               }
                        }
                }
        }
@@ -426,7 +439,7 @@ void imap_fetch(int num_parms, char *parms[]) {
                return;
        }
 
-       imap_pick_range(parms[2]);
+       imap_pick_range(parms[2], 0);
 
        strcpy(items, "");
        for (i=3; i<num_parms; ++i) {
@@ -444,5 +457,45 @@ void imap_fetch(int num_parms, char *parms[]) {
        cprintf("%s OK FETCH completed\r\n", parms[0]);
 }
 
+/*
+ * This function is called by the main command loop.
+ */
+void imap_uidfetch(int num_parms, char *parms[]) {
+       char items[1024];
+       char *itemlist[256];
+       int num_items;
+       int i;
+       int have_uid_item = 0;
+
+       if (num_parms < 5) {
+               cprintf("%s BAD invalid parameters\r\n", parms[0]);
+               return;
+       }
+
+       imap_pick_range(parms[3], 1);
+
+       strcpy(items, "");
+       for (i=4; i<num_parms; ++i) {
+               strcat(items, parms[i]);
+               if (i < (num_parms-1)) strcat(items, " ");
+       }
+
+       num_items = imap_extract_data_items(itemlist, items);
+       if (num_items < 1) {
+               cprintf("%s BAD invalid data item list\r\n", parms[0]);
+               return;
+       }
+
+       /* If the "UID" item was not included, we include it implicitly
+        * because this is a UID FETCH command
+        */
+       for (i=0; i<num_items; ++i) {
+               if (!strcasecmp(itemlist[i], "UID")) ++have_uid_item;
+       }
+       if (have_uid_item == 0) itemlist[num_items++] = "UID";
+
+       imap_do_fetch(num_items, itemlist);
+       cprintf("%s OK UID FETCH completed\r\n", parms[0]);
+}
 
 
index 82939191bae865ffc188eda51a0173387b135378..31c2dd9ef397f2685415be63e1693e466ede39f2 100644 (file)
@@ -4,3 +4,4 @@
  */
 
 void imap_fetch(int num_parms, char *parms[]);
+void imap_uidfetch(int num_parms, char *parms[]);
index 21279c28a84b7182d8443be563221e300462348f..4a3bc9f7cdd00f727d62133dce37290c7122d3d0 100644 (file)
@@ -397,12 +397,11 @@ void imap_command_loop(void) {
        else if (!strcasecmp(parms[1], "FETCH")) {
                imap_fetch(num_parms, parms);
        }
-       /*
+
        else if ( (!strcasecmp(parms[1], "UID"))
                && (!strcasecmp(parms[2], "FETCH")) ) {
                imap_uidfetch(num_parms, parms);
        }
-       */
 
        else if (!strcasecmp(parms[1], "CLOSE")) {
                imap_close(num_parms, parms);