                                 mailsDone++
                                 job.progress mailsDone, results.length
 
-                                if mailsToGo is mailsDone
+                                if mailsDone is results.length
                                     callback()
                                 else
                                     fetchOne(server, i + 1, results, mailsDone)
 
         else
             server.logout ->
-                if mailsToGo isnt mailsDone
+                if mailsDone isnt results.length
                     msg = "Could not import all the mail. Retry"
                     server.emit "error", new Error(msg)
 

                            activated: true
                            importing: true

                        @updateAttributes data, (err) ->
                            server.logout () ->
                                callback err
                    else
                        fetchOne server, results, i + 1, mailsDone, mailsToGo, maxId

                if error
                    server.logout -> server.emit "error", error
                else
                    #console.log "#{mailToBe.remoteId} id saved successfully"
                    mailsDone++
        
                    if mailsDone is mailsToGo
