Merged
This commit is contained in:
@@ -29,7 +29,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <libetpan/libetpan.h>
|
||||
|
||||
/*!
|
||||
@@ -102,6 +102,12 @@
|
||||
*/
|
||||
- (NSString *)htmlBody;
|
||||
|
||||
/*! @abstract Returns a message body as an NSString. First attempts
|
||||
to retrieve a plain text body, if that fails then
|
||||
tries for an HTML body.
|
||||
*/
|
||||
- (NSString *)bodyPreferringPlainText;
|
||||
|
||||
/*!
|
||||
@abstract This method sets the message body. Plaintext only please!
|
||||
*/
|
||||
@@ -125,7 +131,7 @@
|
||||
a date from the distant past is used instead.
|
||||
*/
|
||||
//FIXME
|
||||
//- (NSCalendarDate *)sentDate;
|
||||
- (NSCalendarDate *)sentDate;
|
||||
|
||||
/*!
|
||||
@abstract Returns YES if the message is unread.
|
||||
|
||||
+65
-22
@@ -37,6 +37,7 @@
|
||||
#import "CTMIME_MessagePart.h"
|
||||
#import "CTMIME_TextPart.h"
|
||||
#import "CTMIME_MultiPart.h"
|
||||
#import "CTMIME_SinglePart.h"
|
||||
#import "CTBareAttachment.h"
|
||||
|
||||
@interface CTCoreMessage (Private)
|
||||
@@ -143,6 +144,14 @@ char * etpan_encode_mime_header(char * phrase)
|
||||
return result;
|
||||
}
|
||||
|
||||
- (NSString *)bodyPreferringPlainText {
|
||||
NSString *body = [self body];
|
||||
if ([body length] == 0) {
|
||||
body = [self htmlBody];
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
|
||||
- (void)_buildUpBodyText:(CTMIME *)mime result:(NSMutableString *)result {
|
||||
if (mime == nil)
|
||||
@@ -200,9 +209,17 @@ char * etpan_encode_mime_header(char * phrase)
|
||||
- (void)setBody:(NSString *)body {
|
||||
CTMIME *oldMIME = myParsedMIME;
|
||||
CTMIME_TextPart *text = [CTMIME_TextPart mimeTextPartWithString:body];
|
||||
CTMIME_MessagePart *messagePart = [CTMIME_MessagePart mimeMessagePartWithContent:text];
|
||||
myParsedMIME = [messagePart retain];
|
||||
[oldMIME release];
|
||||
|
||||
// If myParsedMIME is already a multi-part mime, just add it. otherwise replace it.
|
||||
//TODO: If setBody is called multiple times it will add text parts multiple times. Instead
|
||||
// it should find the existing text part (if there is one) and replace it
|
||||
if ([myParsedMIME isKindOfClass:[CTMIME_MultiPart class]]) {
|
||||
[(CTMIME_MultiPart *)myParsedMIME addMIMEPart:text];
|
||||
} else {
|
||||
CTMIME_MessagePart *messagePart = [CTMIME_MessagePart mimeMessagePartWithContent:text];
|
||||
myParsedMIME = [messagePart retain];
|
||||
[oldMIME release];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSArray *)attachments {
|
||||
@@ -225,6 +242,30 @@ char * etpan_encode_mime_header(char * phrase)
|
||||
}
|
||||
|
||||
- (void)addAttachment:(CTCoreAttachment *)attachment {
|
||||
CTMIME_MultiPart *multi;
|
||||
CTMIME_MessagePart *msg;
|
||||
|
||||
if ([myParsedMIME isKindOfClass:[CTMIME_MessagePart class]]) {
|
||||
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 {
|
||||
multi = [CTMIME_MultiPart mimeMultiPart];
|
||||
[multi addMIMEPart:sub];
|
||||
[msg setContent:multi];
|
||||
}
|
||||
|
||||
// add new SinglePart which encodes the attachment in base64
|
||||
CTMIME_SinglePart *attpart = [CTMIME_SinglePart mimeSinglePartWithData:[attachment data]];
|
||||
attpart.contentType = [attachment contentType];
|
||||
attpart.filename = [attachment filename];
|
||||
|
||||
[multi addMIMEPart:attpart];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -248,23 +289,23 @@ char * etpan_encode_mime_header(char * phrase)
|
||||
}
|
||||
|
||||
|
||||
//- (NSCalendarDate *)sentDate {
|
||||
// if ( myFields->fld_orig_date == NULL) {
|
||||
// return [NSDate distantPast];
|
||||
// }
|
||||
// else {
|
||||
// //This feels like a hack, there should be a better way to deal with the time zone
|
||||
// NSInteger seconds = 60*60*myFields->fld_orig_date->dt_date_time->dt_zone/100;
|
||||
// NSTimeZone *timeZone = [NSTimeZone timeZoneForSecondsFromGMT:seconds];
|
||||
// return [NSCalendarDate dateWithYear:myFields->fld_orig_date->dt_date_time->dt_year
|
||||
// month:myFields->fld_orig_date->dt_date_time->dt_month
|
||||
// day:myFields->fld_orig_date->dt_date_time->dt_day
|
||||
// hour:myFields->fld_orig_date->dt_date_time->dt_hour
|
||||
// minute:myFields->fld_orig_date->dt_date_time->dt_min
|
||||
// second:myFields->fld_orig_date->dt_date_time->dt_sec
|
||||
// timeZone:timeZone];
|
||||
// }
|
||||
//}
|
||||
- (NSCalendarDate *)sentDate {
|
||||
if ( myFields->fld_orig_date == NULL) {
|
||||
return [NSDate distantPast];
|
||||
}
|
||||
else {
|
||||
//This feels like a hack, there should be a better way to deal with the time zone
|
||||
NSInteger seconds = 60*60*myFields->fld_orig_date->dt_date_time->dt_zone/100;
|
||||
NSTimeZone *timeZone = [NSTimeZone timeZoneForSecondsFromGMT:seconds];
|
||||
return [NSCalendarDate dateWithYear:myFields->fld_orig_date->dt_date_time->dt_year
|
||||
month:myFields->fld_orig_date->dt_date_time->dt_month
|
||||
day:myFields->fld_orig_date->dt_date_time->dt_day
|
||||
hour:myFields->fld_orig_date->dt_date_time->dt_hour
|
||||
minute:myFields->fld_orig_date->dt_date_time->dt_min
|
||||
second:myFields->fld_orig_date->dt_date_time->dt_sec
|
||||
timeZone:timeZone];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)isUnread {
|
||||
@@ -409,7 +450,9 @@ char * etpan_encode_mime_header(char * phrase)
|
||||
|
||||
|
||||
- (NSString *)render {
|
||||
if ([myParsedMIME isMemberOfClass:[myParsedMIME class]]) {
|
||||
CTMIME *msgPart = myParsedMIME;
|
||||
|
||||
if ([myParsedMIME isKindOfClass:[CTMIME_MessagePart class]]) {
|
||||
/* It's a message part, so let's set it's fields */
|
||||
struct mailimf_fields *fields;
|
||||
struct mailimf_mailbox *sender = (myFields->fld_sender != NULL) ? (myFields->fld_sender->snd_mb) : NULL;
|
||||
@@ -425,7 +468,7 @@ char * etpan_encode_mime_header(char * phrase)
|
||||
//TODO uh oh, when this get freed it frees stuff in the CTCoreMessage
|
||||
//TODO Need to make sure that fields gets freed somewhere
|
||||
fields = mailimf_fields_new_with_data(from, sender, replyTo, to, cc, bcc, inReplyTo, references, subject);
|
||||
[(CTMIME_MessagePart *)myParsedMIME setIMFFields:fields];
|
||||
[(CTMIME_MessagePart *)msgPart setIMFFields:fields];
|
||||
}
|
||||
return [myParsedMIME render];
|
||||
}
|
||||
|
||||
@@ -40,5 +40,6 @@
|
||||
+ (id)mimeMessagePartWithContent:(CTMIME *)mime;
|
||||
- (id)initWithContent:(CTMIME *)messageContent;
|
||||
- (void)setContent:(CTMIME *)aContent;
|
||||
- (CTMIME *)content;
|
||||
- (void)setIMFFields:(struct mailimf_fields *)imfFields;
|
||||
@end
|
||||
|
||||
@@ -77,7 +77,9 @@
|
||||
|
||||
- (struct mailmime *)buildMIMEStruct {
|
||||
struct mailmime *mime = mailmime_new_message_data([myMessageContent buildMIMEStruct]);
|
||||
mailmime_set_imf_fields(mime, myFields);
|
||||
if (myFields != NULL) {
|
||||
mailmime_set_imf_fields(mime, myFields);
|
||||
}
|
||||
return mime;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
*/
|
||||
|
||||
#import "CTMIME_MultiPart.h"
|
||||
#import "CTMIME_MessagePart.h"
|
||||
#import <libetpan/libetpan.h>
|
||||
#import "MailCoreTypes.h"
|
||||
#import "CTMIMEFactory.h"
|
||||
@@ -79,12 +80,13 @@
|
||||
- (struct mailmime *)buildMIMEStruct {
|
||||
//TODO make this smarter so it builds different types other than multipart/mixed
|
||||
struct mailmime *mime = mailmime_multiple_new("multipart/mixed");
|
||||
|
||||
|
||||
NSEnumerator *enumer = [myContentList objectEnumerator];
|
||||
|
||||
CTMIME *part;
|
||||
int r;
|
||||
while ((part = [enumer nextObject])) {
|
||||
r = mailmime_add_part(mime, [part buildMIMEStruct]);
|
||||
r = mailmime_smart_add_part(mime, [part buildMIMEStruct]);
|
||||
assert(r == 0);
|
||||
}
|
||||
return mime;
|
||||
|
||||
@@ -126,18 +126,35 @@
|
||||
|
||||
//TODO need to do content disposition
|
||||
- (struct mailmime *)buildMIMEStruct {
|
||||
struct mailmime_mechanism * encoding;
|
||||
struct mailmime_fields *mime_fields;
|
||||
struct mailmime *mime_sub;
|
||||
struct mailmime_content *content;
|
||||
int r;
|
||||
struct mailmime_disposition * disposition;
|
||||
|
||||
mime_fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_BASE64);
|
||||
encoding = mailmime_mechanism_new(MAILMIME_MECHANISM_BASE64, NULL);
|
||||
|
||||
// MIME Disposition
|
||||
disposition = mailmime_disposition_new_filename(MAILMIME_DISPOSITION_TYPE_ATTACHMENT, [self.filename cStringUsingEncoding:NSUTF8StringEncoding]);
|
||||
assert(disposition != NULL);
|
||||
|
||||
// MIME Fields using disposition
|
||||
// mailmime_fields_new_with_version(encoding, id, description, disposition, language);
|
||||
mime_fields = mailmime_fields_new_with_version(encoding, NULL, NULL, disposition, NULL);
|
||||
assert(mime_fields != NULL);
|
||||
|
||||
|
||||
// mime_fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_BASE64);
|
||||
// assert(mime_fields != NULL);
|
||||
|
||||
// MIME Content Type
|
||||
content = mailmime_content_new_with_str([self.contentType cStringUsingEncoding:NSUTF8StringEncoding]);
|
||||
assert(content != NULL);
|
||||
|
||||
mime_sub = mailmime_new_empty(content, mime_fields);
|
||||
assert(mime_sub != NULL);
|
||||
|
||||
// Add Data
|
||||
r = mailmime_set_body_text(mime_sub, (char *)[self.data bytes], [self.data length]);
|
||||
assert(r == MAILIMF_NO_ERROR);
|
||||
return mime_sub;
|
||||
|
||||
Reference in New Issue
Block a user