diff options
author | Hoa V. DINH <dinh.viet.hoa@gmail.com> | 2014-02-05 22:56:18 -0800 |
---|---|---|
committer | Hoa V. DINH <dinh.viet.hoa@gmail.com> | 2014-02-05 22:56:32 -0800 |
commit | 9edebd8221a3407704880de8d98226c24d88e6b1 (patch) | |
tree | 3e47f674e951777afae4e2d4e171b6350012ff65 | |
parent | 95f1b96ba86c610aeeb8b30c35d1254a962f5edd (diff) |
Render text as HTML
-rw-r--r-- | src/core/basetypes/MCString.cc | 83 | ||||
-rw-r--r-- | src/core/basetypes/MCString.h | 1 | ||||
-rw-r--r-- | src/core/renderer/MCHTMLRenderer.cc | 3 |
3 files changed, 85 insertions, 2 deletions
diff --git a/src/core/basetypes/MCString.cc b/src/core/basetypes/MCString.cc index 26e2f931..054cbb80 100644 --- a/src/core/basetypes/MCString.cc +++ b/src/core/basetypes/MCString.cc @@ -26,6 +26,7 @@ #include "MCValue.h" #include "MCHTMLCleaner.h" #include "MCBase64.h" +#include "MCIterator.h" using namespace mailcore; @@ -1744,7 +1745,7 @@ String * String::flattenHTMLAndShowBlockquoteAndLink(bool showBlockquote, bool s String * result = String::string(); xmlSAXHandler handler; bzero(&handler, sizeof(xmlSAXHandler)); - handler.characters = &charactersParsed; + handler.characters = charactersParsed; handler.startElement = elementStarted; handler.endElement = elementEnded; handler.comment = commentParsed; @@ -2116,6 +2117,86 @@ String * String::cleanedHTMLString() return HTMLCleaner::cleanHTML(this); } +String * String::htmlMessageContent() +{ + String * str = this; + + Array * lines = str->componentsSeparatedByString(MCSTR("\n")); + + while (1) { + if (lines->count() == 0) { + break; + } + + if (((String *) lines->lastObject())->length() > 0) { + break; + } + + lines->removeLastObject(); + } + + String * localString; + int state; + localString = String::string(); + + String * quoted = NULL; + state = 0; + mc_foreacharray(String, line, lines) { + if (state == 0) { + if (line->hasPrefix(MCSTR(">"))) { + state = 1; + quoted = new String(); + int i = 1; + while (i < line->length()) { + if (line->characterAtIndex(i) != ' ') { + break; + } + i ++; + } + quoted->appendString(line->substringFromIndex(i)); + quoted->appendString(MCSTR("\n")); + } + else { + localString->appendString(line->htmlEncodedString()); + localString->appendString(MCSTR("<br/>")); + } + } + else if (state == 1) { + if (line->hasPrefix(MCSTR(">"))) { + int i = 1; + while (i < line->length()) { + if (line->characterAtIndex(i) != ' ') { + break; + } + i ++; + } + quoted->appendString(line->substringFromIndex(i)); + quoted->appendString(MCSTR("\n")); + } + else { + if (quoted != NULL) { + localString->appendString(MCSTR("<blockquote type=\"cite\">")); + localString->appendString(quoted->htmlMessageContent()); + localString->appendString(MCSTR("</blockquote>")); + MC_SAFE_RELEASE(quoted); + state = 0; + } + localString->appendString(line->htmlEncodedString()); + localString->appendString(MCSTR("<br/>")); + } + } + } + + if (quoted != nil) { + localString->appendString(MCSTR("<blockquote type=\"cite\">")); + localString->appendString(quoted); + localString->appendString(MCSTR("</blockquote>")); + MC_SAFE_RELEASE(quoted); + } + + return localString; +} + bool String::isEqualCaseInsensitive(String * otherString) { return caseInsensitiveCompare(otherString) == 0; diff --git a/src/core/basetypes/MCString.h b/src/core/basetypes/MCString.h index 2afd0e7b..49e0a5ac 100644 --- a/src/core/basetypes/MCString.h +++ b/src/core/basetypes/MCString.h @@ -108,6 +108,7 @@ namespace mailcore { virtual String * htmlEncodedString(); virtual String * cleanedHTMLString(); + virtual String * htmlMessageContent(); virtual Data * decodedBase64Data(); diff --git a/src/core/renderer/MCHTMLRenderer.cc b/src/core/renderer/MCHTMLRenderer.cc index 071d7523..45c3a77a 100644 --- a/src/core/renderer/MCHTMLRenderer.cc +++ b/src/core/renderer/MCHTMLRenderer.cc @@ -266,8 +266,9 @@ static String * htmlForAbstractSinglePart(AbstractPart * part, htmlRendererConte return NULL; String * str = data->stringWithDetectedCharset(charset, false); + str = str->htmlMessageContent(); context->firstRendered = true; - return str->htmlEncodedString(); + return str; } else if (mimeType->isEqual(MCSTR("text/html"))) { String * charset = part->charset(); |