--- a/mailnews/mime/src/mimethtm.cpp
+++ b/mailnews/mime/src/mimethtm.cpp
@@ -4,16 +4,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mimethtm.h"
#include "prmem.h"
#include "plstr.h"
#include "prlog.h"
#include "prprf.h"
#include "msgCore.h"
#include "nsMimeStringResources.h"
+#include "nsMsgUtils.h"
#include "mimemoz2.h"
#include <ctype.h>
#define MIME_SUPERCLASS mimeInlineTextClass
MimeDefClass(MimeInlineTextHTML, MimeInlineTextHTMLClass,
mimeInlineTextHTMLClass, &MIME_SUPERCLASS);
static int MimeInlineTextHTML_parse_line (const char *, int32_t, MimeObject *);
@@ -48,23 +49,23 @@ MimeInlineTextHTML_parse_begin (MimeObje
nsMimeOutput::nsMimeMessagePrintOutput == obj->options->format_out)
{
char buf[256]; // local buffer for html tag
int32_t fontSize; // default font size
int32_t fontSizePercentage; // size percentage
nsAutoCString fontLang; // langgroup of the font.
if (NS_SUCCEEDED(GetMailNewsFont(obj, false, &fontSize, &fontSizePercentage,fontLang)))
{
- PR_snprintf(buf, 256, "<div class=\"moz-text-html\" lang=\"%s\">",
+ PR_snprintf(buf, 256, "<div class=\"moz-text-html\" lang=\"%s\"><iframe sandbox srcdoc=\"",
fontLang.get());
status = MimeObject_write(obj, buf, strlen(buf), true);
}
else
{
- status = MimeObject_write(obj, "<div class=\"moz-text-html\">", 27, true);
+ status = MimeObject_write(obj, "<div class=\"moz-text-html\"><iframe sandbox srcdoc=\"", 51, true);
}
if(status<0) return status;
}
MimeInlineTextHTML *textHTML = (MimeInlineTextHTML *) obj;
textHTML->charset = nullptr;
@@ -133,16 +134,17 @@ MimeInlineTextHTML_parse_line (const cha
MimeInlineTextHTML *textHTML = (MimeInlineTextHTML *) obj;
if (!obj->output_p)
return 0;
if (!obj->options || !obj->options->output_fn)
return 0;
+ char* buffer = nullptr;
if (!textHTML->charset)
{
char * cp;
// First, try to detect a charset via a META tag!
if ((cp = PL_strncasestr(line, "META", length)) &&
(cp = PL_strncasestr(cp, "HTTP-EQUIV=", length - (int)(cp - line))) &&
(cp = PL_strncasestr(cp, "CONTENT=", length - (int)(cp - line))) &&
(cp = PL_strncasestr(cp, "CHARSET=", length - (int)(cp - line)))
@@ -164,30 +166,44 @@ MimeInlineTextHTML_parse_line (const cha
PL_strncasecmp(charset, "UTF-16", 6) &&
PL_strncasecmp(charset, "UTF-32", 6))
{
textHTML->charset = charset;
// write out the data without the charset part...
if (textHTML->charset)
{
- int err = MimeObject_write(obj, line, cp - line, true);
- if (err == 0)
- err = MimeObject_write(obj, cp2, length - (int)(cp2 - line), true);
-
- return err;
+ buffer = PL_strndup(line, length);
+ if (!buffer) return -1;
+ // +1 to copy the ending null byte (added by PL_strndup).
+ PL_strncpy(buffer, buffer, length - (int)(cp2 - line) + 1);
}
+ } else {
+ PR_FREEIF(charset);
}
- PR_FREEIF(charset);
}
}
}
+ if (!buffer) {
+ buffer = PL_strndup(line, length);
+ }
+ if (nsMimeOutput::nsMimeMessageBodyDisplay == obj->options->format_out ||
+ nsMimeOutput::nsMimeMessagePrintOutput == obj->options->format_out)
+ {
+ char *escapedBuffer = MsgEscapeHTML(buffer);
+ if (!escapedBuffer) return -1;
+ PR_FREEIF(buffer);
+ buffer = escapedBuffer;
+ }
+
// Now, just write out the data...
- return MimeObject_write(obj, line, length, true);
+ int err = MimeObject_write(obj, buffer, strlen(buffer), true);
+ PR_FREEIF(buffer);
+ return err;
}
static int
MimeInlineTextHTML_parse_eof (MimeObject *obj, bool abort_p)
{
int status;
MimeInlineTextHTML *textHTML = (MimeInlineTextHTML *) obj;
if (obj->closed_p) return 0;
@@ -195,12 +211,12 @@ MimeInlineTextHTML_parse_eof (MimeObject
PR_FREEIF(textHTML->charset);
/* Run parent method first, to flush out any buffered data. */
status = ((MimeObjectClass*)&MIME_SUPERCLASS)->parse_eof(obj, abort_p);
if (status < 0) return status;
if (nsMimeOutput::nsMimeMessageBodyDisplay == obj->options->format_out ||
nsMimeOutput::nsMimeMessagePrintOutput == obj->options->format_out)
- status = MimeObject_write(obj, "</div>", 6, false);
+ status = MimeObject_write(obj, "\"></iframe></div>", 17, false);
return 0;
}