Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

new call to set HTML and Text body at once

  • Loading branch information...
commit 817197d390f6dca83f17cf9fe577790dd879f319 1 parent 1246cdd
@gdonelli gdonelli authored
Showing with 65 additions and 3 deletions.
  1. +6 −0 Source/CTCoreMessage.h
  2. +59 −3 Source/CTCoreMessage.m
View
6 Source/CTCoreMessage.h
@@ -145,6 +145,12 @@ typedef enum {
- (void)setHTMLBody:(NSString *)body;
/**
+ Use this method to set both body Plaintext and HTML content.
+ HTML will have higher priority
+ */
+- (void) setHTMLBody:(NSString*)htmlString textBody:(NSString*)plainString;
+
+/**
A list of attachments this message has
*/
- (NSArray *)attachments;
View
62 Source/CTCoreMessage.m
@@ -272,6 +272,35 @@ - (BOOL)_buildUpHtmlBodyText:(CTMIME *)mime result:(NSMutableString *)result {
}
+
+- (void) setHTMLBody:(NSString*)htmlString textBody:(NSString*)plainString {
+ /*
+ * Message structure:
+ *
+ * [ msg root ]
+ * --> multipart/alternative (Body)
+ * -----> text
+ * -----> html
+ */
+
+ // Body (multipart/alternative)
+ CTMIME_MultiPart* bodyMultipart = [CTMIME_MultiPart mimeMultiPart];
+ bodyMultipart.contentType = @"multipart/alternative";
+
+ CTMIME_TextPart* bodyTextPart = [CTMIME_TextPart mimeTextPartWithString:plainString];
+ CTMIME_HtmlPart* bodyHtmlPart = [CTMIME_HtmlPart mimeTextPartWithString:htmlString];
+
+ [bodyMultipart addMIMEPart: bodyTextPart ];
+ [bodyMultipart addMIMEPart: bodyHtmlPart ];
+
+ // Root
+ CTMIME_MessagePart* messagePartRoot = [CTMIME_MessagePart mimeMessagePartWithContent:bodyMultipart];
+
+ [myParsedMIME release];
+ myParsedMIME = [messagePartRoot retain];
+}
+
+
- (void)setBody:(NSString *)body {
CTMIME *oldMIME = myParsedMIME;
CTMIME_TextPart *text = [CTMIME_TextPart mimeTextPartWithString:body];
@@ -323,11 +352,38 @@ - (void)addAttachment:(CTCoreAttachment *)attachment {
msg = (CTMIME_MessagePart *)myParsedMIME;
CTMIME *sub = [msg content];
-
// Creat new multimime part if needed
if ([sub isKindOfClass:[CTMIME_MultiPart class]]) {
- multi = (CTMIME_MultiPart *)sub;
- } else {
+ // Assuming this is the body
+ if ([sub.contentType isEqualToString:@"multipart/alternative"]) {
+ /*
+ * Transform the following
+ * message structure:
+ *
+ * [ msg root ]
+ * --> multipart/alternative
+ * -----> text
+ * -----> html
+ *
+ * into:
+ *
+ * [ MessagePart Root ]
+ * --> multipart/mixed
+ * -----> attachments
+ * -----> multipart/alternative
+ * --------> text
+ * --------> html
+ */
+
+ CTMIME_MultiPart* multipartMixed = [CTMIME_MultiPart mimeMultiPart];
+ [multipartMixed addMIMEPart:sub];
+ multi = multipartMixed;
+ [msg setContent:multipartMixed];
+ }
+ else
+ multi = (CTMIME_MultiPart *)sub;
+ }
+ else {
multi = [CTMIME_MultiPart mimeMultiPart];
[multi addMIMEPart:sub];
[msg setContent:multi];

0 comments on commit 817197d

Please sign in to comment.
Something went wrong with that request. Please try again.