* HTML messages in foreign character sets are now converted to UTF-8 for
authorArt Cancro <ajc@citadel.org>
Fri, 22 Jul 2005 04:03:31 +0000 (04:03 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 22 Jul 2005 04:03:31 +0000 (04:03 +0000)
  display.

webcit/ChangeLog
webcit/html2html.c
webcit/messages.c
webcit/webcit.h

index 125fb66b7b20f48e5408dd686669a83e784c209c..2830db5437f3d7f06c3358ae95aea52cff5b79e9 100644 (file)
@@ -1,4 +1,8 @@
 $Log$
+Revision 619.30  2005/07/22 04:03:30  ajc
+* HTML messages in foreign character sets are now converted to UTF-8 for
+  display.
+
 Revision 619.29  2005/07/22 03:40:22  ajc
 * Handle display of RFC2047-encoded subjects and senders by converting
   them to UTF-8 (all WebCit pages are output as UTF-8).  Resolves bug #136.
@@ -2728,4 +2732,3 @@ Sun Dec  6 19:50:55 EST 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
 
 1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
        * webserver.c: warning fix
-
index 271dbe14376e9f2a8578878a27ad2468fb56c7ec..110d9682e31d937ffa35a47ee621b75f860431eb 100644 (file)
 #include <stdarg.h>
 #include <pthread.h>
 #include <signal.h>
+
+#ifdef HAVE_ICONV
+#include <iconv.h>
+#endif
+
 #include "webcit.h"
 #include "vcard.h"
 #include "webserver.h"
 
 
 /*
+ * Sanitize and enhance an HTML message for display.
+ * Also convert weird character sets to UTF-8 if necessary.
  */
-void output_html(void) {
+void output_html(char *charset) {
        char buf[SIZ];
        char *msg;
        char *ptr;
@@ -47,6 +54,14 @@ void output_html(void) {
        int alevel = 0;
        int i;
        int linklen;
+#ifdef HAVE_ICONV
+       iconv_t ic = (iconv_t)(-1) ;
+       char *ibuf;                   /* Buffer of characters to be converted */
+       char *obuf;                   /* Buffer for converted characters      */
+       size_t ibuflen;               /* Length of input buffer               */
+       size_t obuflen;               /* Length of output buffer              */
+       char *osav;                   /* Saved pointer to output buffer       */
+#endif
 
        msg = strdup("");
        sprintf(new_window, "<A TARGET=\"%s\" HREF=", TARGET);
@@ -68,6 +83,29 @@ void output_html(void) {
                content_length += 1;
        }
 
+#ifdef HAVE_ICONV
+       if ( (strcasecmp(charset, "us-ascii"))
+          && (strcasecmp(charset, "UTF-8")) ) {
+               ic = iconv_open("UTF-8", charset);
+               if (ic == (iconv_t)(-1) ) {
+                       lprintf(5, "iconv_open() failed: %s\n", strerror(errno));
+               }
+       }
+       if (ic != (iconv_t)(-1) ) {
+               ibuf = msg;
+               ibuflen = content_length;
+               obuflen = content_length + (content_length / 2) ;
+               obuf = (char *) malloc(obuflen);
+               osav = obuf;
+               iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
+               content_length = content_length + (content_length / 2) - obuflen;
+               osav[content_length] = 0;
+               free(msg);
+               msg = osav;
+               iconv_close(ic);
+       }
+#endif
+
        ptr = msg;
        msgstart = msg;
        msgend = &msg[content_length];
index c20ebc455e8b621317297b60f0744b14a9423979..370454c792a02a3eb3804417b9f1bec73d4da6a0 100644 (file)
@@ -784,7 +784,7 @@ void read_message(long msgnum) {
 
        else /* HTML is fun, but we've got to strip it first */
        if (!strcasecmp(mime_content_type, "text/html")) {
-               output_html();
+               output_html(mime_charset);
        }
 
        /* Unknown weirdness */
index 699854449c06466af4a84f16c37f35a62c076cd2..5fc1b2b5611f0d9bf55b33de5f96a14046356472 100644 (file)
@@ -429,7 +429,7 @@ void display_addressbook(long msgnum, char alpha);
 void offer_start_page(void);
 void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext);
 void change_start_page(void);
-void output_html(void);
+void output_html(char *);
 void display_floorconfig(char *);
 void delete_floor(void);
 void create_floor(void);