aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--build-mac/mailcore2.xcodeproj/project.pbxproj22
-rw-r--r--src/async/MCAsync.h14
-rw-r--r--src/async/smtp/MCAsyncSMTP.h16
-rw-r--r--src/async/smtp/MCSMTPAsyncSession.cc43
-rw-r--r--src/async/smtp/MCSMTPAsyncSession.h13
-rw-r--r--src/async/smtp/MCSMTPOperation.cpp85
-rw-r--r--src/async/smtp/MCSMTPOperation.h46
-rw-r--r--src/async/smtp/MCSMTPOperationCallback.h22
-rw-r--r--src/async/smtp/MCSMTPSendWithBuilderOperation.cc34
-rw-r--r--src/async/smtp/MCSMTPSendWithBuilderOperation.h24
-rw-r--r--src/async/smtp/MCSMTPSendWithDataOperation.cc33
-rw-r--r--src/async/smtp/MCSMTPSendWithDataOperation.h21
-rw-r--r--src/async/smtp/MCSMTPSendWithRecipientOperation.cc62
-rw-r--r--src/async/smtp/MCSMTPSendWithRecipientOperation.h31
-rw-r--r--src/core/abstract/MCMessageHeader.cc2
-rw-r--r--src/core/basetypes/MCAutoreleasePool.cc3
-rw-r--r--src/core/basetypes/MCLog.cc34
-rw-r--r--src/mailcore.h1
-rw-r--r--tests/main.mm66
19 files changed, 530 insertions, 42 deletions
diff --git a/build-mac/mailcore2.xcodeproj/project.pbxproj b/build-mac/mailcore2.xcodeproj/project.pbxproj
index 13472734..76c3d3f5 100644
--- a/build-mac/mailcore2.xcodeproj/project.pbxproj
+++ b/build-mac/mailcore2.xcodeproj/project.pbxproj
@@ -107,6 +107,11 @@
C64EA7A5169F2A6100778456 /* mailcore.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = C64EA7A4169F2A3E00778456 /* mailcore.h */; };
C64EA7AB16A00AF600778456 /* main.mm in Sources */ = {isa = PBXBuildFile; fileRef = C64EA7AA16A00AF600778456 /* main.mm */; };
C64EA7B116A00BBB00778456 /* CoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C64EA7B016A00BBB00778456 /* CoreServices.framework */; };
+ C64EA7DA16A1386600778456 /* MCSMTPOperation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C64EA7D816A1386500778456 /* MCSMTPOperation.cpp */; };
+ C64EA7DC16A13A4C00778456 /* MCSMTPOperation.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = C64EA7D916A1386600778456 /* MCSMTPOperation.h */; };
+ C64EA7E516A14A5400778456 /* MCAsync.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = C64EA7E416A14A4500778456 /* MCAsync.h */; };
+ C64EA7E616A14A6A00778456 /* MCAsyncSMTP.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = C64EA7E316A149EF00778456 /* MCAsyncSMTP.h */; };
+ C64EA7E716A14A7400778456 /* MCSMTPOperationCallback.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = C64EA7E116A1425400778456 /* MCSMTPOperationCallback.h */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -127,13 +132,15 @@
dstSubfolderSpec = 16;
files = (
C64EA74C169E859600778456 /* IMAPAsyncSession.h in CopyFiles */,
- C64EA74D169E859600778456 /* MCSMTPAsyncSession.h in CopyFiles */,
C64EA74E169E859600778456 /* MCAbstract.h in CopyFiles */,
C64EA74F169E859600778456 /* MCAbstractMessage.h in CopyFiles */,
+ C64EA7E516A14A5400778456 /* MCAsync.h in CopyFiles */,
C64EA750169E859600778456 /* MCAbstractMessagePart.h in CopyFiles */,
C64EA751169E859600778456 /* MCAbstractMultipart.h in CopyFiles */,
C64EA752169E859600778456 /* MCAbstractPart.h in CopyFiles */,
C64EA7A5169F2A6100778456 /* mailcore.h in CopyFiles */,
+ C64EA7E716A14A7400778456 /* MCSMTPOperationCallback.h in CopyFiles */,
+ C64EA7E616A14A6A00778456 /* MCAsyncSMTP.h in CopyFiles */,
C64EA753169E859600778456 /* MCAddress.h in CopyFiles */,
C64EA754169E859600778456 /* MCMessageConstants.h in CopyFiles */,
C64EA755169E859600778456 /* MCMessageHeader.h in CopyFiles */,
@@ -172,6 +179,8 @@
C64EA775169E859600778456 /* MCPOPProgressCallback.h in CopyFiles */,
C64EA776169E859600778456 /* MCPOPSession.h in CopyFiles */,
C64EA777169E859600778456 /* MCAttachment.h in CopyFiles */,
+ C64EA7DC16A13A4C00778456 /* MCSMTPOperation.h in CopyFiles */,
+ C64EA74D169E859600778456 /* MCSMTPAsyncSession.h in CopyFiles */,
C64EA778169E859600778456 /* MCMessageBuilder.h in CopyFiles */,
C64EA779169E859600778456 /* MCMessageParser.h in CopyFiles */,
C64EA77A169E859600778456 /* MCMessagePart.h in CopyFiles */,
@@ -299,6 +308,11 @@
C64EA7A4169F2A3E00778456 /* mailcore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mailcore.h; sourceTree = "<group>"; };
C64EA7AA16A00AF600778456 /* main.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = main.mm; sourceTree = "<group>"; };
C64EA7B016A00BBB00778456 /* CoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreServices.framework; path = System/Library/Frameworks/CoreServices.framework; sourceTree = SDKROOT; };
+ C64EA7D816A1386500778456 /* MCSMTPOperation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MCSMTPOperation.cpp; sourceTree = "<group>"; };
+ C64EA7D916A1386600778456 /* MCSMTPOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCSMTPOperation.h; sourceTree = "<group>"; };
+ C64EA7E116A1425400778456 /* MCSMTPOperationCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCSMTPOperationCallback.h; sourceTree = "<group>"; };
+ C64EA7E316A149EF00778456 /* MCAsyncSMTP.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCAsyncSMTP.h; sourceTree = "<group>"; };
+ C64EA7E416A14A4500778456 /* MCAsync.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCAsync.h; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -359,6 +373,7 @@
C64EA68B169E847800778456 /* imap */,
C64EA68D169E847800778456 /* pop */,
C64EA68E169E847800778456 /* smtp */,
+ C64EA7E416A14A4500778456 /* MCAsync.h */,
);
path = async;
sourceTree = "<group>";
@@ -389,6 +404,10 @@
C64EA79D169F29A700778456 /* MCSMTPSendWithDataOperation.h */,
C64EA79F169F29D900778456 /* MCSMTPSendWithBuilderOperation.cc */,
C64EA7A0169F29D900778456 /* MCSMTPSendWithBuilderOperation.h */,
+ C64EA7D816A1386500778456 /* MCSMTPOperation.cpp */,
+ C64EA7D916A1386600778456 /* MCSMTPOperation.h */,
+ C64EA7E116A1425400778456 /* MCSMTPOperationCallback.h */,
+ C64EA7E316A149EF00778456 /* MCAsyncSMTP.h */,
);
path = smtp;
sourceTree = "<group>";
@@ -683,6 +702,7 @@
C64EA787169F252C00778456 /* MCSMTPSendWithRecipientOperation.cc in Sources */,
C64EA79E169F29A700778456 /* MCSMTPSendWithDataOperation.cc in Sources */,
C64EA7A1169F29D900778456 /* MCSMTPSendWithBuilderOperation.cc in Sources */,
+ C64EA7DA16A1386600778456 /* MCSMTPOperation.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/src/async/MCAsync.h b/src/async/MCAsync.h
new file mode 100644
index 00000000..4fa1428c
--- /dev/null
+++ b/src/async/MCAsync.h
@@ -0,0 +1,14 @@
+//
+// MCAsync.h
+// mailcore2
+//
+// Created by DINH Viêt Hoà on 1/11/13.
+// Copyright (c) 2013 MailCore. All rights reserved.
+//
+
+#ifndef mailcore2_MCAsync_h
+#define mailcore2_MCAsync_h
+
+#include <mailcore/MCAsyncSMTP.h>
+
+#endif
diff --git a/src/async/smtp/MCAsyncSMTP.h b/src/async/smtp/MCAsyncSMTP.h
new file mode 100644
index 00000000..5d5e8282
--- /dev/null
+++ b/src/async/smtp/MCAsyncSMTP.h
@@ -0,0 +1,16 @@
+//
+// MCAsyncSMTP.h
+// mailcore2
+//
+// Created by DINH Viêt Hoà on 1/11/13.
+// Copyright (c) 2013 MailCore. All rights reserved.
+//
+
+#ifndef mailcore2_MCAsyncSMTP_h
+#define mailcore2_MCAsyncSMTP_h
+
+#include <mailcore/MCSMTPAsyncSession.h>
+#include <mailcore/MCSMTPOperation.h>
+#include <mailcore/MCSMTPOperationCallback.h>
+
+#endif
diff --git a/src/async/smtp/MCSMTPAsyncSession.cc b/src/async/smtp/MCSMTPAsyncSession.cc
index 9798fc0c..e7ddebb7 100644
--- a/src/async/smtp/MCSMTPAsyncSession.cc
+++ b/src/async/smtp/MCSMTPAsyncSession.cc
@@ -4,6 +4,7 @@
#include "MCSMTPSendWithRecipientOperation.h"
#include "MCSMTPSendWithDataOperation.h"
#include "MCSMTPSendWithBuilderOperation.h"
+#include "MCSMTPOperation.h"
using namespace mailcore;
@@ -15,13 +16,12 @@ SMTPAsyncSession::SMTPAsyncSession()
SMTPAsyncSession::~SMTPAsyncSession()
{
- mQueue->release();
- mSession->release();
-}
-
-String * SMTPAsyncSession::className()
-{
- return MCSTR("SMTPAsyncSession");
+ MC_SAFE_RELEASE(mHostname);
+ MC_SAFE_RELEASE(mUsername);
+ MC_SAFE_RELEASE(mPassword);
+
+ MC_SAFE_RELEASE(mQueue);
+ MC_SAFE_RELEASE(mSession);
}
void SMTPAsyncSession::setHostname(String * hostname)
@@ -114,32 +114,39 @@ bool SMTPAsyncSession::useHeloIPEnabled()
return mSession->useHeloIPEnabled();
}
-SMTPOperation * sendMessage(Address * from, Array * recipients, Data * messageData)
+void SMTPAsyncSession::runOperation(SMTPOperation * operation)
+{
+ mQueue->addOperation(operation);
+}
+
+SMTPSession * SMTPAsyncSession::SMTPAsyncSession::session()
+{
+ return mSession;
+}
+
+SMTPOperation * SMTPAsyncSession::sendMessageOperationWithFromAndRecipient(Address * from, Array * recipients, Data * messageData)
{
-#if 0
SMTPSendWithRecipientOperation * op = new SMTPSendWithRecipientOperation();
+ op->setSession(this);
op->setFrom(from);
op->setRecipients(recipients);
- op->messageData(messageData);
+ op->setMessageData(messageData);
return (SMTPOperation *) op->autorelease();
-#endif
- return NULL;
}
-SMTPOperation * sendMessage(Data * messageData)
+SMTPOperation * SMTPAsyncSession::sendMessageOperation(Data * messageData)
{
-#if 0
SMTPSendWithDataOperation * op = new SMTPSendWithDataOperation();
- op->setData(messageData);
+ op->setSession(this);
+ op->setMessageData(messageData);
return (SMTPOperation *) op->autorelease();
-#endif
- return NULL;
}
-SMTPOperation * sendMessage(MessageBuilder * msg)
+SMTPOperation * SMTPAsyncSession::sendMessageOperation(MessageBuilder * msg)
{
#if 0
SMTPSendWithBuilderOperation * op = new SMTPSendWithBuilderOperation();
+ op->setSession(this);
op->setBuilder(msg);
return (SMTPOperation *) op->autorelease();
#endif
diff --git a/src/async/smtp/MCSMTPAsyncSession.h b/src/async/smtp/MCSMTPAsyncSession.h
index 8e0e50b0..c4411a00 100644
--- a/src/async/smtp/MCSMTPAsyncSession.h
+++ b/src/async/smtp/MCSMTPAsyncSession.h
@@ -34,8 +34,6 @@ namespace mailcore {
SMTPAsyncSession();
virtual ~SMTPAsyncSession();
- virtual String * className();
-
virtual void setHostname(String * hostname);
virtual String * hostname();
@@ -63,9 +61,14 @@ namespace mailcore {
virtual void setUseHeloIPEnabled(bool enabled);
virtual bool useHeloIPEnabled();
- virtual SMTPOperation * sendMessage(Address * from, Array * recipients, Data * messageData);
- virtual SMTPOperation * sendMessage(Data * messageData);
- virtual SMTPOperation * sendMessage(MessageBuilder * msg);
+ virtual SMTPOperation * sendMessageOperationWithFromAndRecipient(Address * from, Array * recipients, Data * messageData);
+ virtual SMTPOperation * sendMessageOperation(Data * messageData);
+ virtual SMTPOperation * sendMessageOperation(MessageBuilder * msg);
+
+
+ // private
+ virtual void runOperation(SMTPOperation * operation);
+ virtual SMTPSession * session();
};
}
diff --git a/src/async/smtp/MCSMTPOperation.cpp b/src/async/smtp/MCSMTPOperation.cpp
new file mode 100644
index 00000000..532c6ab4
--- /dev/null
+++ b/src/async/smtp/MCSMTPOperation.cpp
@@ -0,0 +1,85 @@
+//
+// MCSMTPOperation.cpp
+// mailcore2
+//
+// Created by DINH Viêt Hoà on 1/11/13.
+// Copyright (c) 2013 MailCore. All rights reserved.
+//
+
+#include "MCSMTPOperation.h"
+
+#include <stdlib.h>
+
+#include "MCSMTPAsyncSession.h"
+#include "MCSMTPOperationCallback.h"
+
+using namespace mailcore;
+
+SMTPOperation::SMTPOperation()
+{
+ mSession = NULL;
+ mError = ErrorNone;
+}
+
+SMTPOperation::~SMTPOperation()
+{
+ MC_SAFE_RELEASE(mSession);
+}
+
+void SMTPOperation::setSession(SMTPAsyncSession * session)
+{
+ MC_SAFE_REPLACE_RETAIN(SMTPAsyncSession, mSession, session);
+}
+
+SMTPAsyncSession * SMTPOperation::session()
+{
+ return mSession;
+}
+
+void SMTPOperation::start()
+{
+ mSession->runOperation(this);
+}
+
+void SMTPOperation::setSmtpCallback(SMTPOperationCallback * callback)
+{
+ mSmtpCallback = callback;
+}
+
+SMTPOperationCallback * SMTPOperation::smtpCallback()
+{
+ return mSmtpCallback;
+}
+
+void SMTPOperation::setError(ErrorCode error)
+{
+ mError = error;
+}
+
+ErrorCode SMTPOperation::error()
+{
+ return mError;
+}
+
+struct progressContext {
+ unsigned int current;
+ unsigned int maximum;
+};
+
+void SMTPOperation::bodyProgress(SMTPSession * session, unsigned int current, unsigned int maximum)
+{
+ struct progressContext * context = (struct progressContext *) calloc(sizeof(* context), 1);
+ context->current = current;
+ context->maximum = maximum;
+ performMethodOnMainThread((Object::Method) &SMTPOperation::bodyProgressOnMainThread, context);
+}
+
+void SMTPOperation::bodyProgressOnMainThread(void * ctx)
+{
+ struct progressContext * context = (struct progressContext *) ctx;
+ if (mSmtpCallback != NULL) {
+ mSmtpCallback->bodyProgress(this, context->current, context->maximum);
+ }
+ free(context);
+}
+
diff --git a/src/async/smtp/MCSMTPOperation.h b/src/async/smtp/MCSMTPOperation.h
new file mode 100644
index 00000000..841c845c
--- /dev/null
+++ b/src/async/smtp/MCSMTPOperation.h
@@ -0,0 +1,46 @@
+//
+// MCSMTPOperation.h
+// mailcore2
+//
+// Created by DINH Viêt Hoà on 1/11/13.
+// Copyright (c) 2013 MailCore. All rights reserved.
+//
+
+#ifndef __mailcore2__MCSMTPOperation__
+#define __mailcore2__MCSMTPOperation__
+
+#include <mailcore/MCBaseTypes.h>
+#include <mailcore/MCSMTPProgressCallback.h>
+
+namespace mailcore {
+
+ class SMTPAsyncSession;
+ class SMTPOperationCallback;
+
+ class SMTPOperation : public Operation, public SMTPProgressCallback {
+ SMTPAsyncSession * mSession;
+ SMTPOperationCallback * mSmtpCallback;
+ ErrorCode mError;
+ private:
+ virtual void bodyProgress(SMTPSession * session, unsigned int current, unsigned int maximum);
+ virtual void bodyProgressOnMainThread(void * context);
+
+ public:
+ SMTPOperation();
+ virtual ~SMTPOperation();
+
+ virtual void setSession(SMTPAsyncSession * session);
+ virtual SMTPAsyncSession * session();
+
+ virtual void setSmtpCallback(SMTPOperationCallback * callback);
+ virtual SMTPOperationCallback * smtpCallback();
+
+ virtual void setError(ErrorCode error);
+ virtual ErrorCode error();
+
+ virtual void start();
+ };
+
+}
+
+#endif /* defined(__mailcore2__MCSMTPOperation__) */
diff --git a/src/async/smtp/MCSMTPOperationCallback.h b/src/async/smtp/MCSMTPOperationCallback.h
new file mode 100644
index 00000000..fec52767
--- /dev/null
+++ b/src/async/smtp/MCSMTPOperationCallback.h
@@ -0,0 +1,22 @@
+//
+// MCSMTPOperationCallback.h
+// mailcore2
+//
+// Created by DINH Viêt Hoà on 1/11/13.
+// Copyright (c) 2013 MailCore. All rights reserved.
+//
+
+#ifndef __mailcore2__MCSMTPOperationCallback__
+#define __mailcore2__MCSMTPOperationCallback__
+
+namespace mailcore {
+
+ class SMTPOperation;
+
+ class SMTPOperationCallback {
+ public:
+ virtual void bodyProgress(SMTPOperation * session, unsigned int current, unsigned int maximum) {};
+ };
+}
+
+#endif /* defined(__mailcore2__MCSMTPOperationCallback__) */
diff --git a/src/async/smtp/MCSMTPSendWithBuilderOperation.cc b/src/async/smtp/MCSMTPSendWithBuilderOperation.cc
index 560998ff..df19ee17 100644
--- a/src/async/smtp/MCSMTPSendWithBuilderOperation.cc
+++ b/src/async/smtp/MCSMTPSendWithBuilderOperation.cc
@@ -7,3 +7,37 @@
//
#include "MCSMTPSendWithBuilderOperation.h"
+
+#include "MCSMTPAsyncSession.h"
+#include "MCSMTPSession.h"
+#include "MCMessageBuilder.h"
+
+using namespace mailcore;
+
+SMTPSendWithBuilderOperation::SMTPSendWithBuilderOperation()
+{
+ mBuilder = NULL;
+}
+
+SMTPSendWithBuilderOperation::~SMTPSendWithBuilderOperation()
+{
+ MC_SAFE_RELEASE(mBuilder);
+}
+
+void SMTPSendWithBuilderOperation::setBuilder(MessageBuilder * builder)
+{
+ MC_SAFE_REPLACE_RETAIN(MessageBuilder, mBuilder, builder);
+}
+
+MessageBuilder * SMTPSendWithBuilderOperation::builder()
+{
+ return mBuilder;
+}
+
+void SMTPSendWithBuilderOperation::main()
+{
+ ErrorCode error;
+
+ session()->session()->sendMessage(mBuilder, this, &error);
+ setError(error);
+}
diff --git a/src/async/smtp/MCSMTPSendWithBuilderOperation.h b/src/async/smtp/MCSMTPSendWithBuilderOperation.h
index d306e30c..827e34b5 100644
--- a/src/async/smtp/MCSMTPSendWithBuilderOperation.h
+++ b/src/async/smtp/MCSMTPSendWithBuilderOperation.h
@@ -9,6 +9,28 @@
#ifndef __mailcore2__MCSMTPSendWithBuilderOperation__
#define __mailcore2__MCSMTPSendWithBuilderOperation__
-#include <iostream>
+#include <mailcore/MCBaseTypes.h>
+#include <mailcore/MCAbstract.h>
+#include <mailcore/MCSMTPOperation.h>
+
+namespace mailcore {
+
+ class MessageBuilder;
+
+ class SMTPSendWithBuilderOperation : public SMTPOperation {
+ MessageBuilder * mBuilder;
+ private:
+
+ public:
+ SMTPSendWithBuilderOperation();
+ virtual ~SMTPSendWithBuilderOperation();
+
+ virtual void setBuilder(MessageBuilder * builder);
+ virtual MessageBuilder * builder();
+
+ void main();
+ };
+
+}
#endif /* defined(__mailcore2__SMTPSendWithBuilderOperation__) */
diff --git a/src/async/smtp/MCSMTPSendWithDataOperation.cc b/src/async/smtp/MCSMTPSendWithDataOperation.cc
index ab42aa0e..5c43828a 100644
--- a/src/async/smtp/MCSMTPSendWithDataOperation.cc
+++ b/src/async/smtp/MCSMTPSendWithDataOperation.cc
@@ -7,3 +7,36 @@
//
#include "MCSMTPSendWithDataOperation.h"
+
+#include "MCSMTPAsyncSession.h"
+#include "MCSMTPSession.h"
+
+using namespace mailcore;
+
+SMTPSendWithDataOperation::SMTPSendWithDataOperation()
+{
+ mMessageData = NULL;
+}
+
+SMTPSendWithDataOperation::~SMTPSendWithDataOperation()
+{
+ MC_SAFE_RELEASE(mMessageData);
+}
+
+void SMTPSendWithDataOperation::setMessageData(Data * data)
+{
+ MC_SAFE_REPLACE_RETAIN(Data, mMessageData, data);
+}
+
+Data * SMTPSendWithDataOperation::messageData()
+{
+ return mMessageData;
+}
+
+void SMTPSendWithDataOperation::main()
+{
+ ErrorCode error;
+
+ session()->session()->sendMessage(mMessageData, this, &error);
+ setError(error);
+}
diff --git a/src/async/smtp/MCSMTPSendWithDataOperation.h b/src/async/smtp/MCSMTPSendWithDataOperation.h
index c13ee07d..4f71e233 100644
--- a/src/async/smtp/MCSMTPSendWithDataOperation.h
+++ b/src/async/smtp/MCSMTPSendWithDataOperation.h
@@ -9,6 +9,25 @@
#ifndef __mailcore2__MCSMTPSendWithDataOperation__
#define __mailcore2__MCSMTPSendWithDataOperation__
-#include <iostream>
+#include <mailcore/MCBaseTypes.h>
+#include <mailcore/MCAbstract.h>
+#include <mailcore/MCSMTPOperation.h>
+
+namespace mailcore {
+
+ class SMTPSendWithDataOperation : public SMTPOperation {
+ Data * mMessageData;
+ private:
+
+ public:
+ SMTPSendWithDataOperation();
+ virtual ~SMTPSendWithDataOperation();
+
+ virtual void setMessageData(Data * data);
+ virtual Data * messageData();
+
+ virtual void main();
+ };
+}
#endif /* defined(__mailcore2__SMTPSendWithDataOperation__) */
diff --git a/src/async/smtp/MCSMTPSendWithRecipientOperation.cc b/src/async/smtp/MCSMTPSendWithRecipientOperation.cc
index 5fee7fa3..ca91ab63 100644
--- a/src/async/smtp/MCSMTPSendWithRecipientOperation.cc
+++ b/src/async/smtp/MCSMTPSendWithRecipientOperation.cc
@@ -7,3 +7,65 @@
//
#include "MCSMTPSendWithRecipientOperation.h"
+
+#include "MCSMTPAsyncSession.h"
+#include "MCSMTPSession.h"
+
+using namespace mailcore;
+
+void SMTPSendWithRecipientOperation::init()
+{
+ mRecipients = NULL;
+ mFrom = NULL;
+ mMessageData = NULL;
+}
+
+SMTPSendWithRecipientOperation::SMTPSendWithRecipientOperation()
+{
+ init();
+}
+
+SMTPSendWithRecipientOperation::~SMTPSendWithRecipientOperation()
+{
+ MC_SAFE_RELEASE(mRecipients);
+ MC_SAFE_RELEASE(mFrom);
+ MC_SAFE_RELEASE(mMessageData);
+}
+
+void SMTPSendWithRecipientOperation::setFrom(Address * from)
+{
+ MC_SAFE_REPLACE_RETAIN(Address, mFrom, from);
+}
+
+Address * SMTPSendWithRecipientOperation::from()
+{
+ return mFrom;
+}
+
+void SMTPSendWithRecipientOperation::setRecipients(Array * recipients)
+{
+ MC_SAFE_REPLACE_RETAIN(Array, mRecipients, recipients);
+}
+
+Array * SMTPSendWithRecipientOperation::recipients()
+{
+ return mRecipients;
+}
+
+void SMTPSendWithRecipientOperation::setMessageData(Data * data)
+{
+ MC_SAFE_REPLACE_RETAIN(Data, mMessageData, data);
+}
+
+Data * SMTPSendWithRecipientOperation::messageData()
+{
+ return mMessageData;
+}
+
+void SMTPSendWithRecipientOperation::main()
+{
+ ErrorCode error;
+
+ session()->session()->sendMessage(mFrom, mRecipients, mMessageData, this, &error);
+ setError(error);
+}
diff --git a/src/async/smtp/MCSMTPSendWithRecipientOperation.h b/src/async/smtp/MCSMTPSendWithRecipientOperation.h
index f4134688..936e8a51 100644
--- a/src/async/smtp/MCSMTPSendWithRecipientOperation.h
+++ b/src/async/smtp/MCSMTPSendWithRecipientOperation.h
@@ -9,5 +9,36 @@
#ifndef __mailcore2__MCSMTPSendWithRecipientOperation__
#define __mailcore2__MCSMTPSendWithRecipientOperation__
+#include <mailcore/MCBaseTypes.h>
+#include <mailcore/MCAbstract.h>
+#include <mailcore/MCSMTPOperation.h>
+
+namespace mailcore {
+
+ class SMTPSendWithRecipientOperation : public SMTPOperation {
+ private:
+ Array * mRecipients;
+ Address * mFrom;
+ Data * mMessageData;
+
+ void init();
+
+ public:
+ SMTPSendWithRecipientOperation();
+ virtual ~SMTPSendWithRecipientOperation();
+
+ virtual void setFrom(Address * from);
+ virtual Address * from();
+
+ virtual void setRecipients(Array * recipients);
+ virtual Array * recipients();
+
+ virtual void setMessageData(Data * data);
+ virtual Data * messageData();
+
+ virtual void main();
+ };
+
+}
#endif /* defined(__mailcore2__SMTPSendWithRecipientOperation__) */
diff --git a/src/core/abstract/MCMessageHeader.cc b/src/core/abstract/MCMessageHeader.cc
index 06ad386b..765bc085 100644
--- a/src/core/abstract/MCMessageHeader.cc
+++ b/src/core/abstract/MCMessageHeader.cc
@@ -769,7 +769,7 @@ struct mailimf_fields * MessageHeader::createIMFFieldsAndFilterBcc(bool filterBc
imfDate = NULL;
if (date() != (time_t) -1) {
- MCLog("%lu", date());
+ //MCLog("%lu", date());
imfDate = get_date_from_timestamp(date());
}
imfFrom = NULL;
diff --git a/src/core/basetypes/MCAutoreleasePool.cc b/src/core/basetypes/MCAutoreleasePool.cc
index 7e43734f..6c38982d 100644
--- a/src/core/basetypes/MCAutoreleasePool.cc
+++ b/src/core/basetypes/MCAutoreleasePool.cc
@@ -54,6 +54,9 @@ void AutoreleasePool::destroyAutoreleasePoolStack(void *)
{
init();
carray * stack = (carray *) pthread_getspecific(autoreleasePoolStackKey);
+ if (stack == NULL)
+ return;
+
if (carray_count(stack) != 0) {
MCLog("some autoreleasepool have not been released\n");
}
diff --git a/src/core/basetypes/MCLog.cc b/src/core/basetypes/MCLog.cc
index 2ceceecc..51f6d46e 100644
--- a/src/core/basetypes/MCLog.cc
+++ b/src/core/basetypes/MCLog.cc
@@ -1,7 +1,12 @@
#include "MCLog.h"
#include <stdarg.h>
+#include <string.h>
#include <stdio.h>
+#include <time.h>
+#include <sys/time.h>
+#include <pthread.h>
+#include <unistd.h>
static void logInternalv(FILE * file,
const char * user, const char * filename, unsigned int line,
@@ -24,7 +29,34 @@ static void logInternalv(FILE * file,
const char * user, const char * filename, unsigned int line,
int dumpStack, const char * format, va_list argp)
{
- fprintf(file, "%s:%i: ", filename, line);
+ while (1) {
+ const char * p = filename;
+
+ p = strchr(filename, '/');
+ if (p == NULL) {
+ break;
+ }
+ filename = p + 1;
+ }
+
+ struct timeval tv;
+ struct tm tm_value;
+ pthread_t thread_id = pthread_self();
+
+ gettimeofday(&tv, NULL);
+ localtime_r(&tv.tv_sec, &tm_value);
+ fprintf(file, "%04u-%02u-%02u %02u:%02u:%02u.%03u ", tm_value.tm_year + 1900, tm_value.tm_mon + 1, tm_value.tm_mday, tm_value.tm_hour, tm_value.tm_min, tm_value.tm_sec, tv.tv_usec / 1000);
+
+ if (pthread_main_np()) {
+ fprintf(file, "[%i:main] %s:%i: ", getpid(), filename, line);
+ }
+ else {
+#ifdef _MACH_PORT_T
+ fprintf(file, "[%i:%x] %s:%i: ", getpid(), pthread_mach_thread_np(thread_id), filename, line);
+#else
+ fprintf(file, "[%i:%p] %s:%i: ", getpid(), (void *) thread_id, filename, line);
+#endif
+ }
vfprintf(file, format, argp);
fprintf(file, "\n");
}
diff --git a/src/mailcore.h b/src/mailcore.h
index f4198e6d..9b3ba66a 100644
--- a/src/mailcore.h
+++ b/src/mailcore.h
@@ -10,5 +10,6 @@
#define mailcore2_mailcore_h
#include <mailcore/MCCore.h>
+#include <mailcore/MCAsync.h>
#endif
diff --git a/tests/main.mm b/tests/main.mm
index db73c89b..030bab85 100644
--- a/tests/main.mm
+++ b/tests/main.mm
@@ -137,25 +137,13 @@ static void testPOP()
session->release();
}
-void testAll()
+static void testOperationQueue()
{
- u_setDataDirectory("/usr/local/share/icu");
-
- mailcore::AutoreleasePool * pool = new mailcore::AutoreleasePool();
-
- mailstream_debug = 1;
-
- mailcore::Data * data = testMessageBuilder();
- testMessageParser(data);
- testSMTP(data);
- testIMAP();
- testPOP();
-
mailcore::OperationQueue * queue = new mailcore::OperationQueue();
TestCallback * callback = new TestCallback();
- for(unsigned int i = 0 ; i < 1 ; i ++) {
+ for(unsigned int i = 0 ; i < 100 ; i ++) {
mailcore::Operation * op = new TestOperation();
op->setCallback(callback);
queue->addOperation(op);
@@ -165,6 +153,56 @@ void testAll()
[[NSRunLoop currentRunLoop] run];
queue->release();
+}
+
+class TestSMTPCallback : public mailcore::Object, public mailcore::OperationCallback, public mailcore::SMTPOperationCallback {
+ virtual void operationFinished(mailcore::Operation * op)
+ {
+ MCLog("callback %s %s", MCUTF8DESC(op), MCUTF8DESC(this));
+ }
+
+ virtual void bodyProgress(mailcore::SMTPOperation * op, unsigned int current, unsigned int maximum)
+ {
+ MCLog("progress %s %s %i/%i", MCUTF8DESC(op), MCUTF8DESC(this), current, maximum);
+ }
+};
+
+static void testAsyncSMTP(mailcore::Data * data)
+{
+ mailcore::SMTPAsyncSession * smtp;
+ TestSMTPCallback * callback = new TestSMTPCallback();
+
+ smtp = new mailcore::SMTPAsyncSession();
+
+ smtp->setHostname(MCSTR("smtp.gmail.com"));
+ smtp->setPort(25);
+ smtp->setUsername(email);
+ smtp->setPassword(password);
+ smtp->setConnectionType(mailcore::ConnectionTypeStartTLS);
+
+ mailcore::SMTPOperation * op = smtp->sendMessageOperation(data);
+ op->setSmtpCallback(callback);
+ op->start();
+
+ [[NSRunLoop currentRunLoop] run];
+
+ //smtp->release();
+}
+
+void testAll()
+{
+ u_setDataDirectory("/usr/local/share/icu");
+
+ mailcore::AutoreleasePool * pool = new mailcore::AutoreleasePool();
+
+ mailstream_debug = 1;
+
+ mailcore::Data * data = testMessageBuilder();
+ //testMessageParser(data);
+ //testSMTP(data);
+ //testIMAP();
+ //testPOP();
+ testAsyncSMTP(data);
MCLog("pool release");
pool->release();