You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by je...@apache.org on 2010/05/30 05:15:04 UTC

svn commit: r949463 - in /httpd/mod_mbox/trunk: CHANGES module-2.0/mod_mbox.c module-2.0/mod_mbox.h module-2.0/mod_mbox_out.c

Author: jerenkrantz
Date: Sun May 30 03:15:04 2010
New Revision: 949463

URL: http://svn.apache.org/viewvc?rev=949463&view=rev
Log:
Fix up non-printable character support with Firefox and Google Chrome
over AJAX interfaces.

For a test case, try lists with rpluem as a member - April 2010 of dev@httpd
is a good example:

http://mail-archives.apache.org/mod_mbox/httpd-dev/201004.mbox/browser

* CHANGES: Note this.
* module-2.0/mod_mbox.c
  (apr_lib.h): Include.
  (mbox_ascii_escape): Add helper to just HTML-ify non-printable chars based
  on ap_escape_html2 implementation.
* module-2,0/mod_mbox.h
  (mbox_ascii_escape): Declare.
  (ESCAPE_OR_BLANK): If available, use ap_escape_html2 or use our internal
  escape helper on pre-2.3 builds.
  (URI_ESCAPE_OR_BLANK): Relocate declaration.
* module-2.0/mod_mbox_out.c
  (display_xml_msglist_entry): Re-order from escaping to always escape last.
  (mbox_xml_message): HTML-escape unprintable chars in body and re-order from.

Modified:
    httpd/mod_mbox/trunk/CHANGES
    httpd/mod_mbox/trunk/module-2.0/mod_mbox.c
    httpd/mod_mbox/trunk/module-2.0/mod_mbox.h
    httpd/mod_mbox/trunk/module-2.0/mod_mbox_out.c

Modified: httpd/mod_mbox/trunk/CHANGES
URL: http://svn.apache.org/viewvc/httpd/mod_mbox/trunk/CHANGES?rev=949463&r1=949462&r2=949463&view=diff
==============================================================================
--- httpd/mod_mbox/trunk/CHANGES (original)
+++ httpd/mod_mbox/trunk/CHANGES Sun May 30 03:15:04 2010
@@ -1,5 +1,8 @@
 Changes for mod_mbox 0.2
 
+  *) Fix up non-printable character support with Firefox and Google Chrome
+     over AJAX interfaces.  [Justin Erenkrantz]
+
   *) Google's Summer of Code 2005 work release : major front-end module
      rewrite. [Maxime Petazzoni]
 

Modified: httpd/mod_mbox/trunk/module-2.0/mod_mbox.c
URL: http://svn.apache.org/viewvc/httpd/mod_mbox/trunk/module-2.0/mod_mbox.c?rev=949463&r1=949462&r2=949463&view=diff
==============================================================================
--- httpd/mod_mbox/trunk/module-2.0/mod_mbox.c (original)
+++ httpd/mod_mbox/trunk/module-2.0/mod_mbox.c Sun May 30 03:15:04 2010
@@ -38,6 +38,8 @@
 
 #include "mod_mbox.h"
 
+#include "apr_lib.h"
+
 /* Register module hooks.
  */
 static void mbox_register_hooks(apr_pool_t *p)
@@ -165,6 +167,33 @@ char *mbox_wrap_text(char *str)
     return str;
 }
 
