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 { ...@@ -183,22 +183,29 @@ class MailSession {
listeners.append(listener) 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{ func findInJSonFileAndTest() -> Bool{
(hostname, port, connectionType, authType) = loadFromProviderJson() (hostname, port, connectionType, authType) = loadFromProviderJson()
if let h = hostname, let p = port, let con = connectionType { if let h = hostname, let p = port, let con = connectionType {
counter = MailSession.AUTHTYPE.count return findAndTestAuthType(hostname: h, port: p, connType: con)
success = false
for authType in MailSession.AUTHTYPE {
testServer(hostname: h, port: p, connectionType: con, authType: authType, completion: completionTestAuthType)
}
return true
} }
else { else {
return false 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: hostname, port: port, connectionType: connType, authType: authType, completion: completionTestAuthType)
}
return true
}
func findDefaultValuesAndTest() -> Bool { func findDefaultValuesAndTest() -> Bool {
_ = self.fillWithDefaultValues() _ = self.fillWithDefaultValues()
...@@ -354,6 +361,42 @@ class MailSession { ...@@ -354,6 +361,42 @@ class MailSession {
completionTestAuthType(error: error, smtpSession: smtpSession, imapSession: imapSession) 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?){ private func completionTestAuthType(error: MailServerConnectionError?, smtpSession: MCOSMTPSession?, imapSession: MCOIMAPSession?){
guard error == nil else { guard error == nil else {
counter = counter - 1 counter = counter - 1
......
...@@ -576,17 +576,72 @@ class Onboarding: NSObject { ...@@ -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
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 func checkIMAPConfig() { static private func setIMAPSession() -> MailSession {
let mailSession = MailSession(configSession: SessionType.IMAP, mailAddress: mailaddress.text!, password: password.text!, username: mailaddress.text) let mailSession = MailSession(configSession: SessionType.IMAP, mailAddress: mailaddress.text!, password: password.text!, username: mailaddress.text)
mailSession.addListener(listener: listenerIMAP) 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 let imap = imapSession, MailServerConnectionError.wrongServerConfig(errors: imap.errors) && Onboarding.credentialFails == 2 {
if !mailSession.findAndTestLong() { if !mailSession.findAndTestLong() {
imapCompletion(imapWorks: false) imapCompletion(imapWorks: false)
} }
}else { }
else if Onboarding.credentialFails >= 3{
checkDetailConfig(imap: true)
}
else {
if !mailSession.findInJSonFileAndTest() { if !mailSession.findInJSonFileAndTest() {
if !mailSession.findDefaultValuesAndTest() { if !mailSession.findDefaultValuesAndTest() {
if !mailSession.findAndTestLong() { if !mailSession.findAndTestLong() {
...@@ -595,17 +650,26 @@ class Onboarding: NSObject { ...@@ -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) let mailSession = MailSession(configSession: SessionType.SMTP, mailAddress: mailaddress.text!, password: password.text!, username: mailaddress.text)
mailSession.addListener(listener: listenerSMTP) 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 let imap = imapSession, MailServerConnectionError.wrongServerConfig(errors: imap.errors) {
if !mailSession.findAndTestLong() { if !mailSession.findAndTestLong() {
smtpCompletion(smtpWorks: false) smtpCompletion(smtpWorks: false)
} }
}else { }
else if Onboarding.credentialFails >= 3 {
checkDetailConfig(imap: false)
}
else {
if !mailSession.findInJSonFileAndTest() { if !mailSession.findInJSonFileAndTest() {
if !mailSession.findDefaultValuesAndTest() { if !mailSession.findDefaultValuesAndTest() {
if !mailSession.findAndTestLong() { if !mailSession.findAndTestLong() {
...@@ -614,7 +678,6 @@ class Onboarding: NSObject { ...@@ -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