Single mime parts now need to be fetched by hand
This commit is contained in:
@@ -135,6 +135,7 @@ char * etpan_encode_mime_header(char * phrase)
|
||||
[self _buildUpBodyText:[mime content] result:result];
|
||||
}
|
||||
else if ([mime isKindOfClass:[CTMIME_TextPart class]]) {
|
||||
[(CTMIME_TextPart *)mime fetchPart];
|
||||
[result appendString:[mime content]];
|
||||
}
|
||||
else if ([mime isKindOfClass:[CTMIME_MultiPart class]]) {
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
#import "CTMIME_SinglePart.h"
|
||||
|
||||
@interface CTMIME_ImagePart : CTMIME_SinglePart {
|
||||
NSImage *mImage;
|
||||
}
|
||||
- (id)content;
|
||||
- (void)setImage:(NSImage *)image;
|
||||
|
||||
@@ -33,23 +33,14 @@
|
||||
|
||||
|
||||
@implementation CTMIME_ImagePart
|
||||
- (id)initWithMIMEStruct:(struct mailmime *)mime forMessage:(struct mailmessage *)message {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
NSData *data = [self parsePart:mime forMessage:message];
|
||||
mImage = [[NSImage alloc] initWithData:data];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)content {
|
||||
return mImage;
|
||||
return [[[NSImage alloc] initWithData:self.data] autorelease];
|
||||
}
|
||||
|
||||
- (void)setImage:(NSImage *)image {
|
||||
[image release];
|
||||
[mImage release];
|
||||
mImage = image;
|
||||
// The data is all local, so we don't want it to do any fetching
|
||||
self.fetched = YES;
|
||||
//TODO Implement me
|
||||
}
|
||||
|
||||
- (struct mailmime *)buildMIMEStruct {
|
||||
@@ -79,9 +70,4 @@
|
||||
// assert(r == MAILIMF_NO_ERROR);
|
||||
// return mime_sub;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[mImage release];
|
||||
[super dealloc];
|
||||
}
|
||||
@end
|
||||
|
||||
@@ -33,6 +33,18 @@
|
||||
#import "CTMIME.h"
|
||||
|
||||
@interface CTMIME_SinglePart : CTMIME {
|
||||
struct mailmime *mMime;
|
||||
struct mailmessage *mMessage;
|
||||
|
||||
NSData *mData;
|
||||
BOOL mAttached;
|
||||
BOOL mFetched;
|
||||
NSString *mFilename;
|
||||
}
|
||||
- (NSData *)parsePart:(struct mailmime *)mime forMessage:(struct mailmessage *)message;
|
||||
@property BOOL attached;
|
||||
@property BOOL fetched;
|
||||
@property(retain) NSString *filename;
|
||||
@property(retain) NSData *data;
|
||||
|
||||
- (void)fetchPart;
|
||||
@end
|
||||
|
||||
+56
-27
@@ -35,34 +35,63 @@
|
||||
#import "MailCoreTypes.h"
|
||||
|
||||
@implementation CTMIME_SinglePart
|
||||
- (NSData *)parsePart:(struct mailmime *)mime forMessage:(struct mailmessage *)message {
|
||||
struct mailmime_single_fields *mimeFields = NULL;
|
||||
|
||||
int encoding = MAILMIME_MECHANISM_8BIT;
|
||||
mimeFields = mailmime_single_fields_new(mime->mm_mime_fields, mime->mm_content_type);
|
||||
if (mimeFields != NULL && mimeFields->fld_encoding != NULL)
|
||||
encoding = mimeFields->fld_encoding->enc_type;
|
||||
|
||||
char *fetchedData;
|
||||
size_t fetchedDataLen;
|
||||
int r = mailmessage_fetch_section(message, mime, &fetchedData, &fetchedDataLen);
|
||||
if (r != MAIL_NO_ERROR) {
|
||||
mailmessage_fetch_result_free(message, fetchedData);
|
||||
RaiseException(CTMIMEParseError, CTMIMEParseErrorDesc);
|
||||
}
|
||||
@synthesize attached=mAttached;
|
||||
@synthesize filename=mFilename;
|
||||
@synthesize data=mData;
|
||||
@synthesize fetched=mFetched;
|
||||
|
||||
size_t current_index = 0;
|
||||
char * result;
|
||||
size_t result_len;
|
||||
r = mailmime_part_parse(fetchedData, fetchedDataLen, ¤t_index, encoding, &result, &result_len);
|
||||
if (r != MAILIMF_NO_ERROR) {
|
||||
mailmime_decoded_part_free(result);
|
||||
RaiseException(CTMIMEParseError, CTMIMEParseErrorDesc);
|
||||
- (id)initWithMIMEStruct:(struct mailmime *)mime
|
||||
forMessage:(struct mailmessage *)message {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.attached = NO;
|
||||
self.filename = nil;
|
||||
self.data = nil;
|
||||
mMime = mime;
|
||||
mMessage = message;
|
||||
self.fetched = NO;
|
||||
}
|
||||
NSData *data = [NSData dataWithBytes:result length:result_len];
|
||||
mailmessage_fetch_result_free(message, fetchedData);
|
||||
mailmime_decoded_part_free(result);
|
||||
mailmime_single_fields_free(mimeFields);
|
||||
return data;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)fetchPart {
|
||||
if (self.fetched == NO) {
|
||||
struct mailmime_single_fields *mimeFields = NULL;
|
||||
|
||||
int encoding = MAILMIME_MECHANISM_8BIT;
|
||||
mimeFields = mailmime_single_fields_new(mMime->mm_mime_fields, mMime->mm_content_type);
|
||||
if (mimeFields != NULL && mimeFields->fld_encoding != NULL)
|
||||
encoding = mimeFields->fld_encoding->enc_type;
|
||||
|
||||
char *fetchedData;
|
||||
size_t fetchedDataLen;
|
||||
int r = mailmessage_fetch_section(mMessage, mMime, &fetchedData, &fetchedDataLen);
|
||||
if (r != MAIL_NO_ERROR) {
|
||||
mailmessage_fetch_result_free(mMessage, fetchedData);
|
||||
RaiseException(CTMIMEParseError, CTMIMEParseErrorDesc);
|
||||
}
|
||||
|
||||
size_t current_index = 0;
|
||||
char * result;
|
||||
size_t result_len;
|
||||
r = mailmime_part_parse(fetchedData, fetchedDataLen, ¤t_index, encoding, &result, &result_len);
|
||||
if (r != MAILIMF_NO_ERROR) {
|
||||
mailmime_decoded_part_free(result);
|
||||
RaiseException(CTMIMEParseError, CTMIMEParseErrorDesc);
|
||||
}
|
||||
NSData *data = [NSData dataWithBytes:result length:result_len];
|
||||
mailmessage_fetch_result_free(mMessage, fetchedData);
|
||||
mailmime_decoded_part_free(result);
|
||||
mailmime_single_fields_free(mimeFields);
|
||||
self.data = data;
|
||||
self.fetched = YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[mData release];
|
||||
[mFilename release];
|
||||
//The structs are held by CTCoreMessage so we don't have to free them
|
||||
[super dealloc];
|
||||
}
|
||||
@end
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
#import "CTMIME_SinglePart.h"
|
||||
|
||||
@interface CTMIME_TextPart : CTMIME_SinglePart {
|
||||
NSString *myString;
|
||||
}
|
||||
+ (id)mimeTextPartWithString:(NSString *)str;
|
||||
- (id)initWithString:(NSString *)string;
|
||||
|
||||
@@ -39,31 +39,23 @@
|
||||
return [[[CTMIME_TextPart alloc] initWithString:str] autorelease];
|
||||
}
|
||||
|
||||
- (id)initWithMIMEStruct:(struct mailmime *)mime forMessage:(struct mailmessage *)message {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
NSData *data = [self parsePart:mime forMessage:message];
|
||||
myString = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithString:(NSString *)string {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
myString = [string retain];
|
||||
[self setString:string];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)content {
|
||||
return myString;
|
||||
NSString *str = [[NSString alloc] initWithData:self.data encoding:NSASCIIStringEncoding];
|
||||
return [str autorelease];
|
||||
}
|
||||
|
||||
- (void)setString:(NSString *)str {
|
||||
[str retain];
|
||||
[myString release];
|
||||
myString = str;
|
||||
self.data = [str dataUsingEncoding:NSASCIIStringEncoding];
|
||||
// The data is all local, so we don't want it to do any fetching
|
||||
self.fetched = YES;
|
||||
}
|
||||
|
||||
- (struct mailmime *)buildMIMEStruct {
|
||||
@@ -89,13 +81,9 @@
|
||||
|
||||
mime_sub = mailmime_new_empty(content, mime_fields);
|
||||
assert(mime_sub != NULL);
|
||||
r = mailmime_set_body_text(mime_sub, strdup([myString cStringUsingEncoding:NSASCIIStringEncoding]), [myString length]);
|
||||
NSString *str = [self content];
|
||||
r = mailmime_set_body_text(mime_sub, strdup([str cStringUsingEncoding:NSASCIIStringEncoding]), [str length]);
|
||||
assert(r == MAILIMF_NO_ERROR);
|
||||
return mime_sub;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[myString release];
|
||||
[super dealloc];
|
||||
}
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user