diff options
author | Hoa V. DINH <dinh.viet.hoa@gmail.com> | 2016-01-29 21:56:25 -0800 |
---|---|---|
committer | Hoa V. DINH <dinh.viet.hoa@gmail.com> | 2016-01-29 21:57:02 -0800 |
commit | ec46abe9a4c6b3841c767d37b8f5516385885a73 (patch) | |
tree | abf8ec113ca48e7f6c52d40aa44b55ca6a30857d | |
parent | fce13c4e28c6c44cfaf3ca47da5b9dc80eb9f8d3 (diff) |
Sanitize display name
-rw-r--r-- | src/core/renderer/MCAddressDisplay.cpp | 29 | ||||
-rw-r--r-- | src/core/renderer/MCAddressDisplay.h | 2 |
2 files changed, 28 insertions, 3 deletions
diff --git a/src/core/renderer/MCAddressDisplay.cpp b/src/core/renderer/MCAddressDisplay.cpp index d8de47fc..8a27f121 100644 --- a/src/core/renderer/MCAddressDisplay.cpp +++ b/src/core/renderer/MCAddressDisplay.cpp @@ -10,15 +10,38 @@ using namespace mailcore; +String * AddressDisplay::sanitizeDisplayName(String * displayName) +{ + if (displayName->hasPrefix(MCSTR("\"")) && displayName->hasSuffix(MCSTR("\""))) { + String * unquotedDisplayName = displayName->substringWithRange(RangeMake(1, displayName->length() - 2)); + if (unquotedDisplayName->locationOfString(MCSTR("\"")) != -1) { + return displayName; + } + else { + return unquotedDisplayName; + } + } + else { + return displayName; + } +} + String * AddressDisplay::displayStringForAddress(Address * address) { - return address->nonEncodedRFC822String(); + if (address->displayName() != NULL) { + return String::stringWithUTF8Format("%s <%s>", + MCUTF8(AddressDisplay::sanitizeDisplayName(address->displayName())), + MCUTF8(address->mailbox())); + } + else { + return address->mailbox(); + } } String * AddressDisplay::shortDisplayStringForAddress(Address * address) { if ((address->displayName() != NULL) && (address->displayName()->length() > 0)) { - return address->displayName(); + return sanitizeDisplayName(address->displayName()); } else if (address->mailbox()) { return address->mailbox(); @@ -34,7 +57,7 @@ String * AddressDisplay::veryShortDisplayStringForAddress(Address * address) Array * components; String * senderName; - senderName = address->displayName(); + senderName = sanitizeDisplayName(address->displayName()); senderName = (String *) senderName->copy()->autorelease(); senderName->replaceOccurrencesOfString(MCSTR(","), MCSTR(" ")); diff --git a/src/core/renderer/MCAddressDisplay.h b/src/core/renderer/MCAddressDisplay.h index 6dd1faf8..d4841469 100644 --- a/src/core/renderer/MCAddressDisplay.h +++ b/src/core/renderer/MCAddressDisplay.h @@ -18,6 +18,8 @@ namespace mailcore { class MAILCORE_EXPORT AddressDisplay { public: + static String * sanitizeDisplayName(String * displayName); + static String * displayStringForAddress(Address * address); static String * shortDisplayStringForAddress(Address * address); static String * veryShortDisplayStringForAddress(Address * address); |