aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc/smtp/MCOSMTPSession.mm
diff options
context:
space:
mode:
Diffstat (limited to 'src/objc/smtp/MCOSMTPSession.mm')
-rw-r--r--src/objc/smtp/MCOSMTPSession.mm58
1 files changed, 55 insertions, 3 deletions
diff --git a/src/objc/smtp/MCOSMTPSession.mm b/src/objc/smtp/MCOSMTPSession.mm
index de6b54cd..1538d53a 100644
--- a/src/objc/smtp/MCOSMTPSession.mm
+++ b/src/objc/smtp/MCOSMTPSession.mm
@@ -17,8 +17,34 @@
#import "MCOAddress.h"
#import "MCOSMTPOperation+Private.h"
+using namespace mailcore;
+
+@interface MCOSMTPSession ()
+
+- (void) _logWithSender:(void *)sender connectionType:(MCOConnectionLogType)logType data:(NSData *)data;
+
+@end
+
+class MCOSMTPConnectionLoggerBridge : public Object, public ConnectionLogger {
+public:
+ MCOSMTPConnectionLoggerBridge(MCOSMTPSession * session)
+ {
+ mSession = session;
+ }
+
+ virtual void log(void * context, void * sender, ConnectionLogType logType, Data * data)
+ {
+ [mSession _logWithSender:sender connectionType:(MCOConnectionLogType)logType data:MCO_TO_OBJC(data)];
+ }
+
+private:
+ MCOSMTPSession * mSession;
+};
+
@implementation MCOSMTPSession {
mailcore::SMTPAsyncSession * _session;
+ MCOConnectionLogger _connectionLogger;
+ MCOSMTPConnectionLoggerBridge * _loggerBridge;
}
#define nativeType mailcore::SMTPAsyncSession
@@ -30,13 +56,16 @@
- (id)init {
self = [super init];
- if (self) {
- _session = new mailcore::SMTPAsyncSession();
- }
+
+ _session = new mailcore::SMTPAsyncSession();
+ _loggerBridge = new MCOSMTPConnectionLoggerBridge(self);
+
return self;
}
- (void)dealloc {
+ MC_SAFE_RELEASE(_loggerBridge);
+ [_connectionLogger release];
_session->release();
[super dealloc];
}
@@ -51,6 +80,24 @@ MCO_OBJC_SYNTHESIZE_SCALAR(NSTimeInterval, time_t, setTimeout, timeout)
MCO_OBJC_SYNTHESIZE_BOOL(setCheckCertificateEnabled, isCheckCertificateEnabled)
MCO_OBJC_SYNTHESIZE_BOOL(setUseHeloIPEnabled, useHeloIPEnabled)
+- (void) setConnectionLogger:(MCOConnectionLogger)connectionLogger
+{
+ [_connectionLogger release];
+ _connectionLogger = [connectionLogger copy];
+
+ if (_connectionLogger != nil) {
+ _session->setConnectionLogger(_loggerBridge);
+ }
+ else {
+ _session->setConnectionLogger(NULL);
+ }
+}
+
+- (MCOConnectionLogger) connectionLogger
+{
+ return _connectionLogger;
+}
+
#pragma mark - Operations
- (MCOSMTPSendOperation *) sendOperationWithData:(NSData *)messageData
@@ -69,4 +116,9 @@ MCO_OBJC_SYNTHESIZE_BOOL(setUseHeloIPEnabled, useHeloIPEnabled)
return result;
}
+- (void) _logWithSender:(void *)sender connectionType:(MCOConnectionLogType)logType data:(NSData *)data
+{
+ _connectionLogger(sender, logType, data);
+}
+
@end