Archived Forum Post

Index of archived forum posts

Question:

Fetching latest emails starts in middle

Sep 02 '14 at 16:56

I'm following this example for fetching oldest/newest emails in a loop to get the latests ones first, but it keep getting the emails from 64 and down, out a total of 116 emails.

http://www.example-code.com/ios/imap_fetchOldestNewest.asp

int numMessages = [[self NumMessages] intValue];

CkoEmail *newestEmail;
for (int emailNum = numMessages; emailNum > 0; emailNum--) {
    newestEmail = [self FetchSingle: [NSNumber numberWithInt:emailNum] bUid:YES];
    if (!(newestEmail == nil )) {
        NSLog(@"FromAddress: %@ Subject: %@", newestEmail.FromAddress, newestEmail.Subject);
    }
}

Am I doing something wrong? Because I copied and pasted the code from your examples, I just made it in a loop because the example pulls the latest email alone only. Thanks!


Accepted Answer

The 2nd argument to FetchSingle indicates whether the 1st argument is a UID or a sequence number. Given your code snippet, it is obvious you are passing sequence numbers, but you are incorrectly indicating UIDs (the 2nd are is bUid:YES. It should be bUid:NO)