Kaynağa Gözat

implement email url detection, disable default url link handling for email addresses

cyberta 5 yıl önce
ebeveyn
işleme
79415501b4

+ 6 - 1
deltachat-ios/Controller/ChatViewController.swift

@@ -1042,7 +1042,12 @@ extension ChatViewController: MessageLabelDelegate {
     }
 
     func didSelectURL(_ url: URL) {
-        UIApplication.shared.open(url)
+        if Utils.isEmail(url: url) {
+            print("tapped on contact")
+            ///TODO: implement handling
+        } else {
+            UIApplication.shared.open(url)
+        }
     }
 }
 

+ 1 - 1
deltachat-ios/Controller/NewContactController.swift

@@ -11,7 +11,7 @@ class NewContactController: UITableViewController {
     var cancelButton: UIBarButtonItem?
 
     func contactIsValid() -> Bool {
-        return Utils.isValid(model.email)
+        return Utils.isValid(email: model.email)
     }
 
     var model: (name: String, email: String) = ("", "") {

+ 10 - 1
deltachat-ios/Helper/Utils.swift

@@ -72,7 +72,7 @@ struct Utils {
         return acc
     }
 
-    static func isValid(_ email: String) -> Bool {
+    static func isValid(email: String) -> Bool {
         let emailRegEx = "(?:[a-z0-9!#$%\\&'*+/=?\\^_`{|}~-]+(?:\\.[a-z0-9!#$%\\&'*+/=?\\^_`{|}"
             + "~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\"
             + "x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-"
@@ -85,6 +85,15 @@ struct Utils {
         return emailTest.evaluate(with: email)
     }
 
+
+    static func isEmail(url: URL) -> Bool {
+        let mailScheme = "mailto"
+        if let scheme = url.scheme {
+            return mailScheme == scheme && isValid(email: url.absoluteString.substring(mailScheme.count + 1, url.absoluteString.count))
+        }
+        return false
+    }
+
     static func formatAddressForQuery(address: [String: String]) -> String {
         // Open address in Apple Maps app.
         var addressParts = [String]()