diff options
Diffstat (limited to 'src/core/basetypes/MCString.cc')
-rw-r--r-- | src/core/basetypes/MCString.cc | 84 |
1 files changed, 82 insertions, 2 deletions
diff --git a/src/core/basetypes/MCString.cc b/src/core/basetypes/MCString.cc index 3862cd4f..054cbb80 100644 --- a/src/core/basetypes/MCString.cc +++ b/src/core/basetypes/MCString.cc @@ -2,7 +2,6 @@ #include <string.h> #include <stdlib.h> -#define U_DISABLE_RENAMING 1 #include <unicode/ustring.h> #include <unicode/ucnv.h> #include <unicode/utypes.h> @@ -27,6 +26,7 @@ #include "MCValue.h" #include "MCHTMLCleaner.h" #include "MCBase64.h" +#include "MCIterator.h" using namespace mailcore; @@ -1745,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; @@ -2117,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; |