X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fhtml2html.c;h=9d6e357aaabfdf71d577063f3c5ffae85670ec14;hb=719abc348ee76436439a16bcaccce317c12d3435;hp=abd5904e846a1577fa6c2af0c5a2d3fa3e72eed6;hpb=66bc2dac8a06eac6d8fe590d1ccc867090274579;p=citadel.git
diff --git a/webcit/html2html.c b/webcit/html2html.c
index abd5904e8..9d6e357aa 100644
--- a/webcit/html2html.c
+++ b/webcit/html2html.c
@@ -8,7 +8,6 @@
*/
/*@{*/
#include "webcit.h"
-#include "vcard.h"
#include "webserver.h"
@@ -59,6 +58,18 @@ void extract_charset_from_meta(char *charset, char *meta_http_equiv, char *meta_
striplt(buf);
if (!strncasecmp(buf, "charset=", 8)) {
strcpy(charset, &buf[8]);
+
+ /*
+ * The brain-damaged webmail program in Microsoft Exchange declares
+ * a charset of "unicode" when they really mean "UTF-8". GNU iconv
+ * treats "unicode" as an alias for "UTF-16" so we have to manually
+ * fix this here, otherwise messages generated in Exchange webmail
+ * show up as a big pile of weird characters.
+ */
+ if (!strcasecmp(charset, "unicode")) {
+ strcpy(charset, "UTF-8");
+ }
+
}
}
@@ -67,24 +78,25 @@ void extract_charset_from_meta(char *charset, char *meta_http_equiv, char *meta_
/**
* \brief Sanitize and enhance an HTML message for display.
* Also convert weird character sets to UTF-8 if necessary.
+ * Also fixup img src="cid:..." type inline images to fetch the image
*
* \param supplied_charset the input charset as declared in the MIME headers
*/
-void output_html(char *supplied_charset, int treat_as_wiki) {
+void output_html(char *supplied_charset, int treat_as_wiki, int msgnum) {
char buf[SIZ];
char *msg;
char *ptr;
char *msgstart;
char *msgend;
- char *converted_msg;
- size_t converted_alloc = 0;
+ StrBuf *converted_msg;
int buffer_length = 1;
int line_length = 0;
int content_length = 0;
- int output_length = 0;
char new_window[SIZ];
int brak = 0;
int alevel = 0;
+ int scriptlevel = 0;
+ int script_start_pos = (-1);
int i;
int linklen;
char charset[128];
@@ -125,7 +137,7 @@ void output_html(char *supplied_charset, int treat_as_wiki) {
}
/** Do a first pass to isolate the message body */
- ptr = msg;
+ ptr = msg + 1;
msgstart = msg;
msgend = &msg[content_length];
@@ -252,16 +264,27 @@ void output_html(char *supplied_charset, int treat_as_wiki) {
*/
/** Now go through the message, parsing tags as necessary. */
- converted_alloc = content_length + 8192;
- converted_msg = malloc(converted_alloc);
+ converted_msg = NewStrBufPlain(NULL, content_length + 8192);
if (converted_msg == NULL) {
- abort(); /* FIXME */
+ wprintf("Error %d: %s
%s:%d", errno, strerror(errno), __FILE__, __LINE__);
+ goto BAIL;
}
- strcpy(converted_msg, "");
+
ptr = msg;
msgend = strchr(msg, 0);
while (ptr < msgend) {
+ /** Try to sanitize the html of any rogue scripts */
+ if (!strncasecmp(ptr, "