You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ma...@apache.org on 2005/08/28 19:06:15 UTC

svn commit: r263891 - in /httpd/mod_mbox/branches/httpd-mbox-if/module-2.0: mod_mbox_cte.c mod_mbox_mime.c mod_mbox_out.c

Author: maxime
Date: Sun Aug 28 10:06:09 2005
New Revision: 263891

URL: http://svn.apache.org/viewcvs?rev=263891&view=rev
Log:
 * module-2.0/mod_mbox_cte.c:
    (mbox_cte_decode_header): fixed RFC2047 header decoding.
    (mbox_cte_decode_rfc2047): new function.

 * module-2.0/mod_mbox_mime.c:
    (mbox_mime_decode_multipart): better MIME parsing (handle both
quoted and non-quoted filenames, does not require C-T to be the first
header).
    (mbox_mime_get_body): fixed too strict strncmp.

 * module-2.0/mod_mbox_out.c:
    (display_static_msglist_entry): fixed msgID escaping.



Modified:
    httpd/mod_mbox/branches/httpd-mbox-if/module-2.0/mod_mbox_cte.c
    httpd/mod_mbox/branches/httpd-mbox-if/module-2.0/mod_mbox_mime.c
    httpd/mod_mbox/branches/httpd-mbox-if/module-2.0/mod_mbox_out.c

Modified: httpd/mod_mbox/branches/httpd-mbox-if/module-2.0/mod_mbox_cte.c
URL: http://svn.apache.org/viewcvs/httpd/mod_mbox/branches/httpd-mbox-if/module-2.0/mod_mbox_cte.c?rev=263891&r1=263890&r2=263891&view=diff
==============================================================================
--- httpd/mod_mbox/branches/httpd-mbox-if/module-2.0/mod_mbox_cte.c (original)
+++ httpd/mod_mbox/branches/httpd-mbox-if/module-2.0/mod_mbox_cte.c Sun Aug 28 10:06:09 2005
@@ -247,38 +247,25 @@
     return len;
 }
 
-/* MIME header decoding (see RFC 2047).
- *
- * This function performs the decoding of headers like :
+/* This function performs the decoding of strings like :
  * =?UTF-8?B?QnJhbmtvIMSMaWJlag==?=
  *
- * These headers complies to the following syntax :
+ * These strings complies to the following syntax :
  * =?charset?mode?data?= rest
- *
- * FIXME: does not support multiple blocks.
- *        possible mis-use of decoding functions.
  */
-char *mbox_cte_decode_header(apr_pool_t *p, char *src)
+char *mbox_cte_decode_rfc2047(apr_pool_t *p, char *src)
 {
     apr_xlate_t *xlate;
-    apr_size_t len;
 
     char *charset, *mode, *data, *rest;
     int i;
 
-    /* Look for the end bound */
-    rest = strstr(src, "?=");
-    if (!rest) {
-        return src;
-    }
-    *rest = 0;
-    rest += strlen("?=");
-
     /* Look for charset */
     charset = strstr(src, "=?");
     if (!charset) {
         return src;
     }
+    *charset = 0;
     charset += strlen("=?");
 
     /* Encoding mode (first '?' after charset) */
@@ -297,9 +284,17 @@
     *data = 0;
     data++;
 
+    /* Look for the end bound */
+    rest = strstr(data, "?=");
+    if (!rest) {
+        return src;
+    }
+    *rest = 0;
+
     /* Quoted-Printable decoding : mode 'q' */
     if ((*mode == 'q') || (*mode == 'Q')) {
-        int i;
+        apr_size_t data_len;
+	int i;
 
 	/* In QP header encoding, spaces are encoded either in =20 (as
 	   in all QP encoding) or in underscores '_' (for header
@@ -307,16 +302,18 @@
 	   decoding, so we must handle the other one */
 	for (i = 0; i < strlen(data); i++) {
 	    if (data[i] == '_') {
-	      data[i] = ' ';
+	        data[i] = ' ';
 	    }
 	}
 
-	len = mbox_cte_decode_qp(data);
-	data[len] = 0;
+	data_len = mbox_cte_decode_qp(data);
+	data[data_len] = 0;
     }
     else if ((*mode == 'b') || (*mode == 'B')) {
-        len = mbox_cte_decode_b64(data);
-	data[len] = 0;
+        apr_size_t data_len;
+
+	data_len = mbox_cte_decode_b64(data);
+	data[data_len] = 0;
     }
 
     /* Convert charset to uppercase */
@@ -326,26 +323,61 @@
 
     /* Charset conversion */
     if (apr_xlate_open(&xlate, "UTF-8", charset, p) == APR_SUCCESS) {
-      apr_size_t inbytes_left, outbytes_left;
-      apr_size_t outbuf_len = strlen(data);
+        apr_size_t inbytes_left, outbytes_left;
+	apr_size_t outbuf_len = strlen(data);
 
-      char *new_data;
+	char *new_data;
 
-      /* Allocate some memory for our resulting data, and initialize
-	 counters. */
-      new_data = apr_palloc(p, outbuf_len);
-      inbytes_left = strlen(data);
-      outbytes_left = strlen(data);
+	/* Allocate some memory for our resulting data, and initialize
+	   counters. */
+	new_data = apr_palloc(p, outbuf_len);
+	inbytes_left = strlen(data);
+	outbytes_left = strlen(data);
 
-      /* Convert */
-      //      apr_xlate_conv_buffer(xlate, data, &inbytes_left,
-      //		    new_data, &outbytes_left);
+	/* Convert */
+	//      apr_xlate_conv_buffer(xlate, data, &inbytes_left,
+	//		    new_data, &outbytes_left);
 
-      //      new_data[outbuf_len - outbytes_left] = 0;
-      //      data = new_data;
+	//      new_data[outbuf_len - outbytes_left] = 0;
+	//      data = new_data;
 
-      apr_xlate_close(xlate);
+	apr_xlate_close(xlate);
     }
 
-    return apr_psprintf(p, "%s%s", data, rest);
+    return data;
+}
+
+/* MIME header decoding (see RFC 2047). */
+char *mbox_cte_decode_header(apr_pool_t *p, char *src)
+{
+    char *start, *end, *part;
+    char *result = "";
+
+    do {
+        char c;
+
+	start = strstr(src, "=?");
+	if (!start) {
+	    result = apr_psprintf(p, "%s%s", result, src);
+	    return result;
+	}
+
+	end = strstr(start, "?=");
+	if (!end) {
+            result = apr_psprintf(p, "%s%s", result, src);
+	    return result;
+	}
+
+	c = *start;
+	*start = 0;
+	result = apr_psprintf(p, "%s%s", result, src);
+	*start = c;
+
+	part = mbox_cte_decode_rfc2047(p, start);
+	result = apr_psprintf(p, "%s%s", result, part);
+
+	src = end + 2;
+    } while (src && *src);
+
+    return result;
 }

Modified: httpd/mod_mbox/branches/httpd-mbox-if/module-2.0/mod_mbox_mime.c
URL: http://svn.apache.org/viewcvs/httpd/mod_mbox/branches/httpd-mbox-if/module-2.0/mod_mbox_mime.c?rev=263891&r1=263890&r2=263891&view=diff
==============================================================================
--- httpd/mod_mbox/branches/httpd-mbox-if/module-2.0/mod_mbox_mime.c (original)
+++ httpd/mod_mbox/branches/httpd-mbox-if/module-2.0/mod_mbox_mime.c Sun Aug 28 10:06:09 2005
@@ -40,7 +40,8 @@
        sub-part of the multipart message. The Content-Type header
        should then be the first line of the part. If not, just ignore
        the sub-part. */
-    if (!ct && strncasecmp(body, "Content-Type: ", strlen("Content-Type: "))) {
+    tmp = strstr(body, "Content-Type: ");
+    if (!ct && (!tmp || tmp > headers_bound)) {
         return NULL;
     }
 
@@ -48,7 +49,7 @@
 
     /* If no Content-Type is given, we have to look for it. */
     if (!ct) {
-	tmp = body + strlen("Content-Type: ");
+	tmp += strlen("Content-Type: ");
 	k = strchr(tmp, ';');
 
 	/* Isolate the Content-Type string (between 'Content-Type: '
@@ -72,21 +73,28 @@
 	*k = ';';
 
 	/* If available, get MIME part name */
-	tmp = strstr(body, "name=\"");
+	tmp = strstr(body, "name=");
 	if (tmp && tmp < headers_bound) {
-	    tmp += strlen("name=\"");
+	    tmp += strlen("name=");
 	    k = tmp;
 
 	    while (*k) {
-	        if (isspace(*k) || *k == '"') {
+	        if (isspace(*k) || *k == ';') {
 		    *k = 0;
 		    break;
 		}
 		*k++;
 	    }
 
-	    mail->content_name = apr_pstrdup(p, tmp);
-	    *k = '"';
+	    /* Check for double quotes */
+	    if ((*tmp == '"') && (tmp[strlen(tmp)-1] == '"')) {
+	        mail->content_name = apr_pstrndup(p, tmp+1, strlen(tmp) - 2);
+	    }
+	    else {
+	        mail->content_name = apr_pstrdup(p, tmp);
+	    }
+
+	    *k = ';';
 	}
     }
     else
@@ -231,7 +239,10 @@
 		*t = '-';
 
 		search = inbound + strlen(mail->boundary) + 1;
-		mail->sub[count-1]->body_len = inbound - mail->sub[count-1]->body - 2;
+
+		if (mail->sub[count-1]) {
+		    mail->sub[count-1]->body_len = inbound - mail->sub[count-1]->body - 2;
+		}
 	    }
 
 	    /* Otherwise, the MIME part is finished. */
@@ -271,7 +282,7 @@
     }
     else if (m->cte == CTE_QP) {
         new_body = apr_pstrndup(p, m->body, m->body_len);
-	len = mbox_cte_decode_qp(m->body);
+	len = mbox_cte_decode_qp(new_body);
 
 	new_body[len] = 0;
 	m->body = new_body;
@@ -292,7 +303,7 @@
         return NULL;
     }
 
-    if (strncmp(m->content_type, "text/", strlen("text/")) == 0) {
+    if (strncasecmp(m->content_type, "text/", strlen("text/")) == 0) {
         char *new_body = mbox_mime_decode_body(p, m);
 
 	m->body_len = mbox_cte_escape_html(p, m->body, m->body_len, &new_body);
@@ -348,6 +359,11 @@
 
     for (i=0 ; i<m->sub_count ; i++) {
         ap_rputs("<ul>\n", r);
+
+	if (link[strlen(link)-1] == '/') {
+	    link[strlen(link)-1] = 0;
+	}
+
 	mbox_mime_display_static_structure(r, m->sub[i],
 					   apr_psprintf(r->pool, "%s/%d", link, i+1));
 	ap_rputs("</ul>\n", r);
@@ -383,6 +399,10 @@
 
     ap_rputs("<mime>\n", r);
     for (i=0 ; i<m->sub_count ; i++) {
+	if (link[strlen(link)-1] == '/') {
+	    link[strlen(link)-1] = 0;
+	}
+
         mbox_mime_display_xml_structure(r, m->sub[i],
 					apr_psprintf(r->pool, "%s/%d", link, i+1));
     }

Modified: httpd/mod_mbox/branches/httpd-mbox-if/module-2.0/mod_mbox_out.c
URL: http://svn.apache.org/viewcvs/httpd/mod_mbox/branches/httpd-mbox-if/module-2.0/mod_mbox_out.c?rev=263891&r1=263890&r2=263891&view=diff
==============================================================================
--- httpd/mod_mbox/branches/httpd-mbox-if/module-2.0/mod_mbox_out.c (original)
+++ httpd/mod_mbox/branches/httpd-mbox-if/module-2.0/mod_mbox_out.c Sun Aug 28 10:06:09 2005
@@ -292,7 +292,7 @@
 
     /* Message author */
     if (linked) {
-        ap_rprintf(r, "   <tr id=\"%s\">\n", m->msgID);
+        ap_rprintf(r, "   <tr id=\"%s\">\n", URI_ESCAPE_OR_BLANK(r->pool, m->msgID));
         ap_rprintf(r, "    <td class=\"author\">%s</td>\n", from);
     }
     else {
@@ -770,6 +770,13 @@
 	return OK;
     }
 
+    /* Empty MIME part : we want only mail's body */
+    if (part && !*part) {
+        ap_set_content_type(r, "text/plain");
+	ap_rprintf(r, "%s", m->raw_body);
+	return OK;
+    }
+
     /* First, parse the MIME structure, and look for the correct
        subpart */
     m->mime_msg = mbox_mime_decode_multipart(r->pool, m->raw_body,
@@ -971,7 +978,7 @@
 	     "    <td class=\"left\">Mime</td>\n"
 	     "    <td class=\"right\">\n<ul>\n", r);
     mbox_mime_display_static_structure(r, m->mime_msg,
-				       apr_psprintf(r->pool, "%s/raw/%s",
+				       apr_psprintf(r->pool, "%s/raw/%s/",
 						    baseURI, m->msgID));
     ap_rputs("</ul>\n</td>\n</tr>\n", r);
 
@@ -1035,7 +1042,7 @@
     ap_rprintf(r, "%s", mbox_wrap_text(mbox_mime_get_body(r->pool, m->mime_msg)));
     ap_rputs("]]></contents>\n", r);
     ap_rputs(" <mime>\n", r);
-    mbox_mime_display_xml_structure(r, m->mime_msg, "");
+    mbox_mime_display_xml_structure(r, m->mime_msg, apr_psprintf(r->pool, "/"));
     ap_rputs(" </mime>\n", r);
     ap_rputs("</mail>\n", r);