-void imap_do_fetch(int lo, int hi, char *items) {
+/*
+ * Back end function.
+ */
+void imap_do_fetch(int lo, int hi, int num_items, char **itemlist) {
+ int i;
+
+ cprintf("* imap_do_fetch() lo=%d hi=%d num_items=%d\r\n",
+ lo, hi, num_items);
+
+ for (i=0; i<num_items; ++i) {
+ cprintf("* item[%d] = <%s>\r\n", i, itemlist[i]);
+ }
}
+
+/*
+ * Break out the data items requested, possibly a parenthesized list.
+ * Returns the number of data items, or -1 if the list is invalid.
+ * NOTE: this function alters the string it is fed, and uses it as a buffer
+ * to hold the data for the pointers it returns.
+ */
+int imap_extract_data_items(char **argv, char *items) {
+ int num_items = 0;
+ int nest = 0;
+ int i, initial_len;
+ char *start;
+
+ /* Convert all whitespace to ordinary space characters. */
+ for (i=0; i<strlen(items); ++i) {
+ if (isspace(items[i])) items[i]=' ';
+ }
+
+ /* Strip leading and trailing whitespace, then strip leading and
+ * trailing parentheses if it's a list
+ */
+ striplt(items);
+ if ( (items[0]=='(') && (items[strlen(items)-1]==')') ) {
+ items[strlen(items)-1] = 0;
+ strcpy(items, &items[1]);
+ striplt(items);
+ }
+
+ /*
+ * Now break out the data items. We throw in one trailing space in
+ * order to avoid having to break out the last one manually.
+ */
+ strcat(items, " ");
+ start = items;
+ initial_len = strlen(items);
+ for (i=0; i<initial_len; ++i) {
+ if (items[i]=='(') ++nest;
+ if (items[i]=='[') ++nest;
+ if (items[i]=='<') ++nest;
+ if (items[i]=='{') ++nest;
+ if (items[i]==')') --nest;
+ if (items[i]==']') --nest;
+ if (items[i]=='>') --nest;
+ if (items[i]=='}') --nest;
+
+ if (nest <= 0) if (items[i]==' ') {
+ items[i] = 0;
+ argv[num_items++] = start;
+ start = &items[i+1];
+ }
+ }
+
+ return(num_items);
+
+}
+
+
+
+
+
/*
* This function is called by the main command loop.
*/
int lo = 0;
int hi = 0;
char lostr[1024], histr[1024], items[1024];
+ char *itemlist[256];
+ int num_items;
int i;
if (num_parms < 4) {
if (i < (num_parms-1)) strcat(items, " ");
}
- imap_do_fetch(lo, hi, 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;
+ }
+
+ imap_do_fetch(lo, hi, num_items, itemlist);
cprintf("%s OK FETCH completed\r\n", parms[0]);
}