From f5e51aef15c4e7250d118b9626509e9206c42164 Mon Sep 17 00:00:00 2001 From: CodaFi Date: Thu, 4 Jul 2013 13:57:47 -0600 Subject: De-namespace --- src/core/basetypes/MCLog.h | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/core/basetypes/MCLog.h b/src/core/basetypes/MCLog.h index de75314f..6911ab02 100644 --- a/src/core/basetypes/MCLog.h +++ b/src/core/basetypes/MCLog.h @@ -4,13 +4,9 @@ #include -#ifdef __cplusplus - #define MCLog(...) MCLogInternal(NULL, __FILE__, __LINE__, 0, __VA_ARGS__) - -namespace mailcore { - extern int MCLogEnabled; +extern int MCLogEnabled; #ifndef __printflike #define __printflike(a,b) @@ -28,8 +24,4 @@ extern "C" { } #endif -} - -#endif - #endif -- cgit v1.2.3 From 497976e4cf85807017a5a9b4d9840a2d3712b03c Mon Sep 17 00:00:00 2001 From: CodaFi Date: Thu, 4 Jul 2013 14:04:46 -0600 Subject: Adds localized description table --- src/objc/abstract/MCOConstants.h | 38 ++++++++++++++++++++++++++++++++++++++ src/objc/utils/NSError+MCO.mm | 9 ++++++--- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/objc/abstract/MCOConstants.h b/src/objc/abstract/MCOConstants.h index 5ec21422..4d1ce094 100644 --- a/src/objc/abstract/MCOConstants.h +++ b/src/objc/abstract/MCOConstants.h @@ -350,4 +350,42 @@ typedef enum { */ typedef void (^MCOConnectionLogger)(void * connectionID, MCOConnectionLogType type, NSData * data); +NSString * MCOLocalizedDescriptionTable[] = { + @"", /** MCOErrorNone */ + @"A stable connection to the server could not be established.", /** MCOErrorConnection */ + @"The server does not support TLS/SSL connections.", /** MCOErrorTLSNotAvailable */ + @"Unable to parse response from server.", /** MCOErrorParse */ + @"The certificate for this server is invalid.", /** MCOErrorCertificate */ + @"Unable to authenticate with the current session's credentials.", /** MCOErrorAuthentication */ + @"IMAP is not enabled for this Gmail account.", /** MCOErrorGmailIMAPNotEnabled */ + @"Bandwidth limits were exceeded while requesting data from this Gmail account.", /** MCOErrorGmailExceededBandwidthLimit */ + @"Too many simultaneous connections were made to this Gmail account.", /** MCOErrorGmailTooManySimultaneousConnections */ + @"MobileMe is no longer an active mail service.", /** MCOErrorMobileMeMoved */ + @"Yahoo!'s servers are currently unavailable.", /** MCOErrorYahooUnavailable */ + @"The requested folder does not exist. Folder selection failed", /** MCOErrorNonExistantFolder */ + @"An error occured while renaming the requested folder.", /** MCOErrorRename */ + @"An error occured while deleting the requested folder.", /** MCOErrorDelete */ + @"An error occured while creating the requested folder.", /** MCOErrorCreate */ + @"An error occured while (un)subscribing to the requested folder.", /** MCOErrorSubscribe */ + @"An error occured while appending a message to the requested folder.", /** MCOErrorAppend */ + @"An error occured while copying a message to the requested folder.", /** MCOErrorCopy */ + @"An error occured while expunging a message in the requested folder.", /** MCOErrorExpunge */ + @"An error occured while fetching messages in the requested folder.", /** MCOErrorFetch */ + @"An error occured during an IDLE operation.", /** MCOErrorIdle */ + @"An error occured while requesting the server's identity.", /** MCOErrorIdentity */ + @"An error occured while requesting the server's namespace.", /** MCOErrorNamespace */ + @"An error occured while storing flags.", /** MCOErrorStore */ + @"An error occured while requesting the server's capabilities.", /** MCOErrorCapability */ + @"The server does not support STARTTLS connections.", /** MCOErrorStartTLSNotAvailable */ + @"Attempted to send a message with an illegal attachment.", /** MCOErrorSendMessageIllegalAttachment */ + @"The SMTP storage limit was hit while trying to send a large message.", /** MCOErrorStorageLimit */ + @"Sending messages is not allowed on this server.", /** MCOErrorSendMessageNotAllowed */ + @"The current HotMail account cannot connect to WebMail.", /** MCOErrorNeedsConnectToWebmail */ + @"An error occured while sending the message.", /** MCOErrorSendMessage */ + @"Authentication is required for this SMTP server.", /** MCOErrorAuthenticationRequired */ + @"An error occured while fetching a message list on the POP server.", /** MCOErrorFetchMessageList */ + @"An error occured while deleting a message on the POP server.", /** MCOErrorDeleteMessage */ + @"Account check failed because the account is invalid.", /** MCOErrorInvalidAccount */ +}; + #endif diff --git a/src/objc/utils/NSError+MCO.mm b/src/objc/utils/NSError+MCO.mm index c9f4f998..df12123e 100644 --- a/src/objc/utils/NSError+MCO.mm +++ b/src/objc/utils/NSError+MCO.mm @@ -12,10 +12,13 @@ if (code == mailcore::ErrorNone) { return nil; } - + + NSMutableDictionary *userInfo = [[NSMutableDictionary alloc] init]; + [userInfo setObject:MCOLocalizedDescriptionTable[code] forKey:NSLocalizedDescriptionKey]; + NSError *error = [NSError errorWithDomain:MCOErrorDomain code:(int)code - userInfo:nil]; + userInfo:userInfo]; return error; } -@end \ No newline at end of file +@end -- cgit v1.2.3 From b994253888b35ba80a1da4bad6de58c4027d853f Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Thu, 4 Jul 2013 22:08:20 -0600 Subject: Moved table --- src/objc/abstract/MCOConstants.h | 40 ++----------------------------------- src/objc/utils/NSError+MCO.mm | 43 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 39 deletions(-) diff --git a/src/objc/abstract/MCOConstants.h b/src/objc/abstract/MCOConstants.h index 4d1ce094..58239811 100644 --- a/src/objc/abstract/MCOConstants.h +++ b/src/objc/abstract/MCOConstants.h @@ -324,6 +324,8 @@ typedef enum { MCOErrorDeleteMessage, /** SMTP: Error while checking account.*/ MCOErrorInvalidAccount, + /** The count of all errors */ + MCOErrorCodeCount, } MCOErrorCode; /** Here's the list of connection log types.*/ @@ -350,42 +352,4 @@ typedef enum { */ typedef void (^MCOConnectionLogger)(void * connectionID, MCOConnectionLogType type, NSData * data); -NSString * MCOLocalizedDescriptionTable[] = { - @"", /** MCOErrorNone */ - @"A stable connection to the server could not be established.", /** MCOErrorConnection */ - @"The server does not support TLS/SSL connections.", /** MCOErrorTLSNotAvailable */ - @"Unable to parse response from server.", /** MCOErrorParse */ - @"The certificate for this server is invalid.", /** MCOErrorCertificate */ - @"Unable to authenticate with the current session's credentials.", /** MCOErrorAuthentication */ - @"IMAP is not enabled for this Gmail account.", /** MCOErrorGmailIMAPNotEnabled */ - @"Bandwidth limits were exceeded while requesting data from this Gmail account.", /** MCOErrorGmailExceededBandwidthLimit */ - @"Too many simultaneous connections were made to this Gmail account.", /** MCOErrorGmailTooManySimultaneousConnections */ - @"MobileMe is no longer an active mail service.", /** MCOErrorMobileMeMoved */ - @"Yahoo!'s servers are currently unavailable.", /** MCOErrorYahooUnavailable */ - @"The requested folder does not exist. Folder selection failed", /** MCOErrorNonExistantFolder */ - @"An error occured while renaming the requested folder.", /** MCOErrorRename */ - @"An error occured while deleting the requested folder.", /** MCOErrorDelete */ - @"An error occured while creating the requested folder.", /** MCOErrorCreate */ - @"An error occured while (un)subscribing to the requested folder.", /** MCOErrorSubscribe */ - @"An error occured while appending a message to the requested folder.", /** MCOErrorAppend */ - @"An error occured while copying a message to the requested folder.", /** MCOErrorCopy */ - @"An error occured while expunging a message in the requested folder.", /** MCOErrorExpunge */ - @"An error occured while fetching messages in the requested folder.", /** MCOErrorFetch */ - @"An error occured during an IDLE operation.", /** MCOErrorIdle */ - @"An error occured while requesting the server's identity.", /** MCOErrorIdentity */ - @"An error occured while requesting the server's namespace.", /** MCOErrorNamespace */ - @"An error occured while storing flags.", /** MCOErrorStore */ - @"An error occured while requesting the server's capabilities.", /** MCOErrorCapability */ - @"The server does not support STARTTLS connections.", /** MCOErrorStartTLSNotAvailable */ - @"Attempted to send a message with an illegal attachment.", /** MCOErrorSendMessageIllegalAttachment */ - @"The SMTP storage limit was hit while trying to send a large message.", /** MCOErrorStorageLimit */ - @"Sending messages is not allowed on this server.", /** MCOErrorSendMessageNotAllowed */ - @"The current HotMail account cannot connect to WebMail.", /** MCOErrorNeedsConnectToWebmail */ - @"An error occured while sending the message.", /** MCOErrorSendMessage */ - @"Authentication is required for this SMTP server.", /** MCOErrorAuthenticationRequired */ - @"An error occured while fetching a message list on the POP server.", /** MCOErrorFetchMessageList */ - @"An error occured while deleting a message on the POP server.", /** MCOErrorDeleteMessage */ - @"Account check failed because the account is invalid.", /** MCOErrorInvalidAccount */ -}; - #endif diff --git a/src/objc/utils/NSError+MCO.mm b/src/objc/utils/NSError+MCO.mm index df12123e..8b3b0c24 100644 --- a/src/objc/utils/NSError+MCO.mm +++ b/src/objc/utils/NSError+MCO.mm @@ -7,6 +7,44 @@ #import "MCOConstants.h" +static NSString * MCOLocalizedDescriptionTable[] = { + @"", /** MCOErrorNone */ + @"A stable connection to the server could not be established.", /** MCOErrorConnection */ + @"The server does not support TLS/SSL connections.", /** MCOErrorTLSNotAvailable */ + @"Unable to parse response from server.", /** MCOErrorParse */ + @"The certificate for this server is invalid.", /** MCOErrorCertificate */ + @"Unable to authenticate with the current session's credentials.", /** MCOErrorAuthentication */ + @"IMAP is not enabled for this Gmail account.", /** MCOErrorGmailIMAPNotEnabled */ + @"Bandwidth limits were exceeded while requesting data from this Gmail account.", /** MCOErrorGmailExceededBandwidthLimit */ + @"Too many simultaneous connections were made to this Gmail account.", /** MCOErrorGmailTooManySimultaneousConnections */ + @"MobileMe is no longer an active mail service.", /** MCOErrorMobileMeMoved */ + @"Yahoo!'s servers are currently unavailable.", /** MCOErrorYahooUnavailable */ + @"The requested folder does not exist. Folder selection failed", /** MCOErrorNonExistantFolder */ + @"An error occured while renaming the requested folder.", /** MCOErrorRename */ + @"An error occured while deleting the requested folder.", /** MCOErrorDelete */ + @"An error occured while creating the requested folder.", /** MCOErrorCreate */ + @"An error occured while (un)subscribing to the requested folder.", /** MCOErrorSubscribe */ + @"An error occured while appending a message to the requested folder.", /** MCOErrorAppend */ + @"An error occured while copying a message to the requested folder.", /** MCOErrorCopy */ + @"An error occured while expunging a message in the requested folder.", /** MCOErrorExpunge */ + @"An error occured while fetching messages in the requested folder.", /** MCOErrorFetch */ + @"An error occured during an IDLE operation.", /** MCOErrorIdle */ + @"An error occured while requesting the server's identity.", /** MCOErrorIdentity */ + @"An error occured while requesting the server's namespace.", /** MCOErrorNamespace */ + @"An error occured while storing flags.", /** MCOErrorStore */ + @"An error occured while requesting the server's capabilities.", /** MCOErrorCapability */ + @"The server does not support STARTTLS connections.", /** MCOErrorStartTLSNotAvailable */ + @"Attempted to send a message with an illegal attachment.", /** MCOErrorSendMessageIllegalAttachment */ + @"The SMTP storage limit was hit while trying to send a large message.", /** MCOErrorStorageLimit */ + @"Sending messages is not allowed on this server.", /** MCOErrorSendMessageNotAllowed */ + @"The current HotMail account cannot connect to WebMail.", /** MCOErrorNeedsConnectToWebmail */ + @"An error occured while sending the message.", /** MCOErrorSendMessage */ + @"Authentication is required for this SMTP server.", /** MCOErrorAuthenticationRequired */ + @"An error occured while fetching a message list on the POP server.", /** MCOErrorFetchMessageList */ + @"An error occured while deleting a message on the POP server.", /** MCOErrorDeleteMessage */ + @"Account check failed because the account is invalid.", /** MCOErrorInvalidAccount */ +}; + @implementation NSError (MCO) + (NSError *)mco_errorWithErrorCode:(mailcore::ErrorCode)code { if (code == mailcore::ErrorNone) { @@ -14,7 +52,10 @@ } NSMutableDictionary *userInfo = [[NSMutableDictionary alloc] init]; - [userInfo setObject:MCOLocalizedDescriptionTable[code] forKey:NSLocalizedDescriptionKey]; + if (code < MCOErrorCodeCount) { + NSString * localizedString = NSLocalizedStringFromTable(MCOLocalizedDescriptionTable[code], @"description of errors of mailcore", @"MailCore"); + [userInfo setObject:localizedString forKey:NSLocalizedDescriptionKey]; + } NSError *error = [NSError errorWithDomain:MCOErrorDomain code:(int)code -- cgit v1.2.3 From b44204256f7cbe5ac79daecaad27ce09e986f72f Mon Sep 17 00:00:00 2001 From: CodaFi Date: Fri, 5 Jul 2013 21:34:26 -0600 Subject: Added MCOErrorNone message --- src/objc/utils/NSError+MCO.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/objc/utils/NSError+MCO.mm b/src/objc/utils/NSError+MCO.mm index 8b3b0c24..47abf809 100644 --- a/src/objc/utils/NSError+MCO.mm +++ b/src/objc/utils/NSError+MCO.mm @@ -8,7 +8,7 @@ #import "MCOConstants.h" static NSString * MCOLocalizedDescriptionTable[] = { - @"", /** MCOErrorNone */ + @"The operation succeeded.", /** MCOErrorNone */ @"A stable connection to the server could not be established.", /** MCOErrorConnection */ @"The server does not support TLS/SSL connections.", /** MCOErrorTLSNotAvailable */ @"Unable to parse response from server.", /** MCOErrorParse */ -- cgit v1.2.3 From f00e5f03199c2689c06eab9d2ae71a56f0ad53fb Mon Sep 17 00:00:00 2001 From: "Hoa V. DINH" Date: Wed, 3 Jul 2013 23:54:43 -0400 Subject: Added OAuth2 token API on MCOIMAPSession --- src/objc/imap/MCOIMAPSession.h | 9 ++++++--- src/objc/imap/MCOIMAPSession.mm | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/objc/imap/MCOIMAPSession.h b/src/objc/imap/MCOIMAPSession.h index 0358f7ad..3a6cbc6f 100644 --- a/src/objc/imap/MCOIMAPSession.h +++ b/src/objc/imap/MCOIMAPSession.h @@ -40,16 +40,19 @@ @interface MCOIMAPSession : NSObject /** This is the hostname of the IMAP server to connect to. */ -@property (nonatomic, strong) NSString *hostname; +@property (nonatomic, copy) NSString *hostname; /** This is the port of the IMAP server to connect to. */ @property (nonatomic, assign) unsigned int port; /** This is the username of the account. */ -@property (nonatomic, strong) NSString *username; +@property (nonatomic, copy) NSString *username; /** This is the password of the account. */ -@property (nonatomic, strong) NSString *password; +@property (nonatomic, copy) NSString *password; + +/** This is the OAuth2 token. */ +@property (nonatomic, copy) NSString *OAuth2Token; /** This is the authentication type to use to connect. diff --git a/src/objc/imap/MCOIMAPSession.mm b/src/objc/imap/MCOIMAPSession.mm index 0c23f1e2..1dff0f1f 100644 --- a/src/objc/imap/MCOIMAPSession.mm +++ b/src/objc/imap/MCOIMAPSession.mm @@ -77,6 +77,7 @@ MCO_OBJC_SYNTHESIZE_STRING(setHostname, hostname) MCO_OBJC_SYNTHESIZE_SCALAR(unsigned int, unsigned int, setPort, port) MCO_OBJC_SYNTHESIZE_STRING(setUsername, username) MCO_OBJC_SYNTHESIZE_STRING(setPassword, password) +MCO_OBJC_SYNTHESIZE_STRING(setOAuth2Token, OAuth2Token) MCO_OBJC_SYNTHESIZE_SCALAR(MCOAuthType, mailcore::AuthType, setAuthType, authType) MCO_OBJC_SYNTHESIZE_SCALAR(MCOConnectionType, mailcore::ConnectionType, setConnectionType, connectionType) MCO_OBJC_SYNTHESIZE_SCALAR(NSTimeInterval, time_t, setTimeout, timeout) -- cgit v1.2.3 From 83aa26d94613a7220e55899e763e069715511d69 Mon Sep 17 00:00:00 2001 From: "Hoa V. DINH" Date: Fri, 5 Jul 2013 20:57:41 -0700 Subject: Added simple rendering methods for RFC822 message at C++ API level --- build-mac/mailcore2.xcodeproj/project.pbxproj | 8 ++++++ .../renderer/HTMLBodyRendererTemplateCallback.cc | 16 ++++++++++++ .../renderer/HTMLBodyRendererTemplateCallback.h | 28 ++++++++++++++++++++ src/core/rfc822/MCMessageBuilder.cc | 19 ++++++++++++++ src/core/rfc822/MCMessageBuilder.h | 4 +++ src/core/rfc822/MCMessageParser.cc | 30 ++++++++++++++++++++++ src/core/rfc822/MCMessageParser.h | 4 +++ tests/test-all.mm | 3 ++- 8 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 src/core/renderer/HTMLBodyRendererTemplateCallback.cc create mode 100644 src/core/renderer/HTMLBodyRendererTemplateCallback.h diff --git a/build-mac/mailcore2.xcodeproj/project.pbxproj b/build-mac/mailcore2.xcodeproj/project.pbxproj index cedef738..7ae5ee05 100644 --- a/build-mac/mailcore2.xcodeproj/project.pbxproj +++ b/build-mac/mailcore2.xcodeproj/project.pbxproj @@ -113,6 +113,8 @@ C64BB26416FD43A1000DB34C /* MCOMessageParser.mm in Sources */ = {isa = PBXBuildFile; fileRef = C64BB26316FD43A1000DB34C /* MCOMessageParser.mm */; }; C64BB26716FD43E2000DB34C /* MCOMessagePart.mm in Sources */ = {isa = PBXBuildFile; fileRef = C64BB26616FD43E2000DB34C /* MCOMessagePart.mm */; }; C64BB26A16FD44C2000DB34C /* MCOMultipart.mm in Sources */ = {isa = PBXBuildFile; fileRef = C64BB26916FD44C2000DB34C /* MCOMultipart.mm */; }; + C64DBFFD1787CA050012CA0B /* HTMLBodyRendererTemplateCallback.cc in Sources */ = {isa = PBXBuildFile; fileRef = C64DBFFB1787CA050012CA0B /* HTMLBodyRendererTemplateCallback.cc */; }; + C64DBFFE1787CA050012CA0B /* HTMLBodyRendererTemplateCallback.cc in Sources */ = {isa = PBXBuildFile; fileRef = C64DBFFB1787CA050012CA0B /* HTMLBodyRendererTemplateCallback.cc */; }; C64EA6F4169E847800778456 /* MCAbstractMessage.cc in Sources */ = {isa = PBXBuildFile; fileRef = C64EA694169E847800778456 /* MCAbstractMessage.cc */; }; C64EA6F6169E847800778456 /* MCAbstractMessagePart.cc in Sources */ = {isa = PBXBuildFile; fileRef = C64EA696169E847800778456 /* MCAbstractMessagePart.cc */; }; C64EA6F8169E847800778456 /* MCAbstractMultipart.cc in Sources */ = {isa = PBXBuildFile; fileRef = C64EA698169E847800778456 /* MCAbstractMultipart.cc */; }; @@ -1175,6 +1177,8 @@ C64BB26B16FD4C3B000DB34C /* MCORFC822.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCORFC822.h; sourceTree = ""; }; C64BB26C16FD62FB000DB34C /* MCOUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCOUtils.h; sourceTree = ""; }; C64BB26D16FD63F6000DB34C /* MCOConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCOConstants.h; sourceTree = ""; }; + C64DBFFB1787CA050012CA0B /* HTMLBodyRendererTemplateCallback.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLBodyRendererTemplateCallback.cc; sourceTree = ""; }; + C64DBFFC1787CA050012CA0B /* HTMLBodyRendererTemplateCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLBodyRendererTemplateCallback.h; sourceTree = ""; }; C64EA537169E772200778456 /* libMailCore.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libMailCore.a; sourceTree = BUILT_PRODUCTS_DIR; }; C64EA68C169E847800778456 /* MCIMAPAsyncConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCIMAPAsyncConnection.h; sourceTree = ""; }; C64EA68F169E847800778456 /* MCSMTPAsyncSession.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MCSMTPAsyncSession.cc; sourceTree = ""; }; @@ -1534,6 +1538,8 @@ C63CD67616BDCDD300DB18F1 /* renderer */ = { isa = PBXGroup; children = ( + C64DBFFB1787CA050012CA0B /* HTMLBodyRendererTemplateCallback.cc */, + C64DBFFC1787CA050012CA0B /* HTMLBodyRendererTemplateCallback.h */, C63CD67716BDCDD400DB18F1 /* MCAddressDisplay.cc */, C63CD67816BDCDD400DB18F1 /* MCAddressDisplay.h */, C63CD67916BDCDD400DB18F1 /* MCDateFormatter.cc */, @@ -2337,6 +2343,7 @@ C64EA6F6169E847800778456 /* MCAbstractMessagePart.cc in Sources */, C64EA6F8169E847800778456 /* MCAbstractMultipart.cc in Sources */, C64EA6FA169E847800778456 /* MCAbstractPart.cc in Sources */, + C64DBFFD1787CA050012CA0B /* HTMLBodyRendererTemplateCallback.cc in Sources */, C64EA6FC169E847800778456 /* MCAddress.cc in Sources */, C64EA6FF169E847800778456 /* MCMessageHeader.cc in Sources */, C64EA701169E847800778456 /* MCAutoreleasePool.cc in Sources */, @@ -2519,6 +2526,7 @@ C6BA2B9A1705F4E6003F0E9E /* MCAbstractMessagePart.cc in Sources */, C6BA2B9B1705F4E6003F0E9E /* MCAbstractMultipart.cc in Sources */, C6BA2B9C1705F4E6003F0E9E /* MCAbstractPart.cc in Sources */, + C64DBFFE1787CA050012CA0B /* HTMLBodyRendererTemplateCallback.cc in Sources */, C6BA2B9D1705F4E6003F0E9E /* MCAddress.cc in Sources */, C6BA2B9E1705F4E6003F0E9E /* MCMessageHeader.cc in Sources */, C6BA2B9F1705F4E6003F0E9E /* MCAutoreleasePool.cc in Sources */, diff --git a/src/core/renderer/HTMLBodyRendererTemplateCallback.cc b/src/core/renderer/HTMLBodyRendererTemplateCallback.cc new file mode 100644 index 00000000..94ee6de7 --- /dev/null +++ b/src/core/renderer/HTMLBodyRendererTemplateCallback.cc @@ -0,0 +1,16 @@ +// +// HTMLBodyRendererTemplateCallback.cc +// mailcore2 +// +// Created by Paul Young on 02/07/2013. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#include "HTMLBodyRendererTemplateCallback.h" + +using namespace mailcore; + +mailcore::String * HTMLBodyRendererTemplateCallback::templateForMainHeader(MessageHeader * header) +{ + return MCSTR(""); +} diff --git a/src/core/renderer/HTMLBodyRendererTemplateCallback.h b/src/core/renderer/HTMLBodyRendererTemplateCallback.h new file mode 100644 index 00000000..7901e265 --- /dev/null +++ b/src/core/renderer/HTMLBodyRendererTemplateCallback.h @@ -0,0 +1,28 @@ +// +// HTMLBodyRendererTemplateCallback.h +// mailcore2 +// +// Created by Paul Young on 02/07/2013. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#ifndef __MAILCORE_MCHTMLBODYRENDERERTEMPLATECALLBACK_H_ + +#define __MAILCORE_MCHTMLBODYRENDERERTEMPLATECALLBACK_H_ + +#include + +#ifdef __cplusplus + +namespace mailcore { + + class HTMLBodyRendererTemplateCallback : public Object, public HTMLRendererTemplateCallback { + public: + virtual String * templateForMainHeader(MessageHeader * header); + }; + +} + +#endif + +#endif diff --git a/src/core/rfc822/MCMessageBuilder.cc b/src/core/rfc822/MCMessageBuilder.cc index ea449fd6..7f902be1 100644 --- a/src/core/rfc822/MCMessageBuilder.cc +++ b/src/core/rfc822/MCMessageBuilder.cc @@ -691,3 +691,22 @@ String * MessageBuilder::htmlRendering(HTMLRendererTemplateCallback * htmlCallba MessageParser * message = MessageParser::messageParserWithData(data()); return message->htmlRendering(htmlCallback); } + +String * MessageBuilder::htmlBodyRendering() +{ + MessageParser * message = MessageParser::messageParserWithData(data()); + return message->htmlBodyRendering(); +} + +String * MessageBuilder::plainTextRendering() +{ + MessageParser * message = MessageParser::messageParserWithData(data()); + return message->plainTextRendering(); +} + +String * MessageBuilder::plainTextBodyRendering() +{ + MessageParser * message = MessageParser::messageParserWithData(data()); + return message->plainTextBodyRendering(); +} + diff --git a/src/core/rfc822/MCMessageBuilder.h b/src/core/rfc822/MCMessageBuilder.h index 409cd9ee..efbb1f47 100644 --- a/src/core/rfc822/MCMessageBuilder.h +++ b/src/core/rfc822/MCMessageBuilder.h @@ -41,6 +41,10 @@ namespace mailcore { virtual Data * data(); virtual String * htmlRendering(HTMLRendererTemplateCallback * htmlCallback = NULL); + virtual String * htmlBodyRendering(); + + virtual String * plainTextRendering(); + virtual String * plainTextBodyRendering(); public: // subclass behavior MessageBuilder(MessageBuilder * other); diff --git a/src/core/rfc822/MCMessageParser.cc b/src/core/rfc822/MCMessageParser.cc index b936fabf..1de28d6b 100644 --- a/src/core/rfc822/MCMessageParser.cc +++ b/src/core/rfc822/MCMessageParser.cc @@ -5,6 +5,7 @@ #include "MCAttachment.h" #include "MCMessageHeader.h" #include "MCHTMLRenderer.h" +#include "HTMLBodyRendererTemplateCallback.h" using namespace mailcore; @@ -96,3 +97,32 @@ String * MessageParser::htmlRendering(HTMLRendererTemplateCallback * htmlCallbac return HTMLRenderer::htmlForRFC822Message(this, htmlCallback); } +String * MessageParser::htmlBodyRendering() +{ + HTMLBodyRendererTemplateCallback * callback = new HTMLBodyRendererTemplateCallback(); + String * result = htmlRendering(callback); + MC_SAFE_RELEASE(callback); + return result; +} + +String * MessageParser::plainTextRendering() +{ + String * html = htmlRendering(NULL); + return html->flattenHTML(); +} + +String * MessageParser::plainTextBodyRendering() +{ + String * html = htmlBodyRendering(); + String * plainTextBodyString = html->flattenHTML(); + + plainTextBodyString->replaceOccurrencesOfString(MCSTR("\t"), MCSTR(" ")); + plainTextBodyString->replaceOccurrencesOfString(MCSTR("\n"), MCSTR(" ")); + plainTextBodyString->replaceOccurrencesOfString(MCSTR("\v"), MCSTR(" ")); + plainTextBodyString->replaceOccurrencesOfString(MCSTR("\f"), MCSTR(" ")); + plainTextBodyString->replaceOccurrencesOfString(MCSTR("\r"), MCSTR(" ")); + while (plainTextBodyString->replaceOccurrencesOfString(MCSTR(" "), MCSTR(" "))) { + // do nothing. + } + return plainTextBodyString; +} diff --git a/src/core/rfc822/MCMessageParser.h b/src/core/rfc822/MCMessageParser.h index 4f13299d..bed41793 100644 --- a/src/core/rfc822/MCMessageParser.h +++ b/src/core/rfc822/MCMessageParser.h @@ -24,6 +24,10 @@ namespace mailcore { virtual Data * data(); virtual String * htmlRendering(HTMLRendererTemplateCallback * htmlCallback = NULL); + virtual String * htmlBodyRendering(); + + virtual String * plainTextRendering(); + virtual String * plainTextBodyRendering(); public: // subclass behavior MessageParser(MessageParser * other); diff --git a/tests/test-all.mm b/tests/test-all.mm index fdb0888c..c58e5888 100644 --- a/tests/test-all.mm +++ b/tests/test-all.mm @@ -84,6 +84,7 @@ static void testMessageParser(mailcore::Data * data) MCLog("%s", MCUTF8DESC(parser)); MCLog("HTML rendering"); MCLog("%s", MCUTF8(parser->htmlRendering())); + MCLog("%s", MCUTF8(parser->plainTextBodyRendering())); } static void testIMAP() @@ -365,7 +366,7 @@ void testAll() //testAddresses(); //testAttachments(); //testProviders(); - testObjC(); + //testObjC(); MCLog("pool release"); pool->release(); -- cgit v1.2.3 From 3398120ecbe74c4e3a68a886683d9b9fb6390aae Mon Sep 17 00:00:00 2001 From: "Hoa V. DINH" Date: Fri, 5 Jul 2013 21:05:28 -0700 Subject: Objective-C bridge for simple rendering methods for RFC822 message --- src/objc/rfc822/MCOMessageBuilder.h | 10 ++++++++++ src/objc/rfc822/MCOMessageBuilder.mm | 16 ++++++++++++++++ src/objc/rfc822/MCOMessageParser.h | 10 ++++++++++ src/objc/rfc822/MCOMessageParser.mm | 15 +++++++++++++++ 4 files changed, 51 insertions(+) diff --git a/src/objc/rfc822/MCOMessageBuilder.h b/src/objc/rfc822/MCOMessageBuilder.h index 217ec49c..5ba199a4 100644 --- a/src/objc/rfc822/MCOMessageBuilder.h +++ b/src/objc/rfc822/MCOMessageBuilder.h @@ -61,6 +61,16 @@ /** HTML rendering of the message to be displayed in a web view. The delegate can be nil.*/ - (NSString *) htmlRenderingWithDelegate:(id )delegate; +/** HTML rendering of the body of the message to be displayed in a web view.*/ +- (NSString *) htmlBodyRendering; + +/** Text rendering of the message.*/ +- (NSString *) plainTextRendering; + +/** Text rendering of the body of the message. All end of line will be removed and white spaces cleaned up. + This method can be used to generate the summary of the message.*/ +- (NSString *) plainTextBodyRendering; + @end #endif diff --git a/src/objc/rfc822/MCOMessageBuilder.mm b/src/objc/rfc822/MCOMessageBuilder.mm index 2cb26448..dfcf6028 100644 --- a/src/objc/rfc822/MCOMessageBuilder.mm +++ b/src/objc/rfc822/MCOMessageBuilder.mm @@ -75,4 +75,20 @@ MCO_OBJC_SYNTHESIZE_STRING(setBoundaryPrefix, boundaryPrefix) return result; } + +- (NSString *) htmlBodyRendering +{ + return MCO_OBJC_BRIDGE_GET(htmlBodyRendering); +} + +- (NSString *) plainTextRendering +{ + return MCO_OBJC_BRIDGE_GET(plainTextRendering); +} + +- (NSString *) plainTextBodyRendering +{ + return MCO_OBJC_BRIDGE_GET(plainTextBodyRendering); +} + @end diff --git a/src/objc/rfc822/MCOMessageParser.h b/src/objc/rfc822/MCOMessageParser.h index fa46132b..82613403 100644 --- a/src/objc/rfc822/MCOMessageParser.h +++ b/src/objc/rfc822/MCOMessageParser.h @@ -38,6 +38,16 @@ /** HTML rendering of the message to be displayed in a web view. delegate can be nil.*/ - (NSString *) htmlRenderingWithDelegate:(id )delegate; +/** HTML rendering of the body of the message to be displayed in a web view.*/ +- (NSString *) htmlBodyRendering; + +/** Text rendering of the message.*/ +- (NSString *) plainTextRendering; + +/** Text rendering of the body of the message. All end of line will be removed and white spaces cleaned up. + This method can be used to generate the summary of the message.*/ +- (NSString *) plainTextBodyRendering; + @end #endif diff --git a/src/objc/rfc822/MCOMessageParser.mm b/src/objc/rfc822/MCOMessageParser.mm index 05f52f54..84631430 100644 --- a/src/objc/rfc822/MCOMessageParser.mm +++ b/src/objc/rfc822/MCOMessageParser.mm @@ -77,4 +77,19 @@ return result; } +- (NSString *) htmlBodyRendering +{ + return MCO_OBJC_BRIDGE_GET(htmlBodyRendering); +} + +- (NSString *) plainTextRendering +{ + return MCO_OBJC_BRIDGE_GET(plainTextRendering); +} + +- (NSString *) plainTextBodyRendering +{ + return MCO_OBJC_BRIDGE_GET(plainTextBodyRendering); +} + @end -- cgit v1.2.3