struct imap_fetch_part {
- char desired_section[256];
+ char desired_section[SIZ];
FILE *output_fp;
};
}
void imap_fetch_internaldate(struct CtdlMessage *msg) {
- char buf[256];
+ char buf[SIZ];
time_t msgdate;
if (msg->cm_fields['T'] != NULL) {
* so we don't have to check for that condition like we do elsewhere.
*/
void imap_fetch_envelope(long msgnum, struct CtdlMessage *msg) {
- char datestringbuf[256];
+ char datestringbuf[SIZ];
time_t msgdate;
char *fieldptr = NULL;
if (partial[i]=='>') partial[i] = 0;
}
if (is_partial == 0) strcpy(partial, "");
- lprintf(9, "Partial is %s\n", partial);
+ if (strlen(partial) > 0) lprintf(9, "Partial is %s\n", partial);
tmp = tmpfile();
if (tmp == NULL) {
imfp.output_fp = tmp;
mime_parser(msg->cm_fields['M'], NULL,
- *imap_load_part,
+ *imap_load_part, NULL, NULL,
(void *)&imfp,
1);
}
}
}
+/*
+ * Called immediately before outputting a multipart bodystructure
+ */
+void imap_fetch_bodystructure_pre(
+ char *name, char *filename, char *partnum, char *disp,
+ void *content, char *cbtype, size_t length, char *encoding,
+ void *cbuserdata
+ ) {
+
+ cprintf("(");
+}
+
+
+
+/*
+ * Called immediately after outputting a multipart bodystructure
+ */
+void imap_fetch_bodystructure_post(
+ char *name, char *filename, char *partnum, char *disp,
+ void *content, char *cbtype, size_t length, char *encoding,
+ void *cbuserdata
+ ) {
+
+ char subtype[SIZ];
+
+ extract_token(subtype, cbtype, 1, '/');
+ imap_strout(subtype);
+ cprintf(")");
+}
+
+
+
+/*
+ * Output the info for a MIME part in the format required by BODYSTRUCTURE.
+ *
+ */
+void imap_fetch_bodystructure_part(
+ char *name, char *filename, char *partnum, char *disp,
+ void *content, char *cbtype, size_t length, char *encoding,
+ void *cbuserdata
+ ) {
+
+ char buf[SIZ];
+ int have_cbtype = 0;
+ int have_encoding = 0;
+
+ cprintf("(");
+
+ if (cbtype != NULL) if (strlen(cbtype)>0) have_cbtype = 1;
+
+ if (have_cbtype) {
+ extract_token(buf, cbtype, 0, '/');
+ imap_strout(buf);
+ cprintf(" ");
+ extract_token(buf, cbtype, 1, '/');
+ imap_strout(buf);
+ cprintf(" ");
+ }
+ else {
+ cprintf("\"TEXT\" \"PLAIN\" ");
+ }
+
+ cprintf("(\"CHARSET\" \"US-ASCII\"");
+
+ if (name != NULL) if (strlen(name)>0) {
+ cprintf(" \"NAME\" ");
+ imap_strout(name);
+ }
+
+ if (filename != NULL) if (strlen(filename)>0) {
+ cprintf(" \"FILENAME\" ");
+ imap_strout(name);
+ }
+
+ cprintf(") ");
+
+ cprintf("NIL NIL ");
+
+ if (encoding != NULL) if (strlen(encoding) > 0) have_encoding = 1;
+
+ if (have_encoding) {
+ imap_strout(encoding);
+ }
+ else {
+ imap_strout("7BIT");
+ }
+ cprintf(" ");
+
+ cprintf("%ld ", length); /* bytes */
+ cprintf("NIL) "); /* lines */
+}
+
+
/*
* Spew the BODYSTRUCTURE data for a message. (Do you need a silencer if
* you're going to shoot a MIME? Do you need a reason to shoot Mark Crispin?
* No, and no.)
*
- * FIXME finish the implementation
*/
void imap_fetch_bodystructure (long msgnum, char *item,
struct CtdlMessage *msg) {
long lines = 0L;
long bytes = 0L;
-
/* For non-RFC822 (ordinary Citadel) messages, this is short and
* sweet...
*/
cprintf("BODYSTRUCTURE (\"TEXT\" \"PLAIN\" "
"(\"CHARSET\" \"US-ASCII\") NIL NIL "
- "\"7BIT\" %ld %ld) ", bytes, lines);
+ "\"7BIT\" %ld %ld)", bytes, lines);
return;
}
/* For messages already stored in RFC822 format, we have to parse. */
- /* FIXME do this! */
-
-
+ cprintf("BODYSTRUCTURE ");
+ mime_parser(msg->cm_fields['M'],
+ NULL,
+ *imap_fetch_bodystructure_part, /* part */
+ *imap_fetch_bodystructure_pre, /* pre-multi */
+ *imap_fetch_bodystructure_post, /* post-multi */
+ NULL,
+ 0);
}
if (IMAP->num_msgs > 0)
for (i = 0; i < IMAP->num_msgs; ++i)
- if (IMAP->flags[i] && IMAP_FETCHED) {
+ if (IMAP->flags[i] & IMAP_FETCHED) {
msg = CtdlFetchMessage(IMAP->msgids[i]);
if (msg != NULL) {
imap_do_fetch_msg(i+1, msg, num_items, itemlist);
*
* Set is_uid to 1 to fetch by UID instead of sequence number.
*/
-void imap_pick_range(char *range, int is_uid) {
+void imap_pick_range(char *supplied_range, int is_uid) {
int i;
int num_sets;
int s;
- char setstr[1024], lostr[1024], histr[1024];
+ char setstr[SIZ], lostr[SIZ], histr[SIZ]; /* was 1024 */
int lo, hi;
- char *actual_range;
+ char actual_range[SIZ];
- actual_range = range;
- if (!strcasecmp(range, "ALL")) actual_range = "1:*";
+ /*
+ * Handle the "ALL" macro
+ */
+ if (!strcasecmp(supplied_range, "ALL")) {
+ safestrncpy(actual_range, "1:*", sizeof actual_range);
+ }
+ else {
+ safestrncpy(actual_range, supplied_range, sizeof actual_range);
+ }
/*
* Clear out the IMAP_FETCHED flags for all messages.
*/
- for (i = 1; i <= IMAP->num_msgs; ++i) {
- IMAP->flags[i-1] = IMAP->flags[i-1] & ~IMAP_FETCHED;
+ for (i = 0; i < IMAP->num_msgs; ++i) {
+ IMAP->flags[i] = IMAP->flags[i] & ~IMAP_FETCHED;
}
/*
}
}
}
+
+ /*
+ * Make sure we didn't select any expunged messages.
+ */
+ for (i = 0; i < IMAP->num_msgs; ++i) {
+ if (IMAP->flags[i] & IMAP_EXPUNGED) {
+ lprintf(9, "eliminating %d because expunged\n", i);
+ IMAP->flags[i] = IMAP->flags[i] & ~IMAP_FETCHED;
+ }
+ }
+
}
* This function is called by the main command loop.
*/
void imap_fetch(int num_parms, char *parms[]) {
- char items[1024];
- char *itemlist[256];
+ char items[SIZ]; /* was 1024 */
+ char *itemlist[SIZ];
int num_items;
int i;
* This function is called by the main command loop.
*/
void imap_uidfetch(int num_parms, char *parms[]) {
- char items[1024];
- char *itemlist[256];
+ char items[SIZ]; /* was 1024 */
+ char *itemlist[SIZ];
int num_items;
int i;
int have_uid_item = 0;