Jelajahi Sumber

configure advanced config options with dc_set_config, calculate server flags

Jonas Reinsch 6 tahun lalu
induk
melakukan
18f365752e

+ 2 - 0
deltachat-ios.xcodeproj/project.pbxproj

@@ -215,6 +215,7 @@
 		7A9FB14D1FB061E2001FEA36 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
 		7A9FB14F1FB061E2001FEA36 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
 		7A9FB1561FB06540001FEA36 /* deltachat-ios-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "deltachat-ios-Bridging-Header.h"; sourceTree = "<group>"; };
+		7ABE47E321617ACF002F5A67 /* dc_loginparam.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = dc_loginparam.h; sourceTree = "<group>"; };
 		7AE0A5481FC42F65005ECB4B /* NewChatViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewChatViewController.swift; sourceTree = "<group>"; };
 		8DE110C607A0E4485C43B5FA /* Pods-deltachat-ios.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-deltachat-ios.debug.xcconfig"; path = "Pods/Target Support Files/Pods-deltachat-ios/Pods-deltachat-ios.debug.xcconfig"; sourceTree = "<group>"; };
 		A8615D4600859851E53CAA9C /* Pods-deltachat-ios.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-deltachat-ios.release.xcconfig"; path = "Pods/Target Support Files/Pods-deltachat-ios/Pods-deltachat-ios.release.xcconfig"; sourceTree = "<group>"; };
@@ -407,6 +408,7 @@
 				7070FB7E20FF3833000DC258 /* dc_msg.h */,
 				7070FB7B20FF3815000DC258 /* dc_contact.h */,
 				7070FB7D20FF3815000DC258 /* dc_lot.h */,
+				7ABE47E321617ACF002F5A67 /* dc_loginparam.h */,
 				7070FB7820FF353E000DC258 /* deltachat.h */,
 				7070FB4D20FF345C000DC258 /* dc_array.c */,
 				7070FB4A20FF345C000DC258 /* dc_chatlist.c */,

+ 68 - 5
deltachat-ios/AppDelegate.swift

@@ -120,7 +120,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
 }
 
 
-func initCore(withCredentials: Bool, email: String = "", password: String = "") {
+func initCore(withCredentials: Bool, advancedMode:Bool = false, model:CredentialsModel? = nil) {
+/*    let DC_LP_AUTH_NORMAL:Int = 0x4
+    let DC_LP_IMAP_SOCKET_PLAIN:Int = 0x400
+    let DC_LP_IMAP_SOCKET_SSL:Int = 0x200
+    let DC_LP_IMAP_SOCKET_STARTTLS:Int = 0x100
+    let DC_LP_SMTP_SOCKET_PLAIN:Int = 0x40000
+    let DC_LP_SMTP_SOCKET_SSL:Int = 0x20000
+    let DC_LP_SMTP_SOCKET_STARTTLS:Int = 0x10000*/
+
     let paths = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true)
     let documentsPath = paths[0]
     let dbfile = documentsPath + "/messenger.db"
@@ -150,14 +158,69 @@ func initCore(withCredentials: Bool, email: String = "", password: String = "")
     let _ = dc_open(mailboxPointer, dbfile, nil)
     
     if withCredentials {
-        if !(email.contains("@") && (email.count >= 3)) {
+        guard let model = model else {
+            fatalError("withCredentials == true implies non-nil model")
+        }
+        if !(model.email.contains("@") && (model.email.count >= 3)) {
             fatalError("initCore called with withCredentials flag set to true, but email not valid")
         }
-        if password.isEmpty {
+        if model.password.isEmpty {
             fatalError("initCore called with withCredentials flag set to true, password is empty")
         }
-        dc_set_config(mailboxPointer, "addr", email)
-        dc_set_config(mailboxPointer, "mail_pw", password)
+        dc_set_config(mailboxPointer, "addr", model.email)
+        dc_set_config(mailboxPointer, "mail_pw", model.password)
+        if advancedMode {
+            if let imapLoginName = model.imapLoginName {
+                dc_set_config(mailboxPointer, "mail_user", imapLoginName)
+            }
+            if let imapServer = model.imapServer {
+                dc_set_config(mailboxPointer, "mail_server", imapServer)
+            }
+            if let imapPort = model.imapPort {
+                dc_set_config(mailboxPointer, "mail_port", imapPort)
+            }
+
+            
+            if let smtpLoginName = model.smtpLoginName {
+                dc_set_config(mailboxPointer, "send_user", smtpLoginName)
+            }
+            if let smtpPassword = model.smtpPassword {
+                dc_set_config(mailboxPointer, "send_pw", smtpPassword)
+            }
+            if let smtpServer = model.smtpServer {
+                dc_set_config(mailboxPointer, "send_server", smtpServer)
+            }
+            if let smtpPort = model.smtpPort {
+                dc_set_config(mailboxPointer, "send_port", smtpPort)
+            }
+            
+            var flags:Int32 = 0
+            if (model.smtpSecurity == .automatic) && (model.imapSecurity == .automatic) {
+                flags = DC_LP_AUTH_NORMAL
+            } else {
+                if model.smtpSecurity == .off {
+                    flags |= DC_LP_SMTP_SOCKET_PLAIN
+                } else if model.smtpSecurity == .ssltls {
+                    flags |= DC_LP_SMTP_SOCKET_SSL
+                } else if model.smtpSecurity == .starttls {
+                    flags |= DC_LP_SMTP_SOCKET_STARTTLS
+                }
+                
+                if model.imapSecurity == .off {
+                    flags |= DC_LP_IMAP_SOCKET_PLAIN
+                } else if model.imapSecurity == .ssltls {
+                    flags |= DC_LP_IMAP_SOCKET_SSL
+                } else if model.imapSecurity == .starttls {
+                    flags |= DC_LP_IMAP_SOCKET_STARTTLS
+                }
+            }
+            let ptr: UnsafeMutablePointer<Int32> = UnsafeMutablePointer.allocate(capacity: 1)
+            ptr.pointee = flags
+            let rp = UnsafeRawPointer(ptr)
+            // rebind memory from Int32 to Int8
+            let up = rp.bindMemory(to: Int8.self, capacity: 1)
+            dc_set_config(mailboxPointer, "server_flags", up)
+        }
         
         // TODO: - handle failure, need to show credentials screen again
         dc_configure(mailboxPointer)

+ 3 - 1
deltachat-ios/CredentialsController.swift

@@ -200,8 +200,10 @@ class CredentialsController: UITableViewController {
     }
     
     @objc func didPressSaveAccountButton() {
+        let m = model
+        let a = advancedMode
         dismiss(animated: true) {
-            initCore(withCredentials: true, email: self.model.email, password: self.model.password)
+            initCore(withCredentials: true, advancedMode: a, model: m)
         }
     }
     

+ 3 - 0
deltachat-ios/deltachat-ios-Bridging-Header.h

@@ -10,8 +10,11 @@
 #include "dc_msg.h"
 #include "dc_lot.h"
 #include "dc_array.h"
+#include "dc_loginparam.h"
 #include "wrapper.h"
 
+
+
 /*
 #include "mrsqlite3.h"
 #include "mrhash.h"