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.61k stars 627 forks source link

How to find latest messageId in the mailcore? #1846

Closed chaurasiawadh closed 3 years ago

chaurasiawadh commented 4 years ago

I have 25 Lakh mails in my Gmail account but I want only the latest 7 days message or latest 100 mails only. How can I do it?

function getMails

IndexSet indexSet = IndexSet.indexSetWithRange(new Range(1, Long.MAX_VALUE));
    final IMAPFetchMessagesOperation messagesOperation = imapSession.fetchMessagesByUIDOperation(folder,
            requestKind, indexSet);

I want only 100 mails to get:

IndexSet indexSet = IndexSet.indexSetWithRange(new Range(Long.MAX_VALUE-100, Long.MAX_VALUE));
    final IMAPFetchMessagesOperation messagesOperation = imapSession.fetchMessagesByUIDOperation(folder,
            requestKind, indexSet);

But it's not working

tvPrincy commented 3 years ago

let folder : String = "[Gmail]/All Mail" let folderInfo = retSession.folderInfoOperation(folder)

folderInfo?.start({ error, info in let messageCount = info?.messageCount ?? 0 let messageCountData = UInt64(messageCount)

                var latest = 100
                var lowerbound = messageCount

                let uidset = MCOIndexSet(range: MCORangeMake(UInt64(lowerbound) - UInt64(latest), UInt64(latest)))

                let fetchOperation = retSession.fetchMessagesByNumberOperation(
                    withFolder: folder,
                    requestKind: MCOIMAPMessagesRequestKind.fullHeaders,
                    numbers: uidset)

})

haithngn commented 3 years ago

@chaurasiawadh IMAP server does not provide any func to retrieve this kind of data, you must combine message count and next UID to construct the MailCore operation parameter for your purpose.