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.59k stars 623 forks source link

How to remove important label in [Gmail]/Important folder ? #1954

Open sasinderann opened 1 year ago

sasinderann commented 1 year ago

Here is the chunk code I have used, It works if the folders are other than [Gmail]/important.

IMAPFolderQueue = OperationQueue() IMAPFolderQueue?.name = IMAPFolderQueuesNames.storeLabelsOperation.name() IMAPFolderQueue?.qualityOfService = .background let storeLabelsOperationQ = BlockOperation() let semaphore = DispatchSemaphore(value: 0)

    let uidSet =  MCOIndexSet()
    for uid in uids {
        uidSet.add(MCOIndexSet(index: UInt64(uid)))
    }

    storeLabelsOperationQ.addExecutionBlock {
        let storeLabelsOperation = self.mailCoreIMAPSession?.storeLabelsOperation(withFolder: folderPath, uids: uidSet, kind: kind, labels: labels)
        storeLabelsOperation?.start({ (error) in
            guard error == nil else {
                semaphore.signal()
                return
            }
            semaphore.signal()
            status = true
            return
        })
        semaphore.wait()
    }
    storeLabelsOperationQ.completionBlock = {
        getCompleted(status)
    }
    IMAPFolderQueue?.addOperation(storeLabelsOperationQ)

Thanks in advance !