+char *mbox_ascii_escape(apr_pool_t *p, const char *s)
+{
+    int i, j;
+    char *x;
+
+    /* first, count the number of extra characters */
+    for (i = 0, j = 0; s[i] != '\0'; i++)
+        if (!apr_isascii(s[i]))
+            j += 5;
+
+    if (j == 0)
+        return apr_pstrmemdup(p, s, i);
+
+    x = apr_palloc(p, i + j + 1);
+    for (i = 0, j = 0; s[i] != '\0'; i++, j++)
+        if (!apr_isascii(s[i])) {
+            char *esc = apr_psprintf(p, "&#%3.3d;", (unsigned char)s[i]);
+            memcpy(&x[j], esc, 6);
+            j += 5;
+        }
+        else
+            x[j] = s[i];
+
+    x[j] = '\0';
+    return x;
+}
+
 /* Returns the archives base path */
 char *get_base_path(request_rec *r)
 {

Modified: httpd/mod_mbox/trunk/module-2.0/mod_mbox.h
URL: http://svn.apache.org/viewvc/httpd/mod_mbox/trunk/module-2.0/mod_mbox.h?rev=949463&r1=949462&r2=949463&view=diff
==============================================================================
--- httpd/mod_mbox/trunk/module-2.0/mod_mbox.h (original)
+++ httpd/mod_mbox/trunk/module-2.0/mod_mbox.h Sun May 30 03:15:04 2010
@@ -91,12 +91,6 @@ extern module mbox_module;
 
 extern char *mbox_months[12][2];
 
-#define ESCAPE_OR_BLANK(pool, s) \
-(s ? ap_escape_html(pool, s) : "")
-
-#define URI_ESCAPE_OR_BLANK(pool, s) \
-(s ? ap_escape_uri(pool, s) : "")
-
 /* Handlers */
 int mbox_atom_handler(request_rec *r, mbox_cache_info *mli);
 int mbox_sitemap_handler(request_rec *r, mbox_cache_info *mli);
@@ -147,9 +141,21 @@ void mbox_mime_display_xml_structure(req
 
 /* Utility functions */
 char *mbox_wrap_text(char *str);
+char *mbox_ascii_escape(apr_pool_t *p, const char *s);
 char *get_base_path(request_rec *r);
 char *get_base_uri(request_rec *r);
 
+#if AP_MODULE_MAGIC_AT_LEAST(20081231,0)
+#define ESCAPE_OR_BLANK(pool, s) \
+(s ? ap_escape_html2(pool, s, 1) : "")
+#else
+#define ESCAPE_OR_BLANK(pool, s) \
+(s ? mbox_ascii_escape(pool, ap_escape_html(pool, s)) : "")
+#endif
+
+#define URI_ESCAPE_OR_BLANK(pool, s) \
+(s ? ap_escape_uri(pool, s) : "")
+
 /* Backend functions */
 apr_array_header_t *mbox_fetch_boxes_list(request_rec *r,
                                           mbox_cache_info *mli,

Modified: httpd/mod_mbox/trunk/module-2.0/mod_mbox_out.c
URL: http://svn.apache.org/viewvc/httpd/mod_mbox/trunk/module-2.0/mod_mbox_out.c?rev=949463&r1=949462&r2=949463&view=diff
==============================================================================
--- httpd/mod_mbox/trunk/module-2.0/mod_mbox_out.c (original)
+++ httpd/mod_mbox/trunk/module-2.0/mod_mbox_out.c Sun May 30 03:15:04 2010
@@ -481,8 +481,7 @@ static void display_xml_msglist_entry(re
 
     conf = ap_get_module_config(r->per_dir_config, &mbox_module);
 
-    from = ESCAPE_OR_BLANK(r->pool, m->str_from);
-    from = mbox_cte_decode_header(r->pool, from);
+    from = mbox_cte_decode_header(r->pool, m->str_from);
     if (conf->antispam) {
         from = email_antispam(from);
     }
@@ -490,7 +489,8 @@ static void display_xml_msglist_entry(re
     ap_rprintf(r, " <message linked=\"%d\" depth=\"%d\" id=\"%s\">\n",
                linked, depth, ESCAPE_OR_BLANK(r->pool, m->msgID));
 
-    ap_rprintf(r, "  <from><![CDATA[%s]]></from>\n", from);
+    ap_rprintf(r, "  <from><![CDATA[%s]]></from>\n",
+               ESCAPE_OR_BLANK(r->pool, from));
     ap_rprintf(r, "  <date><![CDATA[%s]]></date>\n",
                ESCAPE_OR_BLANK(r->pool, m->str_date));
 
@@ -1278,11 +1278,11 @@ apr_status_t mbox_xml_message(request_re
 
     ap_rputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", r);
 
-    from = ESCAPE_OR_BLANK(r->pool, m->from);
-    from = mbox_cte_decode_header(r->pool, from);
+    from = mbox_cte_decode_header(r->pool, m->from);
     if (conf->antispam) {
         from = email_antispam(from);
     }
+    from = ESCAPE_OR_BLANK(r->pool, from);
 
     ap_rprintf(r, "<mail id=\"%s\">\n"
                " <from><![CDATA[%s]]></from>\n"
@@ -1295,7 +1295,7 @@ apr_status_t mbox_xml_message(request_re
                ESCAPE_OR_BLANK(r->pool, m->rfc822_date));
 
     ap_rprintf(r, "%s",
-               mbox_wrap_text(mbox_mime_get_body(r->pool, m->mime_msg)));
+               mbox_ascii_escape(r->pool, 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,



Fwd: svn commit: r949463 - in /httpd/mod_mbox/trunk: CHANGES module-2.0/mod_mbox.c module-2.0/mod_mbox.h module-2.0/mod_mbox_out.c

Posted by Justin Erenkrantz <ju...@erenkrantz.com>.
I'll leave it to ya'll if/how you want to deploy, but locally, I can
now use FF 3.6 and Google Chrome with mod_mbox on lists where rpluem
appears.  We could probably enable Safari these days, but...well...
=)  -- justin

---------- Forwarded message ----------
From:  <je...@apache.org>
Date: Sat, May 29, 2010 at 8:15 PM
Subject: svn commit: r949463 - in /httpd/mod_mbox/trunk: CHANGES
module-2.0/mod_mbox.c module-2.0/mod_mbox.h module-2.0/mod_mbox_out.c
To: cvs@httpd.apache.org


Author: jerenkrantz
Date: Sun May 30 03:15:04 2010
New Revision: 949463

URL: http://svn.apache.org/viewvc?rev=949463&view=rev
Log:
Fix up non-printable character support with Firefox and Google Chrome
over AJAX interfaces.

For a test case, try lists with rpluem as a member - April 2010 of dev@httpd
is a good example:

http://mail-archives.apache.org/mod_mbox/httpd-dev/201004.mbox/browser

* CHANGES: Note this.
* module-2.0/mod_mbox.c
 (apr_lib.h): Include.
 (mbox_ascii_escape): Add helper to just HTML-ify non-printable chars based
 on ap_escape_html2 implementation.
* module-2,0/mod_mbox.h
 (mbox_ascii_escape): Declare.
 (ESCAPE_OR_BLANK): If available, use ap_escape_html2 or use our internal
 escape helper on pre-2.3 builds.
 (URI_ESCAPE_OR_BLANK): Relocate declaration.
* module-2.0/mod_mbox_out.c
 (display_xml_msglist_entry): Re-order from escaping to always escape last.
 (mbox_xml_message): HTML-escape unprintable chars in body and re-order from.

Modified:
   httpd/mod_mbox/trunk/CHANGES
   httpd/mod_mbox/trunk/module-2.0/mod_mbox.c
   httpd/mod_mbox/trunk/module-2.0/mod_mbox.h
   httpd/mod_mbox/trunk/module-2.0/mod_mbox_out.c

Modified: httpd/mod_mbox/trunk/CHANGES
URL: http://svn.apache.org/viewvc/httpd/mod_mbox/trunk/CHANGES?rev=949463&r1=949462&r2=949463&view=diff
==============================================================================
--- httpd/mod_mbox/trunk/CHANGES (original)
+++ httpd/mod_mbox/trunk/CHANGES Sun May 30 03:15:04 2010
@@ -1,5 +1,8 @@
 Changes for mod_mbox 0.2

+  *) Fix up non-printable character support with Firefox and Google Chrome
+     over AJAX interfaces.  [Justin Erenkrantz]
+
  *) Google's Summer of Code 2005 work release : major front-end module
     rewrite. [Maxime Petazzoni]


Modified: httpd/mod_mbox/trunk/module-2.0/mod_mbox.c
URL: http://svn.apache.org/viewvc/httpd/mod_mbox/trunk/module-2.0/mod_mbox.c?rev=949463&r1=949462&r2=949463&view=diff
==============================================================================
--- httpd/mod_mbox/trunk/module-2.0/mod_mbox.c (original)
+++ httpd/mod_mbox/trunk/module-2.0/mod_mbox.c Sun May 30 03:15:04 2010
@@ -38,6 +38,8 @@

 #include "mod_mbox.h"

+#include "apr_lib.h"
+
 /* Register module hooks.
 */
 static void mbox_register_hooks(apr_pool_t *p)
@@ -165,6 +167,33 @@ char *mbox_wrap_text(char *str)
    return str;
 }

+char *mbox_ascii_escape(apr_pool_t *p, const char *s)
+{
+    int i, j;
+    char *x;
+
+    /* first, count the number of extra characters */
+    for (i = 0, j = 0; s[i] != '\0'; i++)
+        if (!apr_isascii(s[i]))
+            j += 5;
+
+    if (j == 0)
+        return apr_pstrmemdup(p, s, i);
+
+    x = apr_palloc(p, i + j + 1);
+    for (i = 0, j = 0; s[i] != '\0'; i++, j++)
+        if (!apr_isascii(s[i])) {
+            char *esc = apr_psprintf(p, "&#%3.3d;", (unsigned char)s[i]);
+            memcpy(&x[j], esc, 6);
+            j += 5;
+        }
+        else
+            x[j] = s[i];
+
+    x[j] = '\0';
+    return x;
+}
+
 /* Returns the archives base path */
 char *get_base_path(request_rec *r)
 {

Modified: httpd/mod_mbox/trunk/module-2.0/mod_mbox.h
URL: http://svn.apache.org/viewvc/httpd/mod_mbox/trunk/module-2.0/mod_mbox.h?rev=949463&r1=949462&r2=949463&view=diff
==============================================================================
--- httpd/mod_mbox/trunk/module-2.0/mod_mbox.h (original)
+++ httpd/mod_mbox/trunk/module-2.0/mod_mbox.h Sun May 30 03:15:04 2010
@@ -91,12 +91,6 @@ extern module mbox_module;

 extern char *mbox_months[12][2];

-#define ESCAPE_OR_BLANK(pool, s) \
-(s ? ap_escape_html(pool, s) : "")
-
-#define URI_ESCAPE_OR_BLANK(pool, s) \
-(s ? ap_escape_uri(pool, s) : "")
-
 /* Handlers */
 int mbox_atom_handler(request_rec *r, mbox_cache_info *mli);
 int mbox_sitemap_handler(request_rec *r, mbox_cache_info *mli);
@@ -147,9 +141,21 @@ void mbox_mime_display_xml_structure(req

 /* Utility functions */
 char *mbox_wrap_text(char *str);
+char *mbox_ascii_escape(apr_pool_t *p, const char *s);
 char *get_base_path(request_rec *r);
 char *get_base_uri(request_rec *r);

+#if AP_MODULE_MAGIC_AT_LEAST(20081231,0)
+#define ESCAPE_OR_BLANK(pool, s) \
+(s ? ap_escape_html2(pool, s, 1) : "")
+#else
+#define ESCAPE_OR_BLANK(pool, s) \
+(s ? mbox_ascii_escape(pool, ap_escape_html(pool, s)) : "")
+#endif
+
+#define URI_ESCAPE_OR_BLANK(pool, s) \
+(s ? ap_escape_uri(pool, s) : "")
+
 /* Backend functions */
 apr_array_header_t *mbox_fetch_boxes_list(request_rec *r,
                                          mbox_cache_info *mli,

Modified: httpd/mod_mbox/trunk/module-2.0/mod_mbox_out.c
URL: http://svn.apache.org/viewvc/httpd/mod_mbox/trunk/module-2.0/mod_mbox_out.c?rev=949463&r1=949462&r2=949463&view=diff
==============================================================================
--- httpd/mod_mbox/trunk/module-2.0/mod_mbox_out.c (original)
+++ httpd/mod_mbox/trunk/module-2.0/mod_mbox_out.c Sun May 30 03:15:04 2010
@@ -481,8 +481,7 @@ static void display_xml_msglist_entry(re

    conf = ap_get_module_config(r->per_dir_config, &mbox_module);

-    from = ESCAPE_OR_BLANK(r->pool, m->str_from);
-    from = mbox_cte_decode_header(r->pool, from);
+    from = mbox_cte_decode_header(r->pool, m->str_from);
    if (conf->antispam) {
        from = email_antispam(from);
    }
@@ -490,7 +489,8 @@ static void display_xml_msglist_entry(re
    ap_rprintf(r, " <message linked=\"%d\" depth=\"%d\" id=\"%s\">\n",
               linked, depth, ESCAPE_OR_BLANK(r->pool, m->msgID));

-    ap_rprintf(r, "  <from><![CDATA[%s]]></from>\n", from);
+    ap_rprintf(r, "  <from><![CDATA[%s]]></from>\n",
+               ESCAPE_OR_BLANK(r->pool, from));
    ap_rprintf(r, "  <date><![CDATA[%s]]></date>\n",
               ESCAPE_OR_BLANK(r->pool, m->str_date));

@@ -1278,11 +1278,11 @@ apr_status_t mbox_xml_message(request_re

    ap_rputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", r);

-    from = ESCAPE_OR_BLANK(r->pool, m->from);
-    from = mbox_cte_decode_header(r->pool, from);
+    from = mbox_cte_decode_header(r->pool, m->from);
    if (conf->antispam) {
        from = email_antispam(from);
    }
+    from = ESCAPE_OR_BLANK(r->pool, from);

    ap_rprintf(r, "<mail id=\"%s\">\n"
               " <from><![CDATA[%s]]></from>\n"
@@ -1295,7 +1295,7 @@ apr_status_t mbox_xml_message(request_re
               ESCAPE_OR_BLANK(r->pool, m->rfc822_date));

    ap_rprintf(r, "%s",
-               mbox_wrap_text(mbox_mime_get_body(r->pool, m->mime_msg)));
+               mbox_ascii_escape(r->pool,
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,