Skip to content
Snippets Groups Projects
Commit 24b16a5b authored by Oliver Wiese's avatar Oliver Wiese
Browse files

update server config check in detailOnboarding

parent 64fdb97c
No related branches found
No related tags found
No related merge requests found
......@@ -183,22 +183,29 @@ class MailSession {
listeners.append(listener)
}
func testConfig(host: String, port: UInt32, authType: MCOAuthType, connType: MCOConnectionType) {
testServer(hostname: host, port: port, connectionType: connType, authType: authType, completion: completionTestConfig)
}
func findInJSonFileAndTest() -> Bool{
(hostname, port, connectionType, authType) = loadFromProviderJson()
if let h = hostname, let p = port, let con = connectionType {
return findAndTestAuthType(hostname: h, port: p, connType: con)
}
else {
return false
}
}
private func findAndTestAuthType(hostname: String, port: UInt32, connType: MCOConnectionType) -> Bool {
counter = MailSession.AUTHTYPE.count
success = false
for authType in MailSession.AUTHTYPE {
testServer(hostname: h, port: p, connectionType: con, authType: authType, completion: completionTestAuthType)
testServer(hostname: hostname, port: port, connectionType: connType, authType: authType, completion: completionTestAuthType)
}
return true
}
else {
return false
}
}
func findDefaultValuesAndTest() -> Bool {
_ = self.fillWithDefaultValues()
......@@ -354,6 +361,42 @@ class MailSession {
completionTestAuthType(error: error, smtpSession: smtpSession, imapSession: imapSession)
}
private func completionTestConfig(error: MailServerConnectionError?, smtpSession: MCOSMTPSession?, imapSession: MCOIMAPSession?) {
if let e = error {
if e == MailServerConnectionError.AuthenticationError || e == MailServerConnectionError.NoInternetconnection {
errors.insert(e)
for l in listeners {
l.testFinish(result: false)
}
}
else {
var host: String
var port: UInt32
var connType: MCOConnectionType
if let imap = imapSession {
host = imap.hostname
port = imap.port
connType = imap.connectionType
_ = findAndTestAuthType(hostname: host, port: port, connType: connType)
}
else if let smtp = smtpSession {
host = smtp.hostname
port = smtp.port
connType = smtp.connectionType
_ = findAndTestAuthType(hostname: host, port: port, connType: connType)
}
else {
errors.insert(e)
for l in listeners {
l.testFinish(result: false)
}
}
}
return
}
completionTestAuthType(error: error, smtpSession: smtpSession, imapSession: imapSession)
}
private func completionTestAuthType(error: MailServerConnectionError?, smtpSession: MCOSMTPSession?, imapSession: MCOIMAPSession?){
guard error == nil else {
counter = counter - 1
......
......@@ -576,17 +576,72 @@ class Onboarding: NSObject {
}
}
static private func checkDetailConfig(imap: Bool) {
if let imapHost = imapServer.text, let imapPortString = imapPort.text, let smtpHost = smtpServer.text, let smtpPortString = smtpPort.text, let smtpPort = Int(smtpPortString), let imapPort = Int(imapPortString) {
let imapAuthName = imapTransDataDelegate.pickedValue
let imapConName = imapTransDataDelegate.pickedValue
let smtpConnName = smtpTransDataDelegate.pickedValue
let smtpAuthName = smtpAuthDataDelegate.pickedValue
var imapAuthValue = 0
var imapConnValue = 0
var smtpAuthValue = 0
var smtpConnValue = 0
static func checkIMAPConfig() {
for (value, name) in Onboarding.authenticationRows {
if name == imapAuthName {
imapAuthValue = value
}
if name == smtpAuthName {
smtpAuthValue = value
}
}
for (value, name) in Onboarding.transportRows {
if name == imapConName {
imapConnValue = value
}
if name == smtpConnName {
smtpConnValue = value
}
}
if imap {
if imapSession == nil {
_ = setIMAPSession()
}
if let imap = imapSession {
imap.testConfig(host: imapHost, port: UInt32(imapPort), authType: MCOAuthType.init(rawValue: imapAuthValue), connType: MCOConnectionType.init(rawValue: imapConnValue))
}
}
else {
if smtpSession == nil {
_ = setSMTPSession()
}
if let smtp = smtpSession {
smtp.testConfig(host: smtpHost, port: UInt32(smtpPort), authType: MCOAuthType.init(rawValue: smtpAuthValue), connType: MCOConnectionType.init(rawValue: smtpConnValue))
}
}
}
}
static private func setIMAPSession() -> MailSession {
let mailSession = MailSession(configSession: SessionType.IMAP, mailAddress: mailaddress.text!, password: password.text!, username: mailaddress.text)
mailSession.addListener(listener: listenerIMAP)
Onboarding.imapSession = mailSession
return mailSession
}
static func checkIMAPConfig() {
let mailSession = setIMAPSession()
if let imap = imapSession, MailServerConnectionError.wrongServerConfig(errors: imap.errors) && Onboarding.credentialFails == 2 {
if !mailSession.findAndTestLong() {
imapCompletion(imapWorks: false)
}
}else {
}
else if Onboarding.credentialFails >= 3{
checkDetailConfig(imap: true)
}
else {
if !mailSession.findInJSonFileAndTest() {
if !mailSession.findDefaultValuesAndTest() {
if !mailSession.findAndTestLong() {
......@@ -595,17 +650,26 @@ class Onboarding: NSObject {
}
}
}
Onboarding.imapSession = mailSession
}
static func checkSMTPConfig() {
static private func setSMTPSession() -> MailSession{
let mailSession = MailSession(configSession: SessionType.SMTP, mailAddress: mailaddress.text!, password: password.text!, username: mailaddress.text)
mailSession.addListener(listener: listenerSMTP)
Onboarding.smtpSession = mailSession
return mailSession
}
static func checkSMTPConfig() {
let mailSession = setSMTPSession()
if let imap = imapSession, MailServerConnectionError.wrongServerConfig(errors: imap.errors) {
if !mailSession.findAndTestLong() {
smtpCompletion(smtpWorks: false)
}
}else {
}
else if Onboarding.credentialFails >= 3 {
checkDetailConfig(imap: false)
}
else {
if !mailSession.findInJSonFileAndTest() {
if !mailSession.findDefaultValuesAndTest() {
if !mailSession.findAndTestLong() {
......@@ -614,7 +678,6 @@ class Onboarding: NSObject {
}
}
}
Onboarding.smtpSession = mailSession
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment