aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc
diff options
context:
space:
mode:
authorGravatar Hoà V. DINH <dinh.viet.hoa@gmail.com>2016-02-09 07:31:25 -0800
committerGravatar Hoà V. DINH <dinh.viet.hoa@gmail.com>2016-02-09 07:31:25 -0800
commit20ae2fd57a9a9edd4c539fa170433ee8d59904b1 (patch)
tree59699d28c313dc3348d36da8f4d80437deb4ded6 /src/objc
parent5b694c89ebe98f388af25ad8f176f42523594358 (diff)
parente554610cb5b5820eae81217066d594c6f1999089 (diff)
Merge pull request #1355 from disaykin/reduce-memory-on-send-message
Add low-memory interface for building, sending and appending messages
Diffstat (limited to 'src/objc')
-rwxr-xr-xsrc/objc/imap/MCOIMAPSession.h18
-rwxr-xr-xsrc/objc/imap/MCOIMAPSession.mm12
-rw-r--r--src/objc/rfc822/MCOMessageBuilder.h3
-rw-r--r--src/objc/rfc822/MCOMessageBuilder.mm9
-rw-r--r--src/objc/smtp/MCOSMTPSession.h18
-rw-r--r--src/objc/smtp/MCOSMTPSession.mm13
6 files changed, 73 insertions, 0 deletions
diff --git a/src/objc/imap/MCOIMAPSession.h b/src/objc/imap/MCOIMAPSession.h
index bab3be7f..6fd5f76e 100755
--- a/src/objc/imap/MCOIMAPSession.h
+++ b/src/objc/imap/MCOIMAPSession.h
@@ -305,6 +305,24 @@
customFlags:(NSArray *)customFlags;
/**
+ Returns an operation to add a message with custom flags to a folder.
+
+ MCOIMAPOperation * op = [session appendMessageOperationWithFolder:@"Sent Mail"
+ contentsAtPath:rfc822DataFilename
+ flags:MCOMessageFlagNone
+ customFlags:@[@"$CNS-Greeting-On"]];
+ [op start:^(NSError * __nullable error, uint32_t createdUID) {
+ if (error == nil) {
+ NSLog(@"created message with UID %lu", (unsigned long) createdUID);
+ }
+ }];
+ */
+- (MCOIMAPAppendMessageOperation *)appendMessageOperationWithFolder:(NSString *)folder
+ contentsAtPath:(NSString *)path
+ flags:(MCOMessageFlag)flags
+ customFlags:(NSArray *)customFlags;
+
+/**
Returns an operation to copy messages to a folder.
MCOIMAPCopyMessagesOperation * op = [session copyMessagesOperationWithFolder:@"INBOX"
diff --git a/src/objc/imap/MCOIMAPSession.mm b/src/objc/imap/MCOIMAPSession.mm
index 32dd1119..c245cdc3 100755
--- a/src/objc/imap/MCOIMAPSession.mm
+++ b/src/objc/imap/MCOIMAPSession.mm
@@ -264,6 +264,18 @@ MCO_OBJC_SYNTHESIZE_SCALAR(dispatch_queue_t, dispatch_queue_t, setDispatchQueue,
return MCO_TO_OBJC_OP(coreOp);
}
+- (MCOIMAPAppendMessageOperation *)appendMessageOperationWithFolder:(NSString *)folder
+ contentsAtPath:(NSString *)path
+ flags:(MCOMessageFlag)flags
+ customFlags:(NSArray *)customFlags
+{
+ IMAPAppendMessageOperation * coreOp = MCO_NATIVE_INSTANCE->appendMessageOperation([folder mco_mcString],
+ MCO_FROM_OBJC(String, path),
+ (MessageFlag) flags,
+ MCO_FROM_OBJC(Array, customFlags));
+ return MCO_TO_OBJC_OP(coreOp);
+}
+
- (MCOIMAPCopyMessagesOperation *)copyMessagesOperationWithFolder:(NSString *)folder
uids:(MCOIndexSet *)uids
destFolder:(NSString *)destFolder
diff --git a/src/objc/rfc822/MCOMessageBuilder.h b/src/objc/rfc822/MCOMessageBuilder.h
index 1663d6f7..fbebb7f6 100644
--- a/src/objc/rfc822/MCOMessageBuilder.h
+++ b/src/objc/rfc822/MCOMessageBuilder.h
@@ -61,6 +61,9 @@
/** RFC 822 formatted message for encryption.*/
- (NSData *) dataForEncryption;
+/** Store RFC 822 formatted message to file. */
+- (BOOL) writeToFile:(NSString *)filename error:(NSError **)error;
+
/**
Returns an OpenPGP signed message with a given signature.
The signature needs to be computed on the data returned by -dataForEncryption
diff --git a/src/objc/rfc822/MCOMessageBuilder.mm b/src/objc/rfc822/MCOMessageBuilder.mm
index 84cc37f2..31ebc742 100644
--- a/src/objc/rfc822/MCOMessageBuilder.mm
+++ b/src/objc/rfc822/MCOMessageBuilder.mm
@@ -70,6 +70,15 @@ MCO_OBJC_SYNTHESIZE_STRING(setBoundaryPrefix, boundaryPrefix)
return MCO_OBJC_BRIDGE_GET(dataForEncryption);
}
+- (BOOL) writeToFile:(NSString *)filename error:(NSError **)error
+{
+ mailcore::ErrorCode errorCode = MCO_NATIVE_INSTANCE->writeToFile(MCO_FROM_OBJC(mailcore::String, filename));
+ if (error) {
+ *error = [NSError mco_errorWithErrorCode:errorCode];
+ }
+ return errorCode == mailcore::ErrorNone;
+}
+
- (NSString *) htmlRenderingWithDelegate:(id <MCOHTMLRendererDelegate>)delegate
{
MCOAbstractMessageRendererCallback * htmlRenderCallback = new MCOAbstractMessageRendererCallback(self, delegate, NULL);
diff --git a/src/objc/smtp/MCOSMTPSession.h b/src/objc/smtp/MCOSMTPSession.h
index 31055335..84d6949d 100644
--- a/src/objc/smtp/MCOSMTPSession.h
+++ b/src/objc/smtp/MCOSMTPSession.h
@@ -154,6 +154,24 @@
from:(MCOAddress *)from
recipients:(NSArray *)recipients;
+
+/**
+ Returns an operation that will send the message from the given file through SMTP.
+ It will use the sender and recipient set from the parameters.
+ It will also filter out Bcc from the content of the message.
+
+ MCOSMTPOperation * op = [session sendOperationWithContentsOfFile:rfc822DataFilename
+ from:[MCOAddress addressWithMailbox:@"hoa@etpan.org"]
+ recipients:[NSArray arrayWithObject:
+ [MCOAddress addressWithMailbox:@"laura@etpan.org"]]];
+ [op start:^(NSError * __nullable error) {
+ ...
+ }];
+ */
+- (MCOSMTPSendOperation *) sendOperationWithContentsOfFile:(NSString *)path
+ from:(MCOAddress *)from
+ recipients:(NSArray *)recipients;
+
/**
Returns an operation that will check whether the SMTP account is valid.
diff --git a/src/objc/smtp/MCOSMTPSession.mm b/src/objc/smtp/MCOSMTPSession.mm
index 9bcbd48e..9406a719 100644
--- a/src/objc/smtp/MCOSMTPSession.mm
+++ b/src/objc/smtp/MCOSMTPSession.mm
@@ -170,6 +170,19 @@ MCO_OBJC_SYNTHESIZE_SCALAR(dispatch_queue_t, dispatch_queue_t, setDispatchQueue,
return result;
}
+- (MCOSMTPSendOperation *) sendOperationWithContentsOfFile:(NSString *)path
+ from:(MCOAddress *)from
+ recipients:(NSArray *)recipients
+{
+ mailcore::SMTPOperation * coreOp =
+ MCO_NATIVE_INSTANCE->sendMessageOperation(MCO_FROM_OBJC(Address, from),
+ MCO_FROM_OBJC(Array, recipients),
+ MCO_FROM_OBJC(String, path));
+ MCOSMTPSendOperation * result = [[[MCOSMTPSendOperation alloc] initWithMCOperation:coreOp] autorelease];
+ [result setSession:self];
+ return result;
+}
+
- (MCOSMTPOperation *) checkAccountOperationWithFrom:(MCOAddress *)from
{
mailcore::SMTPOperation *coreOp = MCO_NATIVE_INSTANCE->checkAccountOperation(MCO_FROM_OBJC(mailcore::Address, from));