Переглянути джерело

adapt to new server_flags/mail_security/send_security api

B. Petersen 4 роки тому
батько
коміт
e22bb8e306

+ 0 - 26
DcCore/DcCore/DC/Wrapper.swift

@@ -521,20 +521,6 @@ public class DcContext {
         }
     }
 
-    public func setImapSecurity(imapFlags flags: Int) {
-        var sf = serverFlags
-        sf = sf & ~0x700 // DC_LP_IMAP_SOCKET_FLAGS
-        sf = sf | flags
-        serverFlags = sf
-    }
-
-    public func setSmtpSecurity(smptpFlags flags: Int) {
-        var sf = serverFlags
-        sf = sf & ~0x70000 // DC_LP_SMTP_SOCKET_FLAGS
-        sf = sf | flags
-        serverFlags = sf
-    }
-
     public func setAuthFlags(flags: Int) {
         var sf = serverFlags
         sf = sf & ~0x6 // DC_LP_AUTH_FLAGS
@@ -542,18 +528,6 @@ public class DcContext {
         serverFlags = sf
     }
 
-    public func getImapSecurity() -> Int {
-        var sf = serverFlags
-        sf = sf & 0x700 // DC_LP_IMAP_SOCKET_FLAGS
-        return sf
-    }
-
-    public func getSmtpSecurity() -> Int {
-        var sf = serverFlags
-        sf = sf & 0x70000  // DC_LP_SMTP_SOCKET_FLAGS
-        return sf
-    }
-
     public func getAuthFlags() -> Int {
         var sf = serverFlags
         sf = sf & 0x6 // DC_LP_AUTH_FLAGS

+ 11 - 19
deltachat-ios/Controller/AccountSetup/SecuritySettingsController.swift

@@ -3,7 +3,7 @@ import DcCore
 
 class SecuritySettingsController: UITableViewController {
 
-    private var options: [Int]
+    private var options: [Int32] = [DC_SOCKET_AUTO, DC_SOCKET_SSL, DC_SOCKET_STARTTLS, DC_SOCKET_PLAIN]
 
     private var selectedIndex: Int
 
@@ -23,7 +23,7 @@ class SecuritySettingsController: UITableViewController {
     private var staticCells: [UITableViewCell] {
         return options.map {
             let cell = UITableViewCell(style: .default, reuseIdentifier: nil)
-            cell.textLabel?.text = SecurityConverter.convertHexToString(type: self.securityType, hex: $0)
+            cell.textLabel?.text = SecurityConverter.getSocketName(value: $0)
             cell.selectionStyle = .none
             return cell
         }
@@ -34,11 +34,9 @@ class SecuritySettingsController: UITableViewController {
         self.dcContext = dcContext
         switch securityType {
         case .IMAPSecurity:
-            options = [0x00, 0x100, 0x200, 0x400]
-            selectedIndex = options.index(of: dcContext.getImapSecurity()) ?? 0
+            selectedIndex = options.index(of: Int32(dcContext.getConfigInt("mail_security"))) ?? 0
         case .SMTPSecurity:
-            options = [0x00, 0x10000, 0x20000, 0x40000]
-            selectedIndex = options.index(of: dcContext.getSmtpSecurity()) ?? 0
+            selectedIndex = options.index(of: Int32(dcContext.getConfigInt("send_security"))) ?? 0
         }
         super.init(style: .grouped)
         self.title = title
@@ -89,9 +87,9 @@ class SecuritySettingsController: UITableViewController {
     @objc func okButtonPressed() {
         switch securityType {
         case .IMAPSecurity:
-            dcContext.setImapSecurity(imapFlags: options[selectedIndex])
+            dcContext.setConfigInt("mail_security", Int(options[selectedIndex]))
         case .SMTPSecurity:
-            dcContext.setSmtpSecurity(smptpFlags: options[selectedIndex])
+            dcContext.setConfigInt("send_security", Int(options[selectedIndex]))
         }
         navigationController?.popViewController(animated: true)
     }
@@ -107,21 +105,15 @@ enum SecurityType {
 }
 
 class SecurityConverter {
-    static func convertHexToString(type: SecurityType, hex value: Int) -> String {
+    static func getSocketName(value: Int32) -> String {
         switch value {
-        case 0x0:
+        case DC_SOCKET_AUTO:
             return String.localized("automatic")
-        case 0x100:
-            return "StartTLS"
-        case 0x200:
+        case DC_SOCKET_SSL:
             return "SSL/TLS"
-        case 0x400:
-            return String.localized("off")
-        case 0x10000:
+        case DC_SOCKET_STARTTLS:
             return "StartTLS"
-        case 0x20000:
-            return "SSL/TLS"
-        case 0x40000:
+        case DC_SOCKET_PLAIN:
             return String.localized("off")
         default:
             return "Undefined"

+ 4 - 9
deltachat-ios/Controller/AccountSetupController.swift

@@ -173,11 +173,9 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
     }()
 
     lazy var imapSecurityCell: UITableViewCell = {
-        let text = "\(dcContext.getImapSecurity())"
         let cell = UITableViewCell(style: .value1, reuseIdentifier: nil)
         cell.textLabel?.text = String.localized("login_imap_security")
         cell.accessoryType = .disclosureIndicator
-        cell.detailTextLabel?.text = "\(dcContext.getImapSecurity())"
         cell.selectionStyle = .none
         cell.tag = tagImapSecurityCell
         return cell
@@ -234,10 +232,8 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
     }()
 
     lazy var smtpSecurityCell: UITableViewCell = {
-        let security = "\(dcContext.getSmtpSecurity())"
         let cell = UITableViewCell(style: .value1, reuseIdentifier: nil)
         cell.textLabel?.text = String.localized("login_smtp_security")
-        cell.detailTextLabel?.text = security
         cell.tag = tagSmtpSecurityCell
         cell.accessoryType = .disclosureIndicator
         cell.selectionStyle = .none
@@ -417,14 +413,13 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
         } else if sections[section] == advancedSection {
             if advancedSectionShowing && dcContext.isConfigured() {
                 var info = String.localized("used_settings") + "\n"
-                let serverFlags = Int(dcContext.getConfig("configured_server_flags") ?? "") ?? 0
                 info += "IMAP "
-                info += SecurityConverter.convertHexToString(type: .IMAPSecurity, hex: serverFlags&0x700) + " "
+                info += SecurityConverter.getSocketName(value: Int32(dcContext.getConfigInt("mail_security"))) + " "
                 info += (dcContext.getConfig("configured_mail_user") ?? "unset") + ":***@"
                 info += (dcContext.getConfig("configured_mail_server") ?? "unset") + ":"
                 info += (dcContext.getConfig("configured_mail_port") ?? "unset") + "\n"
                 info += "SMTP "
-                info += SecurityConverter.convertHexToString(type: .SMTPSecurity, hex: serverFlags&0x70000) + " "
+                info += SecurityConverter.getSocketName(value: Int32(dcContext.getConfigInt("send_security"))) + " "
                 info += (dcContext.getConfig("configured_send_user") ?? "unset") + ":***@"
                 info += (dcContext.getConfig("configured_send_server") ?? "unset") +  ":"
                 info += (dcContext.getConfig("configured_send_port") ?? "unset") + "\n\n"
@@ -776,8 +771,8 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
     }
 
     private func initSelectionCells() {
-        smtpSecurityCell.detailTextLabel?.text = SecurityConverter.convertHexToString(type: .SMTPSecurity, hex: dcContext.getSmtpSecurity())
-        imapSecurityCell.detailTextLabel?.text = SecurityConverter.convertHexToString(type: .IMAPSecurity, hex: dcContext.getImapSecurity())
+        imapSecurityCell.detailTextLabel?.text = SecurityConverter.getSocketName(value: Int32(dcContext.getConfigInt("mail_security")))
+        smtpSecurityCell.detailTextLabel?.text = SecurityConverter.getSocketName(value: Int32(dcContext.getConfigInt("send_security")))
         certCheckCell.detailTextLabel?.text = CertificateCheckController.ValueConverter.convertHexToString(value: dcContext.certificateChecks)
     }