aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/async/imap/MCIMAPAsyncConnection.cc2
-rw-r--r--src/async/imap/MCIMAPFetchFoldersOperation.cc4
-rw-r--r--src/async/imap/MCIMAPIdleOperation.cc4
-rw-r--r--src/async/pop/MCPOPAsyncSession.cc2
-rw-r--r--src/async/smtp/MCSMTPAsyncSession.cc12
-rw-r--r--src/async/smtp/MCSMTPAsyncSession.h3
-rw-r--r--src/core/abstract/MCAbstractMessagePart.cc2
-rw-r--r--src/core/basetypes/MCConnectionLogger.h1
-rw-r--r--src/core/basetypes/MCLog.c (renamed from src/core/basetypes/MCLog.cc)6
-rw-r--r--src/core/basetypes/MCLog.h24
-rw-r--r--src/core/imap/MCIMAPMessage.cc2
-rw-r--r--src/core/imap/MCIMAPSession.cc102
-rw-r--r--src/core/renderer/HTMLBodyRendererTemplateCallback.cc16
-rw-r--r--src/core/renderer/HTMLBodyRendererTemplateCallback.h28
-rw-r--r--src/core/rfc822/MCMessageBuilder.cc21
-rw-r--r--src/core/rfc822/MCMessageBuilder.h4
-rw-r--r--src/core/rfc822/MCMessageParser.cc32
-rw-r--r--src/core/rfc822/MCMessageParser.h4
-rw-r--r--src/core/smtp/MCSMTPSession.cc158
-rw-r--r--src/core/smtp/MCSMTPSession.h6
-rw-r--r--src/objc/abstract/MCOAbstractMessage.h2
-rw-r--r--src/objc/abstract/MCOAbstractMessage.mm8
-rw-r--r--src/objc/abstract/MCOAbstractPart.h2
-rw-r--r--src/objc/abstract/MCOAbstractPart.mm8
-rw-r--r--src/objc/abstract/MCOConstants.h2
-rw-r--r--src/objc/imap/MCOIMAPMessage.h2
-rw-r--r--src/objc/imap/MCOIMAPMessage.mm8
-rw-r--r--src/objc/imap/MCOIMAPMessagePart.h2
-rw-r--r--src/objc/imap/MCOIMAPMessagePart.mm8
-rw-r--r--src/objc/imap/MCOIMAPMultipart.h2
-rw-r--r--src/objc/imap/MCOIMAPMultipart.mm8
-rw-r--r--src/objc/imap/MCOIMAPPart.h2
-rw-r--r--src/objc/imap/MCOIMAPPart.mm8
-rw-r--r--src/objc/imap/MCOIMAPSession.h9
-rw-r--r--src/objc/imap/MCOIMAPSession.mm3
-rw-r--r--src/objc/pop/MCOPOPSession.mm2
-rw-r--r--src/objc/provider/MCONetService.h2
-rw-r--r--src/objc/provider/MCONetService.mm64
-rw-r--r--src/objc/rfc822/MCOAttachment.h2
-rw-r--r--src/objc/rfc822/MCOAttachment.mm8
-rw-r--r--src/objc/rfc822/MCOMessageBuilder.h10
-rw-r--r--src/objc/rfc822/MCOMessageBuilder.mm16
-rw-r--r--src/objc/rfc822/MCOMessageParser.h12
-rw-r--r--src/objc/rfc822/MCOMessageParser.mm23
-rw-r--r--src/objc/rfc822/MCOMessagePart.mm8
-rw-r--r--src/objc/rfc822/MCOMultipart.h2
-rw-r--r--src/objc/rfc822/MCOMultipart.mm8
-rw-r--r--src/objc/smtp/MCOSMTPSession.h3
-rw-r--r--src/objc/smtp/MCOSMTPSession.mm3
-rw-r--r--src/objc/utils/NSError+MCO.mm50
50 files changed, 459 insertions, 261 deletions
diff --git a/src/async/imap/MCIMAPAsyncConnection.cc b/src/async/imap/MCIMAPAsyncConnection.cc
index fc1935b7..1d07f79a 100644
--- a/src/async/imap/MCIMAPAsyncConnection.cc
+++ b/src/async/imap/MCIMAPAsyncConnection.cc
@@ -69,7 +69,7 @@ namespace mailcore {
virtual ~IMAPConnectionLogger() {
}
- virtual void log(void * context, void * sender, ConnectionLogType logType, Data * buffer)
+ virtual void log(void * sender, ConnectionLogType logType, Data * buffer)
{
mConnection->logConnection(logType, buffer);
}
diff --git a/src/async/imap/MCIMAPFetchFoldersOperation.cc b/src/async/imap/MCIMAPFetchFoldersOperation.cc
index 07533e6e..41a95572 100644
--- a/src/async/imap/MCIMAPFetchFoldersOperation.cc
+++ b/src/async/imap/MCIMAPFetchFoldersOperation.cc
@@ -55,8 +55,8 @@ void IMAPFetchFoldersOperation::main()
char * delimiterData = (char *) malloc(1);
* delimiterData = session()->session()->delimiter();
- session()->performMethodOnMainThread((Object::Method) &IMAPFetchFoldersOperation::setDelimiterDataOnMainThread,
- delimiterData);
+ performMethodOnMainThread((Object::Method) &IMAPFetchFoldersOperation::setDelimiterDataOnMainThread,
+ delimiterData, true);
}
void IMAPFetchFoldersOperation::setDelimiterDataOnMainThread(char * delimiterData)
diff --git a/src/async/imap/MCIMAPIdleOperation.cc b/src/async/imap/MCIMAPIdleOperation.cc
index 42c58f90..8b48b77c 100644
--- a/src/async/imap/MCIMAPIdleOperation.cc
+++ b/src/async/imap/MCIMAPIdleOperation.cc
@@ -47,7 +47,7 @@ void IMAPIdleOperation::unprepare()
void IMAPIdleOperation::main()
{
- performMethodOnMainThread((Object::Method) &IMAPIdleOperation::prepare, NULL);
+ performMethodOnMainThread((Object::Method) &IMAPIdleOperation::prepare, NULL, true);
if (!mSetupSuccess) {
return;
@@ -57,7 +57,7 @@ void IMAPIdleOperation::main()
session()->session()->idle(folder(), mLastKnownUid, &error);
setError(error);
- performMethodOnMainThread((Object::Method) &IMAPIdleOperation::unprepare, NULL);
+ performMethodOnMainThread((Object::Method) &IMAPIdleOperation::unprepare, NULL, true);
}
void IMAPIdleOperation::interruptIdle()
diff --git a/src/async/pop/MCPOPAsyncSession.cc b/src/async/pop/MCPOPAsyncSession.cc
index 342b0f5e..bfabc847 100644
--- a/src/async/pop/MCPOPAsyncSession.cc
+++ b/src/async/pop/MCPOPAsyncSession.cc
@@ -50,7 +50,7 @@ namespace mailcore {
virtual ~POPConnectionLogger() {
}
- virtual void log(void * context, void * sender, ConnectionLogType logType, Data * buffer)
+ virtual void log(void * sender, ConnectionLogType logType, Data * buffer)
{
mSession->logConnection(logType, buffer);
}
diff --git a/src/async/smtp/MCSMTPAsyncSession.cc b/src/async/smtp/MCSMTPAsyncSession.cc
index fafc2e82..f670894a 100644
--- a/src/async/smtp/MCSMTPAsyncSession.cc
+++ b/src/async/smtp/MCSMTPAsyncSession.cc
@@ -41,7 +41,7 @@ namespace mailcore {
virtual ~SMTPConnectionLogger() {
}
- virtual void log(void * context, void * sender, ConnectionLogType logType, Data * buffer)
+ virtual void log(void * sender, ConnectionLogType logType, Data * buffer)
{
mSession->logConnection(logType, buffer);
}
@@ -113,6 +113,16 @@ String * SMTPAsyncSession::password()
return mSession->password();
}
+void SMTPAsyncSession::setOAuth2Token(String * token)
+{
+ mSession->setOAuth2Token(token);
+}
+
+String * SMTPAsyncSession::OAuth2Token()
+{
+ return mSession->OAuth2Token();
+}
+
void SMTPAsyncSession::setAuthType(AuthType authType)
{
mSession->setAuthType(authType);
diff --git a/src/async/smtp/MCSMTPAsyncSession.h b/src/async/smtp/MCSMTPAsyncSession.h
index 9fa6dbdf..bbb81737 100644
--- a/src/async/smtp/MCSMTPAsyncSession.h
+++ b/src/async/smtp/MCSMTPAsyncSession.h
@@ -33,6 +33,9 @@ namespace mailcore {
virtual void setPassword(String * password);
virtual String * password();
+ virtual void setOAuth2Token(String * token);
+ virtual String * OAuth2Token();
+
virtual void setAuthType(AuthType authType);
virtual AuthType authType();
diff --git a/src/core/abstract/MCAbstractMessagePart.cc b/src/core/abstract/MCAbstractMessagePart.cc
index d2cb232e..b4ec4c9a 100644
--- a/src/core/abstract/MCAbstractMessagePart.cc
+++ b/src/core/abstract/MCAbstractMessagePart.cc
@@ -16,7 +16,7 @@ AbstractMessagePart::AbstractMessagePart()
init();
}
-AbstractMessagePart::AbstractMessagePart(AbstractMessagePart * other)
+AbstractMessagePart::AbstractMessagePart(AbstractMessagePart * other) : AbstractPart(other)
{
init();
if (other->mainPart() != NULL) {
diff --git a/src/core/basetypes/MCConnectionLogger.h b/src/core/basetypes/MCConnectionLogger.h
index dd596857..bdb588bc 100644
--- a/src/core/basetypes/MCConnectionLogger.h
+++ b/src/core/basetypes/MCConnectionLogger.h
@@ -16,7 +16,6 @@
namespace mailcore {
class Data;
- class String;
enum ConnectionLogType {
// Received data
diff --git a/src/core/basetypes/MCLog.cc b/src/core/basetypes/MCLog.c
index 7db01b41..8744f2dd 100644
--- a/src/core/basetypes/MCLog.cc
+++ b/src/core/basetypes/MCLog.c
@@ -9,7 +9,7 @@
#include <unistd.h>
static pid_t sPid = -1;
-bool mailcore::logEnabled = false;
+int MCLogEnabled = 0;
__attribute__((constructor))
static void initialize() {
@@ -20,7 +20,7 @@ static void logInternalv(FILE * file,
const char * user, const char * filename, unsigned int line,
int dumpStack, const char * format, va_list argp);
-void mailcore::logInternal(const char * user,
+void MCLogInternal(const char * user,
const char * filename,
unsigned int line,
int dumpStack,
@@ -37,7 +37,7 @@ static void logInternalv(FILE * file,
const char * user, const char * filename, unsigned int line,
int dumpStack, const char * format, va_list argp)
{
- if (!mailcore::logEnabled)
+ if (!MCLogEnabled)
return;
while (1) {
diff --git a/src/core/basetypes/MCLog.h b/src/core/basetypes/MCLog.h
index b84a2182..6911ab02 100644
--- a/src/core/basetypes/MCLog.h
+++ b/src/core/basetypes/MCLog.h
@@ -4,26 +4,24 @@
#include <stdio.h>
-#ifdef __cplusplus
-
-#define MCLog(...) mailcore::logInternal(NULL, __FILE__, __LINE__, 0, __VA_ARGS__)
-
-namespace mailcore {
+#define MCLog(...) MCLogInternal(NULL, __FILE__, __LINE__, 0, __VA_ARGS__)
- extern bool logEnabled;
+extern int MCLogEnabled;
#ifndef __printflike
#define __printflike(a,b)
#endif
- void logInternal(const char * user,
- const char * filename,
- unsigned int line,
- int dumpStack,
- const char * format, ...) __printflike(5, 6);
-
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void MCLogInternal(const char * user,
+ const char * filename,
+ unsigned int line,
+ int dumpStack,
+ const char * format, ...) __printflike(5, 6);
+#ifdef __cplusplus
}
-
#endif
#endif
diff --git a/src/core/imap/MCIMAPMessage.cc b/src/core/imap/MCIMAPMessage.cc
index e4a3aea5..ee9b6b0f 100644
--- a/src/core/imap/MCIMAPMessage.cc
+++ b/src/core/imap/MCIMAPMessage.cc
@@ -29,7 +29,7 @@ IMAPMessage::IMAPMessage()
init();
}
-IMAPMessage::IMAPMessage(IMAPMessage * other)
+IMAPMessage::IMAPMessage(IMAPMessage * other) : AbstractMessage(other)
{
init();
setUid(other->uid());
diff --git a/src/core/imap/MCIMAPSession.cc b/src/core/imap/MCIMAPSession.cc
index 8437cded..e013ac75 100644
--- a/src/core/imap/MCIMAPSession.cc
+++ b/src/core/imap/MCIMAPSession.cc
@@ -687,76 +687,76 @@ void IMAPSession::login(ErrorCode * pError)
break;
case AuthTypeSASLCRAMMD5:
- r = mailimap_authenticate(mImap, "CRAM-MD5",
- MCUTF8(mHostname),
- NULL,
- NULL,
- utf8username, utf8username,
- utf8password, NULL);
- break;
+ r = mailimap_authenticate(mImap, "CRAM-MD5",
+ MCUTF8(mHostname),
+ NULL,
+ NULL,
+ utf8username, utf8username,
+ utf8password, NULL);
+ break;
case AuthTypeSASLPlain:
- r = mailimap_authenticate(mImap, "PLAIN",
- MCUTF8(mHostname),
- NULL,
- NULL,
- utf8username, utf8username,
- utf8password, NULL);
- break;
+ r = mailimap_authenticate(mImap, "PLAIN",
+ MCUTF8(mHostname),
+ NULL,
+ NULL,
+ utf8username, utf8username,
+ utf8password, NULL);
+ break;
case AuthTypeSASLGSSAPI:
// needs to be tested
r = mailimap_authenticate(mImap, "GSSAPI",
- MCUTF8(mHostname),
- NULL,
- NULL,
- utf8username, utf8username,
- utf8password, NULL /* realm */);
+ MCUTF8(mHostname),
+ NULL,
+ NULL,
+ utf8username, utf8username,
+ utf8password, NULL /* realm */);
break;
case AuthTypeSASLDIGESTMD5:
r = mailimap_authenticate(mImap, "DIGEST-MD5",
- MCUTF8(mHostname),
- NULL,
- NULL,
- utf8username, utf8username,
- utf8password, NULL);
+ MCUTF8(mHostname),
+ NULL,
+ NULL,
+ utf8username, utf8username,
+ utf8password, NULL);
break;
-
- case AuthTypeSASLLogin:
+
+ case AuthTypeSASLLogin:
r = mailimap_authenticate(mImap, "LOGIN",
- MCUTF8(mHostname),
- NULL,
- NULL,
- utf8username, utf8username,
- utf8password, NULL);
+ MCUTF8(mHostname),
+ NULL,
+ NULL,
+ utf8username, utf8username,
+ utf8password, NULL);
break;
-
- case AuthTypeSASLSRP:
+
+ case AuthTypeSASLSRP:
r = mailimap_authenticate(mImap, "SRP",
- MCUTF8(mHostname),
- NULL,
- NULL,
- utf8username, utf8username,
- utf8password, NULL);
+ MCUTF8(mHostname),
+ NULL,
+ NULL,
+ utf8username, utf8username,
+ utf8password, NULL);
break;
- case AuthTypeSASLNTLM:
+ case AuthTypeSASLNTLM:
r = mailimap_authenticate(mImap, "NTLM",
- MCUTF8(mHostname),
- NULL,
- NULL,
- utf8username, utf8username,
- utf8password, NULL/* realm */);
+ MCUTF8(mHostname),
+ NULL,
+ NULL,
+ utf8username, utf8username,
+ utf8password, NULL/* realm */);
break;
- case AuthTypeSASLKerberosV4:
+ case AuthTypeSASLKerberosV4:
r = mailimap_authenticate(mImap, "KERBEROS_V4",
- MCUTF8(mHostname),
- NULL,
- NULL,
- utf8username, utf8username,
- utf8password, NULL/* realm */);
+ MCUTF8(mHostname),
+ NULL,
+ NULL,
+ utf8username, utf8username,
+ utf8password, NULL/* realm */);
break;
case AuthTypeXOAuth2:
@@ -773,7 +773,7 @@ void IMAPSession::login(ErrorCode * pError)
}
else if (hasError(r)) {
String * response;
-
+
response = MCSTR("");
if (mImap->imap_response != NULL) {
response = String::stringWithUTF8Characters(mImap->imap_response);
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 <MailCore/MCHTMLRendererCallback.h>
+
+#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..fe9d6903 100644
--- a/src/core/rfc822/MCMessageBuilder.cc
+++ b/src/core/rfc822/MCMessageBuilder.cc
@@ -474,7 +474,7 @@ MessageBuilder::MessageBuilder()
init();
}
-MessageBuilder::MessageBuilder(MessageBuilder * other)
+MessageBuilder::MessageBuilder(MessageBuilder * other) : AbstractMessage(other)
{
init();
setHTMLBody(other->mHTMLBody);
@@ -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..3c3037d3 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;
@@ -42,7 +43,7 @@ MessageParser::MessageParser(Data * data)
mailmessage_free(msg);
}
-MessageParser::MessageParser(MessageParser * other)
+MessageParser::MessageParser(MessageParser * other) : AbstractMessage(other)
{
init();
MC_SAFE_REPLACE_RETAIN(Data, mData, other->mData);
@@ -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/src/core/smtp/MCSMTPSession.cc b/src/core/smtp/MCSMTPSession.cc
index dcbad71e..0febf66e 100644
--- a/src/core/smtp/MCSMTPSession.cc
+++ b/src/core/smtp/MCSMTPSession.cc
@@ -24,6 +24,7 @@ void SMTPSession::init()
mPort = 0;
mUsername = NULL;
mPassword = NULL;
+ mOAuth2Token = NULL;
mAuthType = AuthTypeSASLNone;
mConnectionType = ConnectionTypeClear;
mTimeout = 30;
@@ -50,6 +51,7 @@ SMTPSession::~SMTPSession()
MC_SAFE_RELEASE(mHostname);
MC_SAFE_RELEASE(mUsername);
MC_SAFE_RELEASE(mPassword);
+ MC_SAFE_RELEASE(mOAuth2Token);
}
void SMTPSession::setHostname(String * hostname)
@@ -92,6 +94,16 @@ String * SMTPSession::password()
return mPassword;
}
+void SMTPSession::setOAuth2Token(String * token)
+{
+ MC_SAFE_REPLACE_COPY(String, mOAuth2Token, token);
+}
+
+String * SMTPSession::OAuth2Token()
+{
+ return mOAuth2Token;
+}
+
void SMTPSession::setAuthType(AuthType authType)
{
mAuthType = authType;
@@ -404,86 +416,90 @@ void SMTPSession::login(ErrorCode * pError)
switch (authType()) {
case 0:
default:
- r = mailesmtp_auth_sasl(mSmtp, "PLAIN",
- MCUTF8(mHostname),
- NULL,
- NULL,
- MCUTF8(mUsername), MCUTF8(mUsername),
- MCUTF8(mPassword), NULL);
- break;
-
+ r = mailesmtp_auth_sasl(mSmtp, "PLAIN",
+ MCUTF8(mHostname),
+ NULL,
+ NULL,
+ MCUTF8(mUsername), MCUTF8(mUsername),
+ MCUTF8(mPassword), NULL);
+ break;
+
case AuthTypeSASLCRAMMD5:
- r = mailesmtp_auth_sasl(mSmtp, "CRAM-MD5",
- MCUTF8(mHostname),
- NULL,
- NULL,
- MCUTF8(mUsername), MCUTF8(mUsername),
- MCUTF8(mPassword), NULL);
- break;
-
+ r = mailesmtp_auth_sasl(mSmtp, "CRAM-MD5",
+ MCUTF8(mHostname),
+ NULL,
+ NULL,
+ MCUTF8(mUsername), MCUTF8(mUsername),
+ MCUTF8(mPassword), NULL);
+ break;
+
case AuthTypeSASLPlain:
- r = mailesmtp_auth_sasl(mSmtp, "PLAIN",
- MCUTF8(mHostname),
- NULL,
- NULL,
- MCUTF8(mUsername), MCUTF8(mUsername),
- MCUTF8(mPassword), NULL);
- break;
-
+ r = mailesmtp_auth_sasl(mSmtp, "PLAIN",
+ MCUTF8(mHostname),
+ NULL,
+ NULL,
+ MCUTF8(mUsername), MCUTF8(mUsername),
+ MCUTF8(mPassword), NULL);
+ break;
+
case AuthTypeSASLGSSAPI:
// needs to be tested
- r = mailesmtp_auth_sasl(mSmtp, "GSSAPI",
- MCUTF8(mHostname),
- NULL,
- NULL,
- MCUTF8(mUsername), MCUTF8(mUsername),
- MCUTF8(mPassword), NULL);
- break;
-
+ r = mailesmtp_auth_sasl(mSmtp, "GSSAPI",
+ MCUTF8(mHostname),
+ NULL,
+ NULL,
+ MCUTF8(mUsername), MCUTF8(mUsername),
+ MCUTF8(mPassword), NULL);
+ break;
+
case AuthTypeSASLDIGESTMD5:
- r = mailesmtp_auth_sasl(mSmtp, "DIGEST-MD5",
- MCUTF8(mHostname),
- NULL,
- NULL,
- MCUTF8(mUsername), MCUTF8(mUsername),
- MCUTF8(mPassword), NULL);
- break;
-
+ r = mailesmtp_auth_sasl(mSmtp, "DIGEST-MD5",
+ MCUTF8(mHostname),
+ NULL,
+ NULL,
+ MCUTF8(mUsername), MCUTF8(mUsername),
+ MCUTF8(mPassword), NULL);
+ break;
+
case AuthTypeSASLLogin:
- r = mailesmtp_auth_sasl(mSmtp, "LOGIN",
- MCUTF8(mHostname),
- NULL,
- NULL,
- MCUTF8(mUsername), MCUTF8(mUsername),
- MCUTF8(mPassword), NULL);
- break;
-
+ r = mailesmtp_auth_sasl(mSmtp, "LOGIN",
+ MCUTF8(mHostname),
+ NULL,
+ NULL,
+ MCUTF8(mUsername), MCUTF8(mUsername),
+ MCUTF8(mPassword), NULL);
+ break;
+
case AuthTypeSASLSRP:
- r = mailesmtp_auth_sasl(mSmtp, "SRP",
- MCUTF8(mHostname),
- NULL,
- NULL,
- MCUTF8(mUsername), MCUTF8(mUsername),
- MCUTF8(mPassword), NULL);
- break;
-
+ r = mailesmtp_auth_sasl(mSmtp, "SRP",
+ MCUTF8(mHostname),
+ NULL,
+ NULL,
+ MCUTF8(mUsername), MCUTF8(mUsername),
+ MCUTF8(mPassword), NULL);
+ break;
+
case AuthTypeSASLNTLM:
- r = mailesmtp_auth_sasl(mSmtp, "NTLM",
- MCUTF8(mHostname),
- NULL,
- NULL,
- MCUTF8(mUsername), MCUTF8(mUsername),
- MCUTF8(mPassword), NULL /* realm */);
- break;
-
+ r = mailesmtp_auth_sasl(mSmtp, "NTLM",
+ MCUTF8(mHostname),
+ NULL,
+ NULL,
+ MCUTF8(mUsername), MCUTF8(mUsername),
+ MCUTF8(mPassword), NULL /* realm */);
+ break;
+
case AuthTypeSASLKerberosV4:
- r = mailesmtp_auth_sasl(mSmtp, "KERBEROS_V4",
- MCUTF8(mHostname),
- NULL,
- NULL,
- MCUTF8(mUsername), MCUTF8(mUsername),
- MCUTF8(mPassword), NULL /* realm */);
- break;
+ r = mailesmtp_auth_sasl(mSmtp, "KERBEROS_V4",
+ MCUTF8(mHostname),
+ NULL,
+ NULL,
+ MCUTF8(mUsername), MCUTF8(mUsername),
+ MCUTF8(mPassword), NULL /* realm */);
+ break;
+
+ case AuthTypeXOAuth2:
+ r = mailsmtp_oauth2_authenticate(mSmtp, MCUTF8(mUsername), MCUTF8(mOAuth2Token));
+ break;
}
if (r == MAILSMTP_ERROR_STREAM) {
* pError = ErrorConnection;
diff --git a/src/core/smtp/MCSMTPSession.h b/src/core/smtp/MCSMTPSession.h
index 491ecb07..3d066a6c 100644
--- a/src/core/smtp/MCSMTPSession.h
+++ b/src/core/smtp/MCSMTPSession.h
@@ -30,6 +30,11 @@ namespace mailcore {
virtual void setPassword(String * password);
virtual String * password();
+ // To authenticate using OAuth2, username and oauth2token should be set.
+ // auth type to use is AuthTypeOAuth2.
+ virtual void setOAuth2Token(String * token);
+ virtual String * OAuth2Token();
+
virtual void setAuthType(AuthType authType);
virtual AuthType authType();
@@ -62,6 +67,7 @@ namespace mailcore {
unsigned int mPort;
String * mUsername;
String * mPassword;
+ String * mOAuth2Token;
AuthType mAuthType;
ConnectionType mConnectionType;
time_t mTimeout;
diff --git a/src/objc/abstract/MCOAbstractMessage.h b/src/objc/abstract/MCOAbstractMessage.h
index bf442659..1e6dd2e6 100644
--- a/src/objc/abstract/MCOAbstractMessage.h
+++ b/src/objc/abstract/MCOAbstractMessage.h
@@ -15,7 +15,7 @@
@class MCOMessageHeader;
@class MCOAbstractPart;
-@interface MCOAbstractMessage : NSObject
+@interface MCOAbstractMessage : NSObject <NSCopying>
/** Header of the message. */
@property (nonatomic, strong) MCOMessageHeader * header;
diff --git a/src/objc/abstract/MCOAbstractMessage.mm b/src/objc/abstract/MCOAbstractMessage.mm
index 05530845..637d6172 100644
--- a/src/objc/abstract/MCOAbstractMessage.mm
+++ b/src/objc/abstract/MCOAbstractMessage.mm
@@ -44,6 +44,14 @@
return self;
}
+- (id) copyWithZone:(NSZone *)zone
+{
+ nativeType * nativeObject = (nativeType *) [self mco_mcObject]->copy();
+ id result = [[self class] mco_objectWithMCObject:nativeObject];
+ MC_SAFE_RELEASE(nativeObject);
+ return [result retain];
+}
+
- (void) dealloc
{
MC_SAFE_RELEASE(_message);
diff --git a/src/objc/abstract/MCOAbstractPart.h b/src/objc/abstract/MCOAbstractPart.h
index a3ab44f6..07e44920 100644
--- a/src/objc/abstract/MCOAbstractPart.h
+++ b/src/objc/abstract/MCOAbstractPart.h
@@ -37,7 +37,7 @@ typedef enum {
MCOPartTypeMultipartAlternative,
} MCOPartType;
-@interface MCOAbstractPart : NSObject
+@interface MCOAbstractPart : NSObject <NSCopying>
/** Returns type of the part (single / message part / multipart/mixed,
multipart/related, multipart/alternative). See MCOPartType.*/
diff --git a/src/objc/abstract/MCOAbstractPart.mm b/src/objc/abstract/MCOAbstractPart.mm
index 7a37dcaf..459ae8be 100644
--- a/src/objc/abstract/MCOAbstractPart.mm
+++ b/src/objc/abstract/MCOAbstractPart.mm
@@ -49,6 +49,14 @@
[super dealloc];
}
+- (id) copyWithZone:(NSZone *)zone
+{
+ nativeType * nativeObject = (nativeType *) [self mco_mcObject]->copy();
+ id result = [[self class] mco_objectWithMCObject:nativeObject];
+ MC_SAFE_RELEASE(nativeObject);
+ return [result retain];
+}
+
- (NSString *) description
{
return MCO_OBJC_BRIDGE_GET(description);
diff --git a/src/objc/abstract/MCOConstants.h b/src/objc/abstract/MCOConstants.h
index 5ec21422..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.*/
diff --git a/src/objc/imap/MCOIMAPMessage.h b/src/objc/imap/MCOIMAPMessage.h
index 06e437d8..7de1fd69 100644
--- a/src/objc/imap/MCOIMAPMessage.h
+++ b/src/objc/imap/MCOIMAPMessage.h
@@ -29,7 +29,7 @@
@protocol MCOHTMLRendererIMAPDelegate;
-@interface MCOIMAPMessage : MCOAbstractMessage <NSCopying>
+@interface MCOIMAPMessage : MCOAbstractMessage
/** IMAP UID of the message. */
@property (nonatomic, assign) uint32_t uid;
diff --git a/src/objc/imap/MCOIMAPMessage.mm b/src/objc/imap/MCOIMAPMessage.mm
index c9bfcbb9..2dc71217 100644
--- a/src/objc/imap/MCOIMAPMessage.mm
+++ b/src/objc/imap/MCOIMAPMessage.mm
@@ -27,14 +27,6 @@
MCORegisterClass(self, &typeid(nativeType));
}
-- (id) copyWithZone:(NSZone *)zone
-{
- nativeType * nativeObject = (nativeType *) [self mco_mcObject]->copy();
- id result = [[self class] mco_objectWithMCObject:nativeObject];
- MC_SAFE_RELEASE(nativeObject);
- return [result retain];
-}
-
+ (NSObject *) mco_objectWithMCObject:(mailcore::Object *)object
{
mailcore::IMAPMessage * msg = (mailcore::IMAPMessage *) object;
diff --git a/src/objc/imap/MCOIMAPMessagePart.h b/src/objc/imap/MCOIMAPMessagePart.h
index b602d93a..1e2be559 100644
--- a/src/objc/imap/MCOIMAPMessagePart.h
+++ b/src/objc/imap/MCOIMAPMessagePart.h
@@ -14,7 +14,7 @@
#import <MailCore/MCOAbstractMessagePart.h>
-@interface MCOIMAPMessagePart : MCOAbstractMessagePart <NSCopying>
+@interface MCOIMAPMessagePart : MCOAbstractMessagePart
/** A part identifier is of the form 1.2.1*/
@property (nonatomic, copy) NSString * partID;
diff --git a/src/objc/imap/MCOIMAPMessagePart.mm b/src/objc/imap/MCOIMAPMessagePart.mm
index 827636b3..05a7e102 100644
--- a/src/objc/imap/MCOIMAPMessagePart.mm
+++ b/src/objc/imap/MCOIMAPMessagePart.mm
@@ -22,14 +22,6 @@
MCORegisterClass(self, &typeid(nativeType));
}
-- (id) copyWithZone:(NSZone *)zone
-{
- nativeType * nativeObject = (nativeType *) [self mco_mcObject]->copy();
- id result = [[self class] mco_objectWithMCObject:nativeObject];
- MC_SAFE_RELEASE(nativeObject);
- return [result retain];
-}
-
+ (NSObject *) mco_objectWithMCObject:(mailcore::Object *)object
{
mailcore::IMAPMessagePart * part = (mailcore::IMAPMessagePart *) object;
diff --git a/src/objc/imap/MCOIMAPMultipart.h b/src/objc/imap/MCOIMAPMultipart.h
index 0e0bb0eb..408b6593 100644
--- a/src/objc/imap/MCOIMAPMultipart.h
+++ b/src/objc/imap/MCOIMAPMultipart.h
@@ -14,7 +14,7 @@
#import <MailCore/MCOAbstractMultipart.h>
-@interface MCOIMAPMultipart : MCOAbstractMultipart <NSCopying>
+@interface MCOIMAPMultipart : MCOAbstractMultipart
/** A part identifier looks like 1.2.1 */
@property (nonatomic, copy) NSString * partID;
diff --git a/src/objc/imap/MCOIMAPMultipart.mm b/src/objc/imap/MCOIMAPMultipart.mm
index fdfe4e7a..c3761ade 100644
--- a/src/objc/imap/MCOIMAPMultipart.mm
+++ b/src/objc/imap/MCOIMAPMultipart.mm
@@ -22,14 +22,6 @@
MCORegisterClass(self, &typeid(nativeType));
}
-- (id) copyWithZone:(NSZone *)zone
-{
- nativeType * nativeObject = (nativeType *) [self mco_mcObject]->copy();
- id result = [[self class] mco_objectWithMCObject:nativeObject];
- MC_SAFE_RELEASE(nativeObject);
- return [result retain];
-}
-
+ (NSObject *) mco_objectWithMCObject:(mailcore::Object *)object
{
mailcore::IMAPMultipart * part = (mailcore::IMAPMultipart *) object;
diff --git a/src/objc/imap/MCOIMAPPart.h b/src/objc/imap/MCOIMAPPart.h
index 029135bf..f7bec632 100644
--- a/src/objc/imap/MCOIMAPPart.h
+++ b/src/objc/imap/MCOIMAPPart.h
@@ -16,7 +16,7 @@
/** Represents a single IMAP message part */
-@interface MCOIMAPPart : MCOAbstractPart <NSCopying>
+@interface MCOIMAPPart : MCOAbstractPart
/** A part identifier looks like 1.2.1 */
@property (nonatomic, copy) NSString * partID;
diff --git a/src/objc/imap/MCOIMAPPart.mm b/src/objc/imap/MCOIMAPPart.mm
index 80b86d23..80fc2f1e 100644
--- a/src/objc/imap/MCOIMAPPart.mm
+++ b/src/objc/imap/MCOIMAPPart.mm
@@ -22,14 +22,6 @@
MCORegisterClass(self, &typeid(nativeType));
}
-- (id) copyWithZone:(NSZone *)zone
-{
- nativeType * nativeObject = (nativeType *) [self mco_mcObject]->copy();
- id result = [[self class] mco_objectWithMCObject:nativeObject];
- MC_SAFE_RELEASE(nativeObject);
- return [result retain];
-}
-
+ (NSObject *) mco_objectWithMCObject:(mailcore::Object *)object
{
mailcore::IMAPPart * part = (mailcore::IMAPPart *) object;
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 43f366e6..1dff0f1f 100644
--- a/src/objc/imap/MCOIMAPSession.mm
+++ b/src/objc/imap/MCOIMAPSession.mm
@@ -35,7 +35,7 @@ public:
mSession = session;
}
- virtual void log(void * context, void * sender, ConnectionLogType logType, Data * data)
+ virtual void log(void * sender, ConnectionLogType logType, Data * data)
{
[mSession _logWithSender:sender connectionType:(MCOConnectionLogType)logType data:MCO_TO_OBJC(data)];
}
@@ -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)
diff --git a/src/objc/pop/MCOPOPSession.mm b/src/objc/pop/MCOPOPSession.mm
index 42c76646..fb48cb1e 100644
--- a/src/objc/pop/MCOPOPSession.mm
+++ b/src/objc/pop/MCOPOPSession.mm
@@ -31,7 +31,7 @@ public:
mSession = session;
}
- virtual void log(void * context, void * sender, ConnectionLogType logType, Data * data)
+ virtual void log(void * sender, ConnectionLogType logType, Data * data)
{
[mSession _logWithSender:sender connectionType:(MCOConnectionLogType)logType data:MCO_TO_OBJC(data)];
}
diff --git a/src/objc/provider/MCONetService.h b/src/objc/provider/MCONetService.h
index 482ae4dc..eb198e5e 100644
--- a/src/objc/provider/MCONetService.h
+++ b/src/objc/provider/MCONetService.h
@@ -13,7 +13,7 @@
This class provides a specific way to access a given service
*/
-@interface MCONetService : NSObject
+@interface MCONetService : NSObject <NSCopying>
/**
The hostname of the server. [MCONetService hostnameWithEmail:] is recommended
diff --git a/src/objc/provider/MCONetService.mm b/src/objc/provider/MCONetService.mm
index 0a2c0c33..260cb45f 100644
--- a/src/objc/provider/MCONetService.mm
+++ b/src/objc/provider/MCONetService.mm
@@ -14,50 +14,58 @@
#import "NSObject+MCO.h"
@implementation MCONetService {
- mailcore::NetService *_netService;
+ mailcore::NetService *_netService;
}
#define nativeType mailcore::NetService
+ (void) load
{
- MCORegisterClass( self, &typeid(nativeType) );
+ MCORegisterClass( self, &typeid(nativeType) );
}
- (mailcore::Object *) mco_mcObject
{
- return _netService;
+ return _netService;
}
+ (NSObject *) mco_objectWithMCObject:(mailcore::Object *)object
{
- mailcore::NetService *netService = (mailcore::NetService *)object;
- return [[self alloc] initWithNetService:netService];
+ mailcore::NetService *netService = (mailcore::NetService *)object;
+ return [[[self alloc] initWithNetService:netService] autorelease];
}
+ (MCONetService *) serviceWithInfo:(NSDictionary *)info
{
- return [[[self alloc] initWithInfo:info] autorelease];
+ return [[[self alloc] initWithInfo:info] autorelease];
}
- (id) initWithInfo:(NSDictionary *)info
{
- self = [super init];
-
- _netService = mailcore::NetService::serviceWithInfo(info.mco_mcHashMap);
- _netService->retain();
-
- return self;
+ self = [super init];
+
+ _netService = mailcore::NetService::serviceWithInfo(info.mco_mcHashMap);
+ _netService->retain();
+
+ return self;
}
- (id) initWithNetService:(mailcore::NetService *)netService
{
- self = [super init];
-
- _netService = netService;
- _netService->retain();
-
- return self;
+ self = [super init];
+
+ _netService = netService;
+ _netService->retain();
+
+ return self;
+}
+
+- (id) copyWithZone:(NSZone *)zone
+{
+ nativeType * nativeObject = (nativeType *) [self mco_mcObject]->copy();
+ id result = [[self class] mco_objectWithMCObject:nativeObject];
+ MC_SAFE_RELEASE(nativeObject);
+ return [result retain];
}
MCO_OBJC_SYNTHESIZE_STRING(setHostname, hostname)
@@ -66,20 +74,20 @@ MCO_OBJC_SYNTHESIZE_SCALAR(MCOConnectionType, mailcore::ConnectionType, setConne
- (NSDictionary *) info
{
- return [NSDictionary mco_dictionaryWithMCHashMap:_netService->info()];
+ return [NSDictionary mco_dictionaryWithMCHashMap:_netService->info()];
}
- (NSString *) hostnameWithEmail:(NSString *)email
{
- NSString *result = nil;
- NSArray *components = [email componentsSeparatedByString:@"@"];
- if (components.count == 0) {
- return self.hostname;
- }
- else {
- result = [self.hostname stringByReplacingOccurrencesOfString:@"{domain}" withString:[components lastObject]];
- }
- return [NSString mco_stringWithMCString:_netService->normalizedHostnameWithEmail(email.mco_mcString)];
+ NSString *result = nil;
+ NSArray *components = [email componentsSeparatedByString:@"@"];
+ if (components.count == 0) {
+ return self.hostname;
+ }
+ else {
+ result = [self.hostname stringByReplacingOccurrencesOfString:@"{domain}" withString:[components lastObject]];
+ }
+ return [NSString mco_stringWithMCString:_netService->normalizedHostnameWithEmail(email.mco_mcString)];
}
@end \ No newline at end of file
diff --git a/src/objc/rfc822/MCOAttachment.h b/src/objc/rfc822/MCOAttachment.h
index 50a2d1a7..560f4590 100644
--- a/src/objc/rfc822/MCOAttachment.h
+++ b/src/objc/rfc822/MCOAttachment.h
@@ -16,7 +16,7 @@
It can either parsed from RFC 822 message data or created to build a message.*/
-@interface MCOAttachment : MCOAbstractPart <NSCopying>
+@interface MCOAttachment : MCOAbstractPart
/** Returns a MIME type for a filename.*/
+ (NSString *) mimeTypeForFilename:(NSString *)filename;
diff --git a/src/objc/rfc822/MCOAttachment.mm b/src/objc/rfc822/MCOAttachment.mm
index 423ac0df..5b20e583 100644
--- a/src/objc/rfc822/MCOAttachment.mm
+++ b/src/objc/rfc822/MCOAttachment.mm
@@ -26,14 +26,6 @@
MCORegisterClass(self, &typeid(nativeType));
}
-- (id) copyWithZone:(NSZone *)zone
-{
- nativeType * nativeObject = (nativeType *) [self mco_mcObject]->copy();
- id result = [[self class] mco_objectWithMCObject:nativeObject];
- MC_SAFE_RELEASE(nativeObject);
- return [result retain];
-}
-
+ (NSObject *) mco_objectWithMCObject:(mailcore::Object *)object
{
mailcore::Attachment * attachment = (mailcore::Attachment *) object;
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 <MCOHTMLRendererDelegate>)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..5a009bb7 100644
--- a/src/objc/rfc822/MCOMessageParser.h
+++ b/src/objc/rfc822/MCOMessageParser.h
@@ -20,7 +20,7 @@
@protocol MCOHTMLRendererDelegate;
-@interface MCOMessageParser : MCOAbstractMessage <NSCopying>
+@interface MCOMessageParser : MCOAbstractMessage
/** returns a parsed message from the given RFC 822 data.*/
+ (MCOMessageParser *) messageParserWithData:(NSData *)data;
@@ -38,6 +38,16 @@
/** HTML rendering of the message to be displayed in a web view. delegate can be nil.*/
- (NSString *) htmlRenderingWithDelegate:(id <MCOHTMLRendererDelegate>)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..8e3f1261 100644
--- a/src/objc/rfc822/MCOMessageParser.mm
+++ b/src/objc/rfc822/MCOMessageParser.mm
@@ -26,14 +26,6 @@
MCORegisterClass(self, &typeid(nativeType));
}
-- (id) copyWithZone:(NSZone *)zone
-{
- nativeType * nativeObject = (nativeType *) [self mco_mcObject]->copy();
- id result = [[self class] mco_objectWithMCObject:nativeObject];
- MC_SAFE_RELEASE(nativeObject);
- return [result retain];
-}
-
+ (id) mco_objectWithMCObject:(mailcore::Object *)object
{
mailcore::MessageParser * msg = (mailcore::MessageParser *) object;
@@ -77,4 +69,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
diff --git a/src/objc/rfc822/MCOMessagePart.mm b/src/objc/rfc822/MCOMessagePart.mm
index f1535049..4ed4a6d7 100644
--- a/src/objc/rfc822/MCOMessagePart.mm
+++ b/src/objc/rfc822/MCOMessagePart.mm
@@ -22,14 +22,6 @@
MCORegisterClass(self, &typeid(nativeType));
}
-- (id) copyWithZone:(NSZone *)zone
-{
- nativeType * nativeObject = (nativeType *) [self mco_mcObject]->copy();
- id result = [[self class] mco_objectWithMCObject:nativeObject];
- MC_SAFE_RELEASE(nativeObject);
- return [result retain];
-}
-
+ (id) mco_objectWithMCObject:(mailcore::Object *)object
{
mailcore::MessagePart * part = (mailcore::MessagePart *) object;
diff --git a/src/objc/rfc822/MCOMultipart.h b/src/objc/rfc822/MCOMultipart.h
index e45d4a0c..a730b8a4 100644
--- a/src/objc/rfc822/MCOMultipart.h
+++ b/src/objc/rfc822/MCOMultipart.h
@@ -14,7 +14,7 @@
/** Multipart parsed from RFC 822 message data. */
-@interface MCOMultipart : MCOAbstractMultipart <NSCopying>
+@interface MCOMultipart : MCOAbstractMultipart
@end
diff --git a/src/objc/rfc822/MCOMultipart.mm b/src/objc/rfc822/MCOMultipart.mm
index 2267f775..78fa1a98 100644
--- a/src/objc/rfc822/MCOMultipart.mm
+++ b/src/objc/rfc822/MCOMultipart.mm
@@ -22,14 +22,6 @@
MCORegisterClass(self, &typeid(nativeType));
}
-- (id) copyWithZone:(NSZone *)zone
-{
- nativeType * nativeObject = (nativeType *) [self mco_mcObject]->copy();
- id result = [[self class] mco_objectWithMCObject:nativeObject];
- MC_SAFE_RELEASE(nativeObject);
- return [result retain];
-}
-
+ (id) mco_objectWithMCObject:(mailcore::Object *)object
{
mailcore::Attachment * attachment = (mailcore::Attachment *) object;
diff --git a/src/objc/smtp/MCOSMTPSession.h b/src/objc/smtp/MCOSMTPSession.h
index 44d37942..bb7c5f57 100644
--- a/src/objc/smtp/MCOSMTPSession.h
+++ b/src/objc/smtp/MCOSMTPSession.h
@@ -39,6 +39,9 @@
/** This is the password of the account. */
@property (nonatomic, copy) NSString * password;
+/** This is the OAuth2 token. */
+@property (nonatomic, copy) NSString *OAuth2Token;
+
/**
This is the authentication type to use to connect.
`MCOAuthTypeSASLNone` means that it uses the clear-text is used (and is the default).
diff --git a/src/objc/smtp/MCOSMTPSession.mm b/src/objc/smtp/MCOSMTPSession.mm
index 1538d53a..c9f9f0fc 100644
--- a/src/objc/smtp/MCOSMTPSession.mm
+++ b/src/objc/smtp/MCOSMTPSession.mm
@@ -32,7 +32,7 @@ public:
mSession = session;
}
- virtual void log(void * context, void * sender, ConnectionLogType logType, Data * data)
+ virtual void log(void * sender, ConnectionLogType logType, Data * data)
{
[mSession _logWithSender:sender connectionType:(MCOConnectionLogType)logType data:MCO_TO_OBJC(data)];
}
@@ -74,6 +74,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)
diff --git a/src/objc/utils/NSError+MCO.mm b/src/objc/utils/NSError+MCO.mm
index c9f4f998..47abf809 100644
--- a/src/objc/utils/NSError+MCO.mm
+++ b/src/objc/utils/NSError+MCO.mm
@@ -7,15 +7,59 @@
#import "MCOConstants.h"
+static NSString * MCOLocalizedDescriptionTable[] = {
+ @"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 */
+ @"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) {
return nil;
}
-
+
+ NSMutableDictionary *userInfo = [[NSMutableDictionary alloc] init];
+ 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
- userInfo:nil];
+ userInfo:userInfo];
return error;
}
-@end \ No newline at end of file
+@end