Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using mailcore (iOS), how could I get all emails from a specific email address?

Basically, I have an app that the user enters his email address and password, the app saves it, and then the user enters an email address of a friend, and I need the app to get all inbox emails of the user where the friend is the sender. At first, I thought I would get all emails and then extract the ones for the friend- problem is, this takes a TON of time.. For a user with 4000 emails, it takes above ten minutes.

MCOIMAPSession *session = [[MCOIMAPSession alloc] init];
session.hostname = @"imap.gmail.com";
session.port = 993;
session.username = @"[email protected]";
session.password = @"xxxx";
session.connectionType = MCOConnectionTypeTLS;

MCOIndexSet *uidSet = [MCOIndexSet indexSetWithRange:MCORangeMake(1,UINT64_MAX)];
MCOIMAPMessagesRequestKind requestKind = MCOIMAPMessagesRequestKindFullHeaders;

MCOIMAPFetchMessagesOperation *fetchOp =
[session fetchMessagesByUIDOperationWithFolder:@"INBOX"
                                   requestKind:requestKind
                                          uids:uidSet];

[fetchOp start:^(NSError *err, NSArray *msgs, MCOIndexSet *vanished) {

    for (int i = 0; i < [msgs count]; i++) {
        MCOIMAPMessage *m = msgs[i];

        MCOIMAPFetchContentOperation *operation = [session fetchMessageByUIDOperationWithFolder:@"INBOX" uid:m.uid];

        [operation start:^(NSError *error, NSData *data) {
            MCOMessageParser *messageParser = [[MCOMessageParser alloc] initWithData:data];

            NSString *msgHTMLBody = [messageParser htmlBodyRendering];
            NSLog(@"%i", i);
        }];
    }

}];

So, I really need some way to get all emails from a specific person. Is this possible? And if so, how could I do this? Thanks!

like image 989
maor10 Avatar asked Dec 05 '25 14:12

maor10


1 Answers

Use *+ (MCOIMAPSearchExpression *) searchFrom:(NSString )value

to get the list of messageUids with the fromAddress being the search result and then Fetch the mails of these messageUid List.

like image 83
Keerthi Shekar Avatar answered Dec 07 '25 03:12

Keerthi Shekar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!