0
votes

I am using mailCore to fetch emails from server. I am done with session setup and basic flow. Now i am stuck in a minor problem and i am unable to figure it out.

Here is code of fetching email headers

    let folder: String = "Inbox"
    let folderInfoFetch : MCOIMAPFolderInfoOperation = imapSession.folderInfoOperation(folder)
    folderInfoFetch.start { (error, folderInfo) in

        if (error == nil) {
            var numberOfMessages : Int32 = Int32(30)
            numberOfMessages -= 1

            let request: MCOIMAPMessagesRequestKind = .headers
            let messagesNumbers = MCOIndexSet.init(range: MCORange.init(location: UInt64(abs((folderInfo?.messageCount)!-numberOfMessages)) , length: UInt64(numberOfMessages)))
            let fetch : MCOIMAPFetchMessagesOperation = self.imapSession.fetchMessagesByNumberOperation(withFolder: folder, requestKind: request, numbers: messagesNumbers)
            fetch.start({ (error, fetchedMessages, vanishedMessages) in
                if(error != nil)
                {
                    print("Error downloading message headers: \(String(describing: error))")

                } else {
                    if let mails = fetchedMessages as? [MCOIMAPMessage] {
                        print(mails)

                    }
                }
            })
        }

This code is successfully returning mail headers. But read/unread flags are missing in this. I have seen many solutions of this problem but they all in objective c.

i-e

MCOIMAPMessagesRequestKind requestKind = MCOIMAPMessagesRequestKindHeaders | MCOIMAPMessagesRequestKindFlags

It's solution is to send multiple types of flags in request. But how i can achieve this in swift ? Any help will be appreciated!

Solution Link : https://github.com/MailCore/mailcore2/issues/409

2
were you able to get header like- "ARC-Authentication-Results" and "Return-Path". We are trying to get that from emails. May you please help. - Sumit

2 Answers

0
votes

So after banging my head the only solution which worked for me is append flags by taking its union.

            let kind = MCOIMAPMessagesRequestKind()
            let headers = kind.union(MCOIMAPMessagesRequestKind.headers)
            let request = headers.union(MCOIMAPMessagesRequestKind.flags)

I know it's not best but it worked for me.

0
votes

In swift4.2, I achieved this with the following syntax:

let requestKind: MCOIMAPMessagesRequestKind = [.headers, .flags]