3
\$\begingroup\$

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
}
nhgrif
25.4k3 gold badges64 silver badges129 bronze badges
asked Mar 23, 2015 at 5:26
\$\endgroup\$
5
  • \$\begingroup\$ It will be very difficult to address your primary concerns with such little context provided. \$\endgroup\$ Commented Mar 23, 2015 at 10:28
  • \$\begingroup\$ @jamal May be I'm asking on the wrong site then. i don't believe xcode ship with libraries to interact with IMAP sessions out of the box. Hence, I believe my issue, if there is, is in the incorrect way of utilizing specific functions in the library Mailcore Or perhaps my session configurations. \$\endgroup\$ Commented Mar 23, 2015 at 11:39
  • \$\begingroup\$ @nhgrif how may i provide more context? :) I'd love to learn to ask better questions. \$\endgroup\$ Commented Mar 23, 2015 at 11:46
  • \$\begingroup\$ Do you want a full review or are you only concerned with the slowness of mailcore2? \$\endgroup\$ Commented Mar 23, 2015 at 11:49
  • \$\begingroup\$ any feedback on the style of code / the way I asked the question will be be greatly appreciated. \$\endgroup\$ Commented Mar 23, 2015 at 11:51

1 Answer 1

1
\$\begingroup\$

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.

answered Mar 23, 2015 at 21:52
\$\endgroup\$
1

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.