aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/core/rfc822/MCMessageBuilder.cpp25
-rw-r--r--src/core/rfc822/MCMessageBuilder.h5
-rw-r--r--src/objc/rfc822/MCOMessageBuilder.h3
-rw-r--r--src/objc/rfc822/MCOMessageBuilder.mm9
4 files changed, 41 insertions, 1 deletions
diff --git a/src/core/rfc822/MCMessageBuilder.cpp b/src/core/rfc822/MCMessageBuilder.cpp
index a98cefd1..b3a95249 100644
--- a/src/core/rfc822/MCMessageBuilder.cpp
+++ b/src/core/rfc822/MCMessageBuilder.cpp
@@ -810,6 +810,31 @@ Data * MessageBuilder::dataForEncryption()
return dataAndFilterBccAndForEncryption(false, true);
}
+ErrorCode MessageBuilder::writeToFile(String * filename)
+{
+ FILE * f = fopen(filename->fileSystemRepresentation(), "wb");
+ if (f == NULL) {
+ return ErrorFile;
+ }
+
+ ErrorCode error = ErrorNone;
+ struct mailmime * mime = mimeAndFilterBccAndForEncryption(false, false);
+
+ int col = 0;
+ int r = mailmime_write_file(f, &col, mime);
+ if (r != MAILIMF_NO_ERROR) {
+ error = ErrorFile;
+ }
+
+ mailmime_free(mime);
+
+ if (fclose(f) != 0) {
+ error = ErrorFile;
+ }
+
+ return error;
+}
+
String * MessageBuilder::htmlRendering(HTMLRendererTemplateCallback * htmlCallback)
{
MessageParser * message = MessageParser::messageParserWithData(data());
diff --git a/src/core/rfc822/MCMessageBuilder.h b/src/core/rfc822/MCMessageBuilder.h
index f03bd09a..3d26ac59 100644
--- a/src/core/rfc822/MCMessageBuilder.h
+++ b/src/core/rfc822/MCMessageBuilder.h
@@ -40,7 +40,10 @@ namespace mailcore {
virtual Data * data();
virtual Data * dataForEncryption();
-
+
+ // Store builded message to file.
+ virtual ErrorCode writeToFile(String * filename);
+
virtual String * htmlRendering(HTMLRendererTemplateCallback * htmlCallback = NULL);
virtual String * htmlBodyRendering();
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);