4 * Implements the FETCH command in IMAP.
5 * This command is way too convoluted. Marc Crispin is a fscking idiot.
18 #include <sys/types.h>
27 #include "sysdep_decls.h"
28 #include "citserver.h"
31 #include "dynloader.h"
38 #include "internet_addressing.h"
39 #include "mime_parser.h"
40 #include "serv_imap.h"
41 #include "imap_tools.h"
42 #include "imap_fetch.h"
47 struct imap_fetch_part {
48 char desired_section[SIZ];
53 * Individual field functions for imap_do_fetch_msg() ...
58 void imap_fetch_uid(int seq) {
59 cprintf("UID %ld", IMAP->msgids[seq-1]);
62 void imap_fetch_flags(int seq) {
64 if (IMAP->flags[seq] & IMAP_DELETED) cprintf("\\Deleted ");
65 if (IMAP->flags[seq] & IMAP_SEEN) cprintf("\\Seen ");
69 void imap_fetch_internaldate(struct CtdlMessage *msg) {
73 if (msg->cm_fields['T'] != NULL) {
74 msgdate = atol(msg->cm_fields['T']);
80 datestring(buf, msgdate, DATESTRING_IMAP);
81 cprintf("INTERNALDATE \"%s\"", buf);
86 * Fetch RFC822-formatted messages.
88 * 'whichfmt' should be set to one of:
89 * "RFC822" entire message
90 * "RFC822.HEADER" headers only (with trailing blank line)
91 * "RFC822.SIZE" size of translated message
92 * "RFC822.TEXT" body only (without leading blank line)
94 void imap_fetch_rfc822(int msgnum, char *whichfmt, struct CtdlMessage *msg) {
98 long headers_size, text_size, total_size;
99 long bytes_remaining = 0;
104 lprintf(1, "Cannot open temp file: %s\n", strerror(errno));
109 * Load the message into a temp file for translation and measurement
111 CtdlRedirectOutput(tmp, -1);
112 CtdlOutputPreLoadedMsg(msg, msgnum, MT_RFC822, 0, 0, 1);
113 CtdlRedirectOutput(NULL, -1);
114 if (!is_valid_message(msg)) {
115 lprintf(1, "WARNING: output clobbered the message!\n");
119 * Now figure out where the headers/text break is. IMAP considers the
120 * intervening blank line to be part of the headers, not the text.
125 ptr = fgets(buf, sizeof buf, tmp);
128 if (strlen(buf) == 0) headers_size = ftell(tmp);
130 } while ( (headers_size == 0L) && (ptr != NULL) );
131 fseek(tmp, 0L, SEEK_END);
132 total_size = ftell(tmp);
133 text_size = total_size - headers_size;
135 if (!strcasecmp(whichfmt, "RFC822.SIZE")) {
136 cprintf("RFC822.SIZE %ld", total_size);
141 else if (!strcasecmp(whichfmt, "RFC822")) {
142 bytes_remaining = total_size;
146 else if (!strcasecmp(whichfmt, "RFC822.HEADER")) {
147 bytes_remaining = headers_size;
151 else if (!strcasecmp(whichfmt, "RFC822.TEXT")) {
152 bytes_remaining = text_size;
153 fseek(tmp, headers_size, SEEK_SET);
156 cprintf("%s {%ld}\r\n", whichfmt, bytes_remaining);
157 blocksize = sizeof(buf);
158 while (bytes_remaining > 0L) {
159 if (blocksize > bytes_remaining) blocksize = bytes_remaining;
160 fread(buf, blocksize, 1, tmp);
161 client_write(buf, blocksize);
162 bytes_remaining = bytes_remaining - blocksize;
171 * Load a specific part of a message into the temp file to be output to a
172 * client. FIXME we can handle parts like "2" and "2.1" and even "2.MIME"
173 * but we still can't handle "2.HEADER" (which might not be a problem, because
174 * we currently don't have the ability to break out nested RFC822's anyway).
176 * Note: mime_parser() was called with dont_decode set to 1, so we have the
177 * luxury of simply spewing without having to re-encode.
179 void imap_load_part(char *name, char *filename, char *partnum, char *disp,
180 void *content, char *cbtype, size_t length, char *encoding,
183 struct imap_fetch_part *imfp;
186 imfp = (struct imap_fetch_part *)cbuserdata;
188 if (!strcasecmp(partnum, imfp->desired_section)) {
189 fwrite(content, length, 1, imfp->output_fp);
192 sprintf(mbuf2, "%s.MIME", partnum);
194 if (!strcasecmp(imfp->desired_section, mbuf2)) {
195 fprintf(imfp->output_fp, "Content-type: %s", cbtype);
196 if (strlen(name) > 0)
197 fprintf(imfp->output_fp, "; name=\"%s\"", name);
198 fprintf(imfp->output_fp, "\r\n");
199 if (strlen(encoding) > 0)
200 fprintf(imfp->output_fp,
201 "Content-Transfer-Encoding: %s\r\n", encoding);
202 if (strlen(encoding) > 0) {
203 fprintf(imfp->output_fp, "Content-Disposition: %s",
205 if (strlen(filename) > 0) {
206 fprintf(imfp->output_fp, "; filename=\"%s\"",
209 fprintf(imfp->output_fp, "\r\n");
211 fprintf(imfp->output_fp, "Content-Length: %d\r\n", length);
212 fprintf(imfp->output_fp, "\r\n");
220 * Called by imap_fetch_envelope() to output the "From" field.
221 * This is in its own function because its logic is kind of complex. We
222 * really need to make this suck less.
224 void imap_output_envelope_from(struct CtdlMessage *msg) {
225 char user[1024], node[1024], name[1024];
227 cprintf("(("); /* open double-parens */
228 imap_strout(msg->cm_fields['A']); /* personal name */
229 cprintf(" NIL "); /* source route (not used) */
231 if (msg->cm_fields['F'] != NULL) {
232 process_rfc822_addr(msg->cm_fields['F'], user, node, name);
233 imap_strout(user); /* mailbox name (user id) */
235 if (!strcasecmp(node, config.c_nodename)) {
236 imap_strout(config.c_fqdn);
239 imap_strout(node); /* host name */
243 imap_strout(msg->cm_fields['A']); /* mailbox name (user id) */
245 imap_strout(msg->cm_fields['N']); /* host name */
248 cprintf(")) "); /* close double-parens */
253 * Implements the ENVELOPE fetch item
255 * FIXME ... we only output some of the fields right now. Definitely need
256 * to do all of them. Accurately, too.
258 * Note that the imap_strout() function can cleverly output NULL fields as NIL,
259 * so we don't have to check for that condition like we do elsewhere.
261 void imap_fetch_envelope(long msgnum, struct CtdlMessage *msg) {
262 char datestringbuf[SIZ];
264 char *fieldptr = NULL;
266 /* Parse the message date into an IMAP-format date string */
267 if (msg->cm_fields['T'] != NULL) {
268 msgdate = atol(msg->cm_fields['T']);
271 msgdate = time(NULL);
273 datestring(datestringbuf, msgdate, DATESTRING_IMAP);
275 /* Now start spewing data fields. The order is important, as it is
276 * defined by the protocol specification. Nonexistent fields must
277 * be output as NIL, existent fields must be quoted or literalled.
278 * The imap_strout() function conveniently does all this for us.
280 cprintf("ENVELOPE (");
283 imap_strout(datestringbuf);
287 imap_strout(msg->cm_fields['U']);
291 imap_output_envelope_from(msg);
295 /* FIXME ... check for a *real* Sender: field */
298 imap_output_envelope_from(msg);
303 /* FIXME ... check for a *real* Reply-to: field */
306 imap_output_envelope_from(msg);
309 cprintf("NIL "); /* to */
311 cprintf("NIL "); /* cc */
313 cprintf("NIL "); /* bcc */
316 fieldptr = rfc822_fetch_field(msg->cm_fields['M'], "In-reply-to");
317 imap_strout(fieldptr);
319 if (fieldptr != NULL) phree(fieldptr);
322 imap_strout(msg->cm_fields['I']);
329 * Strip any non header information out of a chunk of RFC822 data on disk,
330 * then boil it down to just the fields we want.
332 void imap_strip_headers(FILE *fp, char *section) {
334 char *which_fields = NULL;
335 int doing_headers = 0;
340 char *boiled_headers = NULL;
342 int done_headers = 0;
344 which_fields = strdoop(section);
346 if (!strncasecmp(which_fields, "HEADER.FIELDS", 13))
348 if (!strncasecmp(which_fields, "HEADER.FIELDS.NOT", 17))
351 for (i=0; i<strlen(which_fields); ++i) {
352 if (which_fields[i]=='(')
353 strcpy(which_fields, &which_fields[i+1]);
355 for (i=0; i<strlen(which_fields); ++i) {
356 if (which_fields[i]==')')
359 num_parms = imap_parameterize(parms, which_fields);
361 fseek(fp, 0L, SEEK_END);
362 boiled_headers = mallok((size_t)(ftell(fp) + 256L));
363 strcpy(boiled_headers, "");
367 while ( (done_headers == 0) && (fgets(buf, sizeof buf, fp) != NULL) ) {
368 if (!isspace(buf[0])) {
370 if (doing_headers == 0) ok = 1;
372 if (headers_not) ok = 1;
374 for (i=0; i<num_parms; ++i) {
375 if ( (!strncasecmp(buf, parms[i],
376 strlen(parms[i]))) &&
377 (buf[strlen(parms[i])]==':') ) {
378 if (headers_not) ok = 0;
386 strcat(boiled_headers, buf);
389 if (strlen(buf) == 0) done_headers = 1;
390 if (buf[0]=='\r') done_headers = 1;
391 if (buf[0]=='\n') done_headers = 1;
394 /* Now write it back */
396 fwrite(boiled_headers, strlen(boiled_headers), 1, fp);
398 ftruncate(fileno(fp), ftell(fp));
400 fprintf(fp, "\r\n"); /* add the trailing newline */
403 phree(boiled_headers);
408 * Implements the BODY and BODY.PEEK fetch items
410 void imap_fetch_body(long msgnum, char *item, int is_peek,
411 struct CtdlMessage *msg) {
418 long bytes_remaining = 0;
421 struct imap_fetch_part imfp;
423 /* extract section */
424 strcpy(section, item);
425 for (i=0; i<strlen(section); ++i) {
426 if (section[i]=='[') strcpy(section, §ion[i+1]);
428 for (i=0; i<strlen(section); ++i) {
429 if (section[i]==']') section[i] = 0;
431 lprintf(9, "Section is %s\n", section);
433 /* extract partial */
434 strcpy(partial, item);
435 for (i=0; i<strlen(partial); ++i) {
436 if (partial[i]=='<') {
437 strcpy(partial, &partial[i+1]);
441 for (i=0; i<strlen(partial); ++i) {
442 if (partial[i]=='>') partial[i] = 0;
444 if (is_partial == 0) strcpy(partial, "");
445 if (strlen(partial) > 0) lprintf(9, "Partial is %s\n", partial);
449 lprintf(1, "Cannot open temp file: %s\n", strerror(errno));
453 /* Now figure out what the client wants, and get it */
455 if (!strcmp(section, "")) { /* the whole thing */
456 CtdlRedirectOutput(tmp, -1);
457 CtdlOutputPreLoadedMsg(msg, msgnum, MT_RFC822, 0, 0, 1);
458 CtdlRedirectOutput(NULL, -1);
462 * If the client asked for just headers, or just particular header
463 * fields, strip it down.
465 else if (!strncasecmp(section, "HEADER", 6)) {
466 CtdlRedirectOutput(tmp, -1);
467 CtdlOutputPreLoadedMsg(msg, msgnum, MT_RFC822, 1, 0, 1);
468 CtdlRedirectOutput(NULL, -1);
469 imap_strip_headers(tmp, section);
473 * Anything else must be a part specifier.
474 * (Note value of 1 passed as 'dont_decode' so client gets it encoded)
477 safestrncpy(imfp.desired_section, section,
478 sizeof(imfp.desired_section));
479 imfp.output_fp = tmp;
481 mime_parser(msg->cm_fields['M'], NULL,
482 *imap_load_part, NULL, NULL,
488 fseek(tmp, 0L, SEEK_END);
489 bytes_remaining = ftell(tmp);
491 if (is_partial == 0) {
493 cprintf("BODY[%s] {%ld}\r\n", section, bytes_remaining);
496 sscanf(partial, "%ld.%ld", &pstart, &pbytes);
497 if ((bytes_remaining - pstart) < pbytes) {
498 pbytes = bytes_remaining - pstart;
500 fseek(tmp, pstart, SEEK_SET);
501 bytes_remaining = pbytes;
502 cprintf("BODY[%s] {%ld}<%ld>\r\n",
503 section, bytes_remaining, pstart);
506 blocksize = sizeof(buf);
507 while (bytes_remaining > 0L) {
508 if (blocksize > bytes_remaining) blocksize = bytes_remaining;
509 fread(buf, blocksize, 1, tmp);
510 client_write(buf, blocksize);
511 bytes_remaining = bytes_remaining - blocksize;
516 /* Mark this message as "seen" *unless* this is a "peek" operation */
518 CtdlSetSeen(msgnum, 1);
523 * Called immediately before outputting a multipart bodystructure
525 void imap_fetch_bodystructure_pre(
526 char *name, char *filename, char *partnum, char *disp,
527 void *content, char *cbtype, size_t length, char *encoding,
537 * Called immediately after outputting a multipart bodystructure
539 void imap_fetch_bodystructure_post(
540 char *name, char *filename, char *partnum, char *disp,
541 void *content, char *cbtype, size_t length, char *encoding,
547 extract_token(subtype, cbtype, 1, '/');
548 imap_strout(subtype);
555 * Output the info for a MIME part in the format required by BODYSTRUCTURE.
558 void imap_fetch_bodystructure_part(
559 char *name, char *filename, char *partnum, char *disp,
560 void *content, char *cbtype, size_t length, char *encoding,
566 int have_encoding = 0;
570 if (cbtype != NULL) if (strlen(cbtype)>0) have_cbtype = 1;
573 extract_token(buf, cbtype, 0, '/');
576 extract_token(buf, cbtype, 1, '/');
581 cprintf("\"TEXT\" \"PLAIN\" ");
584 cprintf("(\"CHARSET\" \"US-ASCII\"");
586 if (name != NULL) if (strlen(name)>0) {
587 cprintf(" \"NAME\" ");
591 if (filename != NULL) if (strlen(filename)>0) {
592 cprintf(" \"FILENAME\" ");
600 if (encoding != NULL) if (strlen(encoding) > 0) have_encoding = 1;
603 imap_strout(encoding);
610 cprintf("%ld ", length); /* bytes */
611 cprintf("NIL) "); /* lines */
617 * Spew the BODYSTRUCTURE data for a message. (Do you need a silencer if
618 * you're going to shoot a MIME? Do you need a reason to shoot Mark Crispin?
622 void imap_fetch_bodystructure (long msgnum, char *item,
623 struct CtdlMessage *msg) {
629 /* For non-RFC822 (ordinary Citadel) messages, this is short and
632 if (msg->cm_format_type != FMT_RFC822) {
634 /* *sigh* We have to RFC822-format the message just to be able
638 if (tmp == NULL) return;
639 CtdlRedirectOutput(tmp, -1);
640 CtdlOutputPreLoadedMsg(msg, msgnum, MT_RFC822, 0, 0, 1);
641 CtdlRedirectOutput(NULL, -1);
644 while (fgets(buf, sizeof buf, tmp) != NULL) ++lines;
648 cprintf("BODYSTRUCTURE (\"TEXT\" \"PLAIN\" "
649 "(\"CHARSET\" \"US-ASCII\") NIL NIL "
650 "\"7BIT\" %ld %ld)", bytes, lines);
655 /* For messages already stored in RFC822 format, we have to parse. */
656 cprintf("BODYSTRUCTURE ");
657 mime_parser(msg->cm_fields['M'],
659 *imap_fetch_bodystructure_part, /* part */
660 *imap_fetch_bodystructure_pre, /* pre-multi */
661 *imap_fetch_bodystructure_post, /* post-multi */
672 * imap_do_fetch() calls imap_do_fetch_msg() to output the deta of an
673 * individual message, once it has been successfully loaded from disk.
675 void imap_do_fetch_msg(int seq, struct CtdlMessage *msg,
676 int num_items, char **itemlist) {
679 cprintf("* %d FETCH (", seq);
681 for (i=0; i<num_items; ++i) {
683 if (!strncasecmp(itemlist[i], "BODY[", 5)) {
684 imap_fetch_body(IMAP->msgids[seq-1], itemlist[i],
687 else if (!strncasecmp(itemlist[i], "BODY.PEEK[", 10)) {
688 imap_fetch_body(IMAP->msgids[seq-1], itemlist[i],
691 else if (!strcasecmp(itemlist[i], "BODYSTRUCTURE")) {
692 imap_fetch_bodystructure(IMAP->msgids[seq-1],
695 else if (!strcasecmp(itemlist[i], "ENVELOPE")) {
696 imap_fetch_envelope(IMAP->msgids[seq-1], msg);
698 else if (!strcasecmp(itemlist[i], "FLAGS")) {
699 imap_fetch_flags(seq-1);
701 else if (!strcasecmp(itemlist[i], "INTERNALDATE")) {
702 imap_fetch_internaldate(msg);
704 else if (!strcasecmp(itemlist[i], "RFC822")) {
705 imap_fetch_rfc822(IMAP->msgids[seq-1], itemlist[i], msg);
707 else if (!strcasecmp(itemlist[i], "RFC822.HEADER")) {
708 imap_fetch_rfc822(IMAP->msgids[seq-1], itemlist[i], msg);
710 else if (!strcasecmp(itemlist[i], "RFC822.SIZE")) {
711 imap_fetch_rfc822(IMAP->msgids[seq-1], itemlist[i], msg);
713 else if (!strcasecmp(itemlist[i], "RFC822.TEXT")) {
714 imap_fetch_rfc822(IMAP->msgids[seq-1], itemlist[i], msg);
716 else if (!strcasecmp(itemlist[i], "UID")) {
720 if (i != num_items-1) cprintf(" ");
729 * imap_fetch() calls imap_do_fetch() to do its actual work, once it's
730 * validated and boiled down the request a bit.
732 void imap_do_fetch(int num_items, char **itemlist) {
734 struct CtdlMessage *msg;
736 if (IMAP->num_msgs > 0)
737 for (i = 0; i < IMAP->num_msgs; ++i)
738 if (IMAP->flags[i] & IMAP_SELECTED) {
739 msg = CtdlFetchMessage(IMAP->msgids[i]);
741 imap_do_fetch_msg(i+1, msg, num_items, itemlist);
742 CtdlFreeMessage(msg);
745 cprintf("* %d FETCH <internal error>\r\n", i+1);
753 * Back end for imap_handle_macros()
754 * Note that this function *only* looks at the beginning of the string. It
755 * is not a generic search-and-replace function.
757 void imap_macro_replace(char *str, char *find, char *replace) {
760 if (!strncasecmp(str, find, strlen(find))) {
761 if (str[strlen(find)]==' ') {
762 strcpy(holdbuf, &str[strlen(find)+1]);
763 strcpy(str, replace);
765 strcat(str, holdbuf);
767 if (str[strlen(find)]==0) {
768 strcpy(holdbuf, &str[strlen(find)+1]);
769 strcpy(str, replace);
777 * Handle macros embedded in FETCH data items.
778 * (What the heck are macros doing in a wire protocol? Are we trying to save
779 * the computer at the other end the trouble of typing a lot of characters?)
781 void imap_handle_macros(char *str) {
785 for (i=0; i<strlen(str); ++i) {
786 if (str[i]=='(') ++nest;
787 if (str[i]=='[') ++nest;
788 if (str[i]=='<') ++nest;
789 if (str[i]=='{') ++nest;
790 if (str[i]==')') --nest;
791 if (str[i]==']') --nest;
792 if (str[i]=='>') --nest;
793 if (str[i]=='}') --nest;
796 imap_macro_replace(&str[i],
798 "FLAGS INTERNALDATE RFC822.SIZE ENVELOPE"
800 imap_macro_replace(&str[i],
804 imap_macro_replace(&str[i],
806 "FLAGS INTERNALDATE RFC822.SIZE"
808 imap_macro_replace(&str[i],
810 "FLAGS INTERNALDATE RFC822.SIZE ENVELOPE BODY"
818 * Break out the data items requested, possibly a parenthesized list.
819 * Returns the number of data items, or -1 if the list is invalid.
820 * NOTE: this function alters the string it is fed, and uses it as a buffer
821 * to hold the data for the pointers it returns.
823 int imap_extract_data_items(char **argv, char *items) {
829 /* Convert all whitespace to ordinary space characters. */
830 for (i=0; i<strlen(items); ++i) {
831 if (isspace(items[i])) items[i]=' ';
834 /* Strip leading and trailing whitespace, then strip leading and
835 * trailing parentheses if it's a list
838 if ( (items[0]=='(') && (items[strlen(items)-1]==')') ) {
839 items[strlen(items)-1] = 0;
840 strcpy(items, &items[1]);
844 /* Parse any macro data items */
845 imap_handle_macros(items);
848 * Now break out the data items. We throw in one trailing space in
849 * order to avoid having to break out the last one manually.
853 initial_len = strlen(items);
854 for (i=0; i<initial_len; ++i) {
855 if (items[i]=='(') ++nest;
856 if (items[i]=='[') ++nest;
857 if (items[i]=='<') ++nest;
858 if (items[i]=='{') ++nest;
859 if (items[i]==')') --nest;
860 if (items[i]==']') --nest;
861 if (items[i]=='>') --nest;
862 if (items[i]=='}') --nest;
864 if (nest <= 0) if (items[i]==' ') {
866 argv[num_items++] = start;
877 * One particularly hideous aspect of IMAP is that we have to allow the client
878 * to specify arbitrary ranges and/or sets of messages to fetch. Citadel IMAP
879 * handles this by setting the IMAP_SELECTED flag for each message specified in
880 * the ranges/sets, then looping through the message array, outputting messages
881 * with the flag set. We don't bother returning an error if an out-of-range
882 * number is specified (we just return quietly) because any client braindead
883 * enough to request a bogus message number isn't going to notice the
886 * This function clears out the IMAP_SELECTED bits, then sets that bit for each
887 * message included in the specified range.
889 * Set is_uid to 1 to fetch by UID instead of sequence number.
891 void imap_pick_range(char *supplied_range, int is_uid) {
895 char setstr[SIZ], lostr[SIZ], histr[SIZ]; /* was 1024 */
897 char actual_range[SIZ];
900 * Handle the "ALL" macro
902 if (!strcasecmp(supplied_range, "ALL")) {
903 safestrncpy(actual_range, "1:*", sizeof actual_range);
906 safestrncpy(actual_range, supplied_range, sizeof actual_range);
910 * Clear out the IMAP_SELECTED flags for all messages.
912 for (i = 0; i < IMAP->num_msgs; ++i) {
913 IMAP->flags[i] = IMAP->flags[i] & ~IMAP_SELECTED;
917 * Now set it for all specified messages.
919 num_sets = num_tokens(actual_range, ',');
920 for (s=0; s<num_sets; ++s) {
921 extract_token(setstr, actual_range, s, ',');
923 extract_token(lostr, setstr, 0, ':');
924 if (num_tokens(setstr, ':') >= 2) {
925 extract_token(histr, setstr, 1, ':');
926 if (!strcmp(histr, "*")) sprintf(histr, "%d", INT_MAX);
929 strcpy(histr, lostr);
934 /* Loop through the array, flipping bits where appropriate */
935 for (i = 1; i <= IMAP->num_msgs; ++i) {
936 if (is_uid) { /* fetch by sequence number */
937 if ( (IMAP->msgids[i-1]>=lo)
938 && (IMAP->msgids[i-1]<=hi)) {
940 IMAP->flags[i-1] | IMAP_SELECTED;
943 else { /* fetch by uid */
944 if ( (i>=lo) && (i<=hi)) {
946 IMAP->flags[i-1] | IMAP_SELECTED;
957 * This function is called by the main command loop.
959 void imap_fetch(int num_parms, char *parms[]) {
960 char items[SIZ]; /* was 1024 */
966 cprintf("%s BAD invalid parameters\r\n", parms[0]);
970 imap_pick_range(parms[2], 0);
973 for (i=3; i<num_parms; ++i) {
974 strcat(items, parms[i]);
975 if (i < (num_parms-1)) strcat(items, " ");
978 num_items = imap_extract_data_items(itemlist, items);
980 cprintf("%s BAD invalid data item list\r\n", parms[0]);
984 imap_do_fetch(num_items, itemlist);
985 cprintf("%s OK FETCH completed\r\n", parms[0]);
989 * This function is called by the main command loop.
991 void imap_uidfetch(int num_parms, char *parms[]) {
992 char items[SIZ]; /* was 1024 */
996 int have_uid_item = 0;
999 cprintf("%s BAD invalid parameters\r\n", parms[0]);
1003 imap_pick_range(parms[3], 1);
1006 for (i=4; i<num_parms; ++i) {
1007 strcat(items, parms[i]);
1008 if (i < (num_parms-1)) strcat(items, " ");
1011 num_items = imap_extract_data_items(itemlist, items);
1012 if (num_items < 1) {
1013 cprintf("%s BAD invalid data item list\r\n", parms[0]);
1017 /* If the "UID" item was not included, we include it implicitly
1018 * because this is a UID FETCH command
1020 for (i=0; i<num_items; ++i) {
1021 if (!strcasecmp(itemlist[i], "UID")) ++have_uid_item;
1023 if (have_uid_item == 0) itemlist[num_items++] = "UID";
1025 imap_do_fetch(num_items, itemlist);
1026 cprintf("%s OK UID FETCH completed\r\n", parms[0]);