Discussion:
Loading messages from the cache
Gus Mueller
2010-01-28 19:04:24 UTC
Permalink
So I've got the cache files being written out right now in Crashy, and they are loaded up when you start (assuming you've already connected once and pulled messages down). One thing that isn't working correctly however, is LBMessage's initWithFileAtPath: . For some reason, the data isn't loaded the same as when it is when it's loaded directly off the IMAP server. I haven't had a chance to figure out why yet, but this seems like something someone could try and do. Right now LBMessage uses libEtPan to load the message. It doesn't need to though- If you think you've got a better way load a multipart mime message up, go for it.

It's also be awesome if some extra methods could be added to LBMessage, for getting sent date, received date, etc. And maybe a method for getting a list off all the headers.

let me (or the list) know if you'd like to tackle this.

thanks,

-gus

--

August 'Gus' Mueller
Flying Meat Inc.
http://flyingmeat.com/
DINH Viêt Hoà
2010-01-28 22:38:25 UTC
Permalink
So I've got the cache files being written out right now in Crashy, and they are loaded up when you start (assuming you've already connected once and pulled messages down).  One thing that isn't working correctly however, is LBMessage's initWithFileAtPath: .  For some reason, the data isn't loaded the same as when it is when it's loaded directly off the IMAP server.  I haven't had a chance to figure out why yet, but this seems like something someone could try and do.  Right now LBMessage uses libEtPan to load the message.  It doesn't need to though- If you think you've got a better way load a multipart mime message up, go for it.
It's also be awesome if some extra methods could be added to LBMessage, for getting sent date, received date, etc.  And maybe a method for getting a list off all the headers.
let me (or the list) know if you'd like to tackle this.
I think that the caveat is that UTF-8 is referenced in those two methods:

- (id)initWithFileAtPath:(NSString *)path {
return [self initWithString:[NSString
stringWithContentsOfFile:path encoding:NSUTF8StringEncoding
error:NULL]];
}

- (id)initWithString:(NSString *)msgData {
struct mailmessage *msg = data_message_init((char *)[msgData
cStringUsingEncoding:NSUTF8StringEncoding], [msgData
lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
int err;
struct mailmime *dummyMime;
/* mailmessage_get_bodystructure will fill the mailmessage struct for us */
err = mailmessage_get_bodystructure(msg, &dummyMime);
assert(err == 0);
return [self initWithMessageStruct:msg];
}

- initWithString: should be called - initWithData: and should take a
NSData as argument.
we should read in initWithData()
data_message_init([msgData bytes], [msgData length])

Is this crashy because of [NSString stringWithContentsOfFile:path
encoding:NSUTF8StringEncoding error:NULL] being nil ?
--
DINH Viêt Hoà
Gus Mueller
2010-01-30 04:44:27 UTC
Permalink
Post by DINH Viêt Hoà
Post by Gus Mueller
So I've got the cache files being written out right now in Crashy, and they are loaded up when you start (assuming you've already connected once and pulled messages down). One thing that isn't working correctly however, is LBMessage's initWithFileAtPath: . For some reason, the data isn't loaded the same as when it is when it's loaded directly off the IMAP server. I haven't had a chance to figure out why yet, but this seems like something someone could try and do. Right now LBMessage uses libEtPan to load the message. It doesn't need to though- If you think you've got a better way load a multipart mime message up, go for it.
It's also be awesome if some extra methods could be added to LBMessage, for getting sent date, received date, etc. And maybe a method for getting a list off all the headers.
let me (or the list) know if you'd like to tackle this.
- (id)initWithFileAtPath:(NSString *)path {
return [self initWithString:[NSString
stringWithContentsOfFile:path encoding:NSUTF8StringEncoding
error:NULL]];
}
- (id)initWithString:(NSString *)msgData {
struct mailmessage *msg = data_message_init((char *)[msgData
cStringUsingEncoding:NSUTF8StringEncoding], [msgData
lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
int err;
struct mailmime *dummyMime;
/* mailmessage_get_bodystructure will fill the mailmessage struct for us */
err = mailmessage_get_bodystructure(msg, &dummyMime);
assert(err == 0);
return [self initWithMessageStruct:msg];
}
- initWithString: should be called - initWithData: and should take a
NSData as argument.
we should read in initWithData()
data_message_init([msgData bytes], [msgData length])
Why would this make a difference? data_message_init takes a char* after all..
Post by DINH Viêt Hoà
Is this crashy because of [NSString stringWithContentsOfFile:path
encoding:NSUTF8StringEncoding error:NULL] being nil ?
Ahem.

Maybe.

-gus

--

August 'Gus' Mueller
Flying Meat Inc.
http://flyingmeat.com/
DINH Viêt Hoà
2010-01-30 13:24:41 UTC
Permalink
Post by DINH Viêt Hoà
So I've got the cache files being written out right now in Crashy, and they are loaded up when you start (assuming you've already connected once and pulled messages down).  One thing that isn't working correctly however, is LBMessage's initWithFileAtPath: .  For some reason, the data isn't loaded the same as when it is when it's loaded directly off the IMAP server.  I haven't had a chance to figure out why yet, but this seems like something someone could try and do.  Right now LBMessage uses libEtPan to load the message.  It doesn't need to though- If you think you've got a better way load a multipart mime message up, go for it.
It's also be awesome if some extra methods could be added to LBMessage, for getting sent date, received date, etc.  And maybe a method for getting a list off all the headers.
let me (or the list) know if you'd like to tackle this.
- (id)initWithFileAtPath:(NSString *)path {
   return [self initWithString:[NSString
stringWithContentsOfFile:path encoding:NSUTF8StringEncoding
error:NULL]];
}
- (id)initWithString:(NSString *)msgData {
   struct mailmessage *msg = data_message_init((char *)[msgData
cStringUsingEncoding:NSUTF8StringEncoding],  [msgData
lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
   int err;
   struct mailmime *dummyMime;
   /* mailmessage_get_bodystructure will fill the mailmessage struct for us */
   err = mailmessage_get_bodystructure(msg, &dummyMime);
   assert(err == 0);
   return [self initWithMessageStruct:msg];
}
- initWithString: should be called - initWithData: and should take a
NSData as argument.
we should read in initWithData()
data_message_init([msgData bytes], [msgData length])
Why would this make a difference?  data_message_init takes a char* after all..
interpreting a char * as UTF8 can fail, sometimes because it's
iso-8859-1. Think about "DINH Viêt Hoà" being encoding in different
kind of charset encoding.
Then, - [NSString stringWithContentsOfFile:encoding:error] may return
nil in this case (it can be destructive).

whereas interpreting char * as NSData will always succeed and will be
non-destructive.
Do you have the example of message failing for this case ?

Regards,
--
DINH Viêt Hoà
Loading...