]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/imap/imap_fetch.c
When outputting the extension data for a
[citadel.git] / citadel / modules / imap / imap_fetch.c
index d13c84277fa3d1f215005e3a5da595404c0bd448..2165688125cea1edadc66a1cb5baa53445d0adbc 100644 (file)
@@ -510,13 +510,15 @@ void imap_strip_headers(char *section) {
        if (!strncasecmp(which_fields, "HEADER.FIELDS.NOT", 17))
                headers_not = 1;
 
-       for (i=0; i<strlen(which_fields); ++i) {
+       for (i=0; which_fields[i]; ++i) {
                if (which_fields[i]=='(')
                        strcpy(which_fields, &which_fields[i+1]);
        }
-       for (i=0; i<strlen(which_fields); ++i) {
-               if (which_fields[i]==')')
+       for (i=0; which_fields[i]; ++i) {
+               if (which_fields[i]==')') {
                        which_fields[i] = 0;
+                       break;
+               }
        }
        num_parms = imap_parameterize(parms, which_fields);
 
@@ -585,9 +587,19 @@ void imap_fetch_body(long msgnum, char *item, int is_peek) {
        lprintf(CTDL_DEBUG, "Section is: %s%s\n", 
                section, 
                IsEmptyStr(section) ? "(empty)" : "");
-       if (!strncasecmp(section, "HEADER", 6)) {
-               need_body = 0;
-       }
+
+       /*
+        * We used to have this great optimization in place that would avoid
+        * fetching the entire RFC822 message from disk if the client was only
+        * asking for the headers.  Unfortunately, fetching only the Citadel
+        * headers omits "Content-type:" and this behavior breaks the iPhone
+        * email client.  So we have to fetch the whole message from disk.  The
+        *
+        *      if (!strncasecmp(section, "HEADER", 6)) {
+        *              need_body = 0;
+        *      }
+        *
+        */
 
        /* Burn the cache if we don't have the same section of the 
         * same message again.
@@ -739,7 +751,7 @@ void imap_fetch_bodystructure_post(
        imap_strout(subtype);
 
        /* body language */
-       cprintf(" NIL");
+       /* cprintf(" NIL"); We thought we needed this at one point, but maybe we don't... */
 
        cprintf(")");
 }
@@ -774,33 +786,39 @@ void imap_fetch_bodystructure_part(
        }
 
        cprintf("(");
-       imap_strout(cbmaintype);
+       imap_strout(cbmaintype);                                        /* body type */
        cprintf(" ");
-       imap_strout(cbsubtype);
+       imap_strout(cbsubtype);                                         /* body subtype */
        cprintf(" ");
 
+       cprintf("(");                                                   /* begin body parameter list */
+
+       /* "NAME" must appear as the first parameter.  This is not required by IMAP,
+        * but the Asterisk voicemail application blindly assumes that NAME will be in
+        * the first position.  If it isn't, it rejects the message.
+        */
+       if (name != NULL) if (!IsEmptyStr(name)) {
+               cprintf("\"NAME\" ");
+               imap_strout(name);
+               cprintf(" ");
+       }
+
+       cprintf("\"CHARSET\" ");
        if (cbcharset == NULL) {
-               cprintf("(\"CHARSET\" \"US-ASCII\"");
+               imap_strout("US-ASCII");
        }
-       else if (IsEmptyStr(cbcharset)) {
-               cprintf("(\"CHARSET\" \"US-ASCII\"");
+       else if (cbcharset[0] == 0) {
+               imap_strout("US-ASCII");
        }
        else {
-               cprintf("(\"CHARSET\" ");
                imap_strout(cbcharset);
        }
+       cprintf(") ");                                                  /* end body parameter list */
 
-       if (name != NULL) if (!IsEmptyStr(name)) {
-               cprintf(" \"NAME\" ");
-               imap_strout(name);
-       }
+       cprintf("NIL ");                                                /* Body ID */
+       cprintf("NIL ");                                                /* Body description */
 
-       cprintf(") ");
-
-       cprintf("NIL ");        /* Body ID */
-       cprintf("NIL ");        /* Body description */
-
-       if (encoding != NULL) if (!IsEmptyStr(encoding))  have_encoding = 1;
+       if (encoding != NULL) if (encoding[0] != 0)  have_encoding = 1;
        if (have_encoding) {
                imap_strout(encoding);
        }
@@ -1084,7 +1102,7 @@ void imap_handle_macros(char *str) {
        int i;
        int nest = 0;
 
-       for (i=0; i<strlen(str); ++i) {
+       for (i=0; str[i]; ++i) {
                if (str[i]=='(') ++nest;
                if (str[i]=='[') ++nest;
                if (str[i]=='<') ++nest;
@@ -1125,11 +1143,12 @@ void imap_handle_macros(char *str) {
 int imap_extract_data_items(char **argv, char *items) {
        int num_items = 0;
        int nest = 0;
-       int i, initial_len;
+       int i;
        char *start;
+       long initial_len;
 
        /* Convert all whitespace to ordinary space characters. */
-       for (i=0; i<strlen(items); ++i) {
+       for (i=0; items[i]; ++i) {
                if (isspace(items[i])) items[i]=' ';
        }