Deleting email using mailcore with imapSession The following function works fine. However, deleting 1 mail takes about 4 seconds (from start of operation to the firing of the completion handler). 

Currently, using mailcore2, copying mails on the Gmail server.

Are there any significant issues?

func deleteOnServer (indexSet: MCOIndexSet) {
     NSLog("will delete email")
     let sessionForOperation = getSessionForOperation()
     let localCopyMessageOperation = sessionForOperation.copyMessagesOperationWithFolder("INBOX", uids: indexSet, destFolder: account.trashFolderPath)
     localCopyMessageOperation!.start { (error, uidMapping) -&gt; Void in
            if let error = error {
                NSLog("error in deleting email : \(error.userInfo!)")
            } else {
                NSLog("email deleted")
            }
        }
    }

}


My session is configured as follows:

    func createNewIMAPSessionWith(userName: String, hostname: String, oauth2Token: String) -&gt; MCOIMAPSession {
        let retSession =  MCOIMAPSession()
        retSession.hostname = hostname
        retSession.port = 993
        retSession.username = userName
        retSession.OAuth2Token = oauth2Token
        retSession.authType = MCOAuthType.XOAuth2
        retSession.connectionType = MCOConnectionType.TLS
        retSession.maximumConnections = 2
        retSession.timeout = NSTimeInterval(60)
        retSession.allowsFolderConcurrentAccessEnabled = true

        return retSession
}
I don't know anything about mailcore2, nor have you provided any Time Profiler information to help narrow down what takes so long to complete the action (is it just a slow network, or is it something in your code?  Anyone's guess), so I can't really address the slowness issue.  I also don't have a clue which methods are yours versus what you simply get from mailcore2, but with that said...

NSLog() statements should almost always be wrapped in #if DEBUG and #endif statements.

Moreover, regardless of whether or not the deletion is successfully, we need to let the user know one way or the other, and NSLog() isn't going to cut it.

I'm not sure how the second code snippet ties to the first, but all of our methods could use better names.

deleteOnServer(indexSet:) - delete what?  on which server?  What does index set represent?



createNewIMAPSessionWith - the words New and With can both be removed from this method.  Although, what would probably be best is simply creating a factory method:

extension MCOIMAPSession {
    class func session(userName: String, hostname: String, oauth2Token: String) -&gt; MCOIMAPSession {
        // all the code you're already doing
    }
}


And then we call it simply like this:

let imapSession = MCOIMAPSession.session(userName:"username", hostname:"hostname", oauth2Token:"token")





localCopyMessageOperation!.start 



This is a pretty big no-no, in my opinion.  If the method we're calling to get localCopyMessageOperation returns an optional, then we should use real optional chaining, not forced unwrapping.  It's as simple as changing the exclamation point to a question mark and it prevents an "found nil when unwrapping" (or whatever it's called) exception.