From 2daad16e272fcab4e128e66407048ecf9825e41c Mon Sep 17 00:00:00 2001
From: lazarog98 <lazarog98@ninlil.imp.fu-berlin.de>
Date: Thu, 27 Feb 2020 11:03:36 +0100
Subject: [PATCH] #238 refactor inbox search

---
 enzevalos_iphone/InboxViewController.swift | 36 ++++++++++++++++++----
 1 file changed, 30 insertions(+), 6 deletions(-)

diff --git a/enzevalos_iphone/InboxViewController.swift b/enzevalos_iphone/InboxViewController.swift
index 5f31fac0..75123752 100644
--- a/enzevalos_iphone/InboxViewController.swift
+++ b/enzevalos_iphone/InboxViewController.swift
@@ -276,11 +276,35 @@ class InboxViewController: UITableViewController, InboxCellDelegator {
      */
     private func _filterContentForSearchText(_ searchText: String, scope: Int = 0) {
         var records = [KeyRecord]()
-        if scope == 0 {
-            records += folder.records.filter({ (record: KeyRecord) -> Bool in
-                return containsSearchTerms(content: record.name, searchText: searchText)
-            })
-        }
+        
+        records += folder.records.filter({ (record: KeyRecord) -> Bool in
+            if scope == 0
+            {
+                 return containsSearchTerms(content: record.name, searchText: searchText)
+            }
+            let mails = record.inboxMails
+            return mails.filter({ (mail: PersistentMail) -> Bool in
+                var str = ""
+                if scope == 1 || scope == 3
+                {
+                    str.append(contentsOf: mail.subject ?? "")
+                }
+                if scope == 2 || scope == 3
+                {
+                    if let decryptedBody = mail.decryptedBody {
+                        str.append(decryptedBody)
+                    } else if !mail.isEncrypted {
+                        str.append(contentsOf: mail.body ?? "")
+                    }
+                }
+                if scope == 3
+                {
+                    str.append(contentsOf: record.name)
+                }
+                return containsSearchTerms(content: str, searchText: searchText)
+                }).count > 0
+        })
+        /*
         if scope == 1 {
             records += folder.records.filter({ (record: KeyRecord) -> Bool in
                 let mails = record.inboxMails
@@ -320,7 +344,7 @@ class InboxViewController: UITableViewController, InboxCellDelegator {
                     return false
                 }).count > 0
             })
-        }
+        }*/
         
 
         filteredRecords = records.unique.sorted()
-- 
GitLab