Added a method sequenceNumberForUID to CTCoreFolder

This commit is contained in:
mronge@mronges-macbook-pro-15.local
2007-07-15 21:08:07 -07:00
parent 5b00fcc41b
commit b5dfa72a5e
4 changed files with 80 additions and 11 deletions
+9
View File
@@ -83,6 +83,15 @@
*/
- (BOOL)isUIDValid:(NSString *)uid;
/*!
@abstract Pulls the sequence number for the messag with the specified uid.
It does not perform UID validation, and the sequence ID is only
valid per session.
@param The uid for the message
@return > 1 if successful, 0 on err
*/
- (NSUInteger)sequenceNumberForUID:(NSString *)uid;
//FIXME What is this?
- (void)check;
+56 -7
View File
@@ -202,7 +202,7 @@
if (uid == nil)
uidnum = 0;
else
uidnum = (unsigned int)[[[uid componentsSeparatedByString:@"-"] objectAtIndex:1] doubleValue];
uidnum = (unsigned int)[[[uid componentsSeparatedByString:@"-"] objectAtIndex:1] unsignedIntegerValue];
mailmessage_driver *driver = imap_message_driver;
err = imap_get_messages_list([self imapSession], [self folderSession], driver, (uint32_t)uidnum+1, &msgList);
@@ -229,6 +229,54 @@
return messages;
}
- (NSUInteger)sequenceNumberForUID:(NSString *)uid {
//TODO check UID validity
//TODO factor out this duplicate code
int r;
struct mailimap_fetch_att * fetch_att;
struct mailimap_fetch_type * fetch_type;
struct mailimap_set * set;
clist * fetch_result;
//TODO factor this out
NSUInteger uidnum = (unsigned int)[[[uid componentsSeparatedByString:@"-"] objectAtIndex:1] doubleValue];
[self connect];
set = mailimap_set_new_single(uidnum);
if (set == NULL)
return 0;
fetch_type = mailimap_fetch_type_new_fetch_att_list_empty();
fetch_att = mailimap_fetch_att_new_uid();
r = mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att);
if (r != MAILIMAP_NO_ERROR) {
mailimap_fetch_att_free(fetch_att);
return 0;
}
r = mailimap_uid_fetch([self imapSession], set, fetch_type, &fetch_result);
if (r != MAIL_NO_ERROR) {
NSException *exception = [NSException
exceptionWithName:CTUnknownError
reason:[NSString stringWithFormat:@"Error number: %d",r]
userInfo:nil];
[exception raise];
}
mailimap_fetch_type_free(fetch_type);
mailimap_set_free(set);
if (r != MAILIMAP_NO_ERROR)
return 0; //Add exception
NSUInteger sequenceNumber = 0;
if (!clist_isempty(fetch_result)) {
struct mailimap_msg_att *msg_att = (struct mailimap_msg_att *)clist_nth_data(fetch_result, 0);
sequenceNumber = msg_att->att_number;
}
mailimap_fetch_list_free(fetch_result);
return sequenceNumber;
}
- (NSSet *)messageObjectsFromIndex:(unsigned int)start toIndex:(unsigned int)end {
struct mailmessage_list * env_list;
@@ -283,9 +331,6 @@
env_list = NULL;
r = uid_list_to_env_list(fetch_result, &env_list, [self folderSession], imap_message_driver);
mailimap_fetch_list_free(fetch_result);
r = mailfolder_get_envelopes_list(myFolder, env_list);
if (r != MAIL_NO_ERROR) {
if ( env_list != NULL )
@@ -301,18 +346,23 @@
int i;
CTCoreMessage *msgObject;
struct mailmessage *msg;
clistiter *fetchResultIter = clist_begin(fetch_result);
NSMutableSet *messages = [NSMutableSet set];
for(i=0; i<len; i++) {
msg = carray_get(env_list->msg_tab, i);
msgObject = [[CTCoreMessage alloc] initWithMessageStruct:msg];
struct mailimap_msg_att *msg_att = (struct mailimap_msg_att *)clist_content(fetchResultIter);
[msgObject setSequenceNumber:msg_att->att_number];
[messages addObject:msgObject];
[msgObject release];
fetchResultIter = clist_next(fetchResultIter);
}
if ( env_list != NULL ) {
//I am only freeing the message array because the messages themselves are in use
carray_free(env_list->msg_tab);
free(env_list);
}
}
mailimap_fetch_list_free(fetch_result);
return messages;
}
@@ -567,14 +617,13 @@ int uid_list_to_env_list(clist * fetch_result, struct mailmessage_list ** result
size_t size;
msg_att = clist_content(cur);
printf("number: %d\n", msg_att->att_number);
uid = 0;
size = 0;
for(item_cur = clist_begin(msg_att->att_list); item_cur != NULL; item_cur = clist_next(item_cur)) {
struct mailimap_msg_att_item * item;
item = clist_content(item_cur);
switch (item->att_type) {
case MAILIMAP_MSG_ATT_ITEM_STATIC:
switch (item->att_data.att_static->att_type) {
+9 -2
View File
@@ -16,6 +16,7 @@
struct mailmessage *myMessage;
struct mailimf_single_fields *myFields;
CTMIME *myParsedMIME;
NSUInteger mySequenceNumber;
}
//TODO Parse this stuff: message_id, inReplyTo, references, comments, keywords, headers
@@ -87,9 +88,15 @@
- (NSString *)uid;
/*!
@abstract Returns the message index, this number cannot be used across sessions
@abstract Returns the message sequence number, this number cannot be used across sessions
*/
- (NSUInteger)indexNumber;
- (NSUInteger)sequenceNumber;
/*!
@abstract Set the message sequence number, this will NOT set any thing on the server.
This is used to assign sequence numbers after retrieving the message list.
*/
- (void)setSequenceNumber:(NSUInteger)sequenceNumber;
/*!
@abstract Parses the from list, the result is an NSSet containing CTCoreAddress's
+6 -2
View File
@@ -164,8 +164,12 @@
return [NSString stringWithCString:myMessage->msg_uid encoding:NSASCIIStringEncoding];
}
- (NSUInteger)indexNumber {
return myMessage->msg_index;
- (NSUInteger)sequenceNumber {
return mySequenceNumber;
}
- (void)setSequenceNumber:(NSUInteger)sequenceNumber {
mySequenceNumber = sequenceNumber;
}