diff --git a/enzevalos_iphone/AuthenticationScreen.swift b/enzevalos_iphone/AuthenticationScreen.swift index d22b410dc04373ae4c9e96321d2cb0a988ea19e1..494b2c215d2da8f8acd621126ee854743b709667 100644 --- a/enzevalos_iphone/AuthenticationScreen.swift +++ b/enzevalos_iphone/AuthenticationScreen.swift @@ -20,7 +20,6 @@ struct AuthenticationScreen: View { @State private var smtpEncryption = 0 @ObservedObject private var viewModel = AuthenticationViewModel(authenticationModel: AuthenticationModel.instance) - var encryptionOptions = ["Plaintext", "StartTLS", "TLS/SSL"] var body: some View { ScrollView { @@ -41,7 +40,7 @@ struct AuthenticationScreen: View { } Spacer() Button(action: {self.viewModel.isDetailedAuthentication ? - self.viewModel.detailValidation(self.login, self.password, self.username, self.imapServer, self.imapPort, self.imapEncryption, self.smtpServer, self.smtpPort, self.smtpEncryption) : + self.viewModel.detailValidation(self.login, self.password, self.username, self.imapServer, self.imapPort, AuthenticationViewModel.encryptionOptions[self.imapEncryption].value, self.smtpServer, self.smtpPort, AuthenticationViewModel.encryptionOptions[self.smtpEncryption].value) : self.viewModel.validate(self.login, self.password) }) { Text("Login") @@ -61,8 +60,8 @@ struct AuthenticationScreen: View { TextField("e.g. 993", text:self.$imapPort).keyboardType(.numberPad) } Picker(selection: self.$imapEncryption, label: Text("IMAP-Transportencryption")) { - ForEach(0..<self.encryptionOptions.count) { - Text(self.encryptionOptions[$0]) + ForEach(0..<AuthenticationViewModel.encryptionOptions.count) { + Text(AuthenticationViewModel.encryptionOptions[$0].name) } } HStack { @@ -75,8 +74,8 @@ struct AuthenticationScreen: View { } Picker(selection: self.$smtpEncryption, label: Text("SMTP-Transportencryption")) { - ForEach(0..<self.encryptionOptions.count) { - Text(self.encryptionOptions[$0]) + ForEach(0..<AuthenticationViewModel.encryptionOptions.count) { + Text(AuthenticationViewModel.encryptionOptions[$0].name) } } } diff --git a/enzevalos_iphone/AuthenticationViewModel.swift b/enzevalos_iphone/AuthenticationViewModel.swift index 01464b9c24ce7eacef44117bca17921af41b2f91..7679b3e4606b16cb263d1de7e704fe692f8a56fc 100644 --- a/enzevalos_iphone/AuthenticationViewModel.swift +++ b/enzevalos_iphone/AuthenticationViewModel.swift @@ -17,6 +17,8 @@ class AuthenticationViewModel : ObservableObject { let model: AuthenticationModel var cancellable: AnyCancellable? + + static let encryptionOptions: [(name: String, value: Int)] = [(name: "Plaintext", value: MCOConnectionType.clear.rawValue), (name: "StartTLS", value: MCOConnectionType.startTLS.rawValue), (name: "TLS/SSL", value: MCOConnectionType.TLS.rawValue)] init(authenticationModel: AuthenticationModel) { self.model = authenticationModel @@ -40,7 +42,7 @@ class AuthenticationViewModel : ObservableObject { } func detailValidation(_ login: String, _ password: String, _ username: String, _ imapServer: String, _ imapPort: String, _ imapEncryption: Int, _ smtpServer: String, _ smtpPort: String, _ smtpEncryption: Int) -> Void { - let mailAccount = MailAccount(emailAddress: login, password: password, username: username, imapServer: imapServer, imapPort: Int(imapPort)!, imapEncryption: 1 << imapEncryption, smtpServer: smtpServer, smtpPort: Int(smtpPort)!, smtpEncryption: 1 << smtpEncryption) + let mailAccount = MailAccount(emailAddress: login, password: password, username: username, imapServer: imapServer, imapPort: Int(imapPort)!, imapEncryption: imapEncryption, smtpServer: smtpServer, smtpPort: Int(smtpPort)!, smtpEncryption: smtpEncryption) showProgressSpinner = true cancellable = model.checkConfig(mailAccount: mailAccount, extendedValidation: true).sink { promise in @@ -68,7 +70,10 @@ class AuthenticationViewModel : ObservableObject { print("Google authetication failed") return } - let mailAccount = MailAccount(emailAddress: userEmail.lowercased(), password: "", username: userEmail.lowercased(), imapServer: "imap.gmail.com", imapPort: 993, imapEncryption: 1 << 2, smtpServer: "smtp.gmail.com", smtpPort: 587, smtpEncryption: 1 << 1, authType: MCOAuthType.xoAuth2.rawValue) + let googleImapPort = 993 + let googleSmtpPort = 587 + + let mailAccount = MailAccount(emailAddress: userEmail.lowercased(), password: "", username: userEmail.lowercased(), imapServer: "imap.gmail.com", imapPort: googleImapPort, imapEncryption: AuthenticationViewModel.encryptionOptions[2].value, smtpServer: "smtp.gmail.com", smtpPort: googleSmtpPort, smtpEncryption: AuthenticationViewModel.encryptionOptions[1].value, authType: MCOAuthType.xoAuth2.rawValue) self.showProgressSpinner = true self.cancellable = self.model.checkConfig(mailAccount: mailAccount, extendedValidation: true).sink { promise in