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) -> 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) -> 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
}
1 Answer 1
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) -> 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.
-
\$\begingroup\$ Thank you for your feedback on the code style. :) I think I had found the root cause of my issue here: github.com/MailCore/mailcore2/issues/148#issuecomment-51481854 what should I do with this question then? \$\endgroup\$iamdavidlam– iamdavidlam2015年03月25日 07:56:50 +00:00Commented Mar 25, 2015 at 7:56
mailcore2
? \$\endgroup\$