MailCore / mailcore2

MailCore 2 provide a simple and asynchronous API to work with e-mail protocols IMAP, POP and SMTP. The API has been redesigned from ground up.
Other
2.58k stars 623 forks source link

[Bug] - App Crash on 'fetchMessagesByUIDOperationWithFolder:requestKind:uids: #2000

Open karam28 opened 3 months ago

karam28 commented 3 months ago

Summary I'm utilizing MailCore2 via CocoaPods. After copying the Objective-C code, my application crashes upon running. The crash is associated with a deprecated method mentioned in the warning from Xcode: 'fetchMessagesByUIDOperationWithFolder:requestKind:uids:'.

Platform(s)

<iOS>

Happens on Mail Server

<Yahoo>

Piece of code

    MCOIMAPSession *session = [[MCOIMAPSession alloc] init];
    [session setHostname:@"imap.mail.yahoo.com"];
    [session setPort:993];
    [session setUsername:@"xxx@yahoo.com"];
    [session setPassword:@"xxxx"];
    [session setConnectionType:MCOConnectionTypeTLS];

    MCOIMAPMessagesRequestKind requestKind = MCOIMAPMessagesRequestKindHeaders;
    NSString *folder = @"INBOX";
    MCOIndexSet *uids = [MCOIndexSet indexSetWithRange:MCORangeMake(1, UINT64_MAX)];

    MCOIMAPFetchMessagesOperation *fetchOperation = [session fetchMessagesByUIDOperationWithFolder:folder requestKind:requestKind uids:uids];

    [fetchOperation start:^(NSError * error, NSArray * fetchedMessages, MCOIndexSet * vanishedMessages) {
        //We've finished downloading the messages!

        //Let's check if there was an error:
        if(error) {
            NSLog(@"Error downloading message headers:%@", error);
        }

        //And, let's print out the messages...
        NSLog(@"The post man delivereth:%@", fetchedMessages);
    }];

Actual outcome it should not crash. Please provide the updated method and update that in your documentation also.

Connection Logs


**Expected outcome**

**Link to sample code on GitHub reproducing the issue (a full Xcode project):**
karam28 commented 3 months ago

I find the updated method I think but it's crashing and no reason mention. here is the crash Thread 5: EXC_BREAKPOINT (code=1, subcode=0x20fc0f374)

MCOIMAPSession *session = [[MCOIMAPSession alloc] init];
    session.hostname = @"imap.mail.yahoo.com";
    session.port = 993;
    session.username = @"karamjeetsinghbuttar@yahoo.com";
    session.password = @"ybykuvrpfxqswxqo ";
    session.connectionType = MCOConnectionTypeTLS;

    MCOIndexSet *uidSet = [MCOIndexSet indexSetWithRange:MCORangeMake(1,UINT64_MAX)];
  MCOIMAPFetchMessagesOperation * op = [session fetchMessagesOperationWithFolder:@"INBOX"
                                                                       requestKind:MCOIMAPMessagesRequestKindHeaders | MCOIMAPMessagesRequestKindStructure
                                                                              uids:uidSet];
    [op start:^(NSError * error, NSArray * messages, MCOIndexSet * vanishedMessages) {
       for(MCOIMAPMessage * msg in messages) {
         NSLog(@" mails-- %lu: %@", [msg uid], [msg header]);
       }
    }];