From 7ab7433e86e2d330604862e384cfab186952f52b Mon Sep 17 00:00:00 2001 From: Anton Kharchevskyi Date: Thu, 30 Dec 2021 16:14:50 +0200 Subject: [PATCH] Fix crash when openning messages in IMAP --- FlowCrypt.xcodeproj/project.pbxproj | 4 ++ .../MsgListViewController.swift | 10 +++-- ...eatePassphraseAbstractViewController.swift | 1 + .../Imap/ImapSessionProvider.swift | 1 - .../IMAPConnectionParameters.swift | 1 - .../Mail Provider/MailProvider.swift | 2 +- .../Threads/Imap+ThreadOperations.swift | 38 +++++++++++++++++++ 7 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 FlowCrypt/Functionality/Mail Provider/Threads/Imap+ThreadOperations.swift diff --git a/FlowCrypt.xcodeproj/project.pbxproj b/FlowCrypt.xcodeproj/project.pbxproj index 2ae30d421..ec65400a4 100644 --- a/FlowCrypt.xcodeproj/project.pbxproj +++ b/FlowCrypt.xcodeproj/project.pbxproj @@ -155,6 +155,7 @@ 9F5F504326FA6C7500294FA2 /* EnterpriseServerApiMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F5F504226FA6C7500294FA2 /* EnterpriseServerApiMock.swift */; }; 9F5F504A26FA6C8F00294FA2 /* ClientConfigurationProviderMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F5F504926FA6C8F00294FA2 /* ClientConfigurationProviderMock.swift */; }; 9F5FAF6D271DCDAF00B8762B /* MessageActionsHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F5FAF6C271DCDAE00B8762B /* MessageActionsHandler.swift */; }; + 9F65B0B7277DF2AD005CD19C /* Imap+ThreadOperations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F65B0B6277DF2AD005CD19C /* Imap+ThreadOperations.swift */; }; 9F67998B277B222B00AFE5BE /* BigInt in Frameworks */ = {isa = PBXBuildFile; productRef = 9F67998A277B222B00AFE5BE /* BigInt */; }; 9F67998C277B3E4000AFE5BE /* BundleExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E26D5E20275AA417007B8802 /* BundleExtensions.swift */; }; 9F67998D277B3E4D00AFE5BE /* CommandLineExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E26D5E1E275AA295007B8802 /* CommandLineExtensions.swift */; }; @@ -597,6 +598,7 @@ 9F5F504226FA6C7500294FA2 /* EnterpriseServerApiMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnterpriseServerApiMock.swift; sourceTree = ""; }; 9F5F504926FA6C8F00294FA2 /* ClientConfigurationProviderMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientConfigurationProviderMock.swift; sourceTree = ""; }; 9F5FAF6C271DCDAE00B8762B /* MessageActionsHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageActionsHandler.swift; sourceTree = ""; }; + 9F65B0B6277DF2AD005CD19C /* Imap+ThreadOperations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Imap+ThreadOperations.swift"; sourceTree = ""; }; 9F696292236091DD003712E1 /* SignInImageNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignInImageNode.swift; sourceTree = ""; }; 9F696294236091F4003712E1 /* SignInDescriptionNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignInDescriptionNode.swift; sourceTree = ""; }; 9F6EE1542597399D0059BA51 /* BackupProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackupProvider.swift; sourceTree = ""; }; @@ -1420,6 +1422,7 @@ children = ( 9F88391827270A1A00669B56 /* MessagesThreadOperationsProvider.swift */, 9F883915272709E200669B56 /* MessagesThreadProvider.swift */, + 9F65B0B6277DF2AD005CD19C /* Imap+ThreadOperations.swift */, ); path = Threads; sourceTree = ""; @@ -2544,6 +2547,7 @@ 51B4AE5327144E590001F33B /* PubKey.swift in Sources */, 21623D1826FA860700A11B9A /* PhotosManager.swift in Sources */, C132B9B41EC2DBD800763715 /* AppDelegate.swift in Sources */, + 9F65B0B7277DF2AD005CD19C /* Imap+ThreadOperations.swift in Sources */, 9F5FAF6D271DCDAF00B8762B /* MessageActionsHandler.swift in Sources */, 9F976592267E19880058419D /* TestData.swift in Sources */, 04B472961ECE29F600B8266F /* SideMenuNavigationController.swift in Sources */, diff --git a/FlowCrypt/Controllers/MessageList Extension/MsgListViewController.swift b/FlowCrypt/Controllers/MessageList Extension/MsgListViewController.swift index 2f9196260..3459ab670 100644 --- a/FlowCrypt/Controllers/MessageList Extension/MsgListViewController.swift +++ b/FlowCrypt/Controllers/MessageList Extension/MsgListViewController.swift @@ -37,10 +37,12 @@ extension MsgListViewController where Self: UIViewController { } private func openMsg(appContext: AppContext, with message: Message, path: String) { - let thread = MessageThread(identifier: message.threadId, - snippet: nil, - path: path, - messages: [message]) + let thread = MessageThread( + identifier: message.threadId, + snippet: nil, + path: path, + messages: [message] + ) openThread(with: thread, appContext: appContext) } diff --git a/FlowCrypt/Controllers/Setup/SetupCreatePassphraseAbstractViewController.swift b/FlowCrypt/Controllers/Setup/SetupCreatePassphraseAbstractViewController.swift index 913d82a50..721421128 100644 --- a/FlowCrypt/Controllers/Setup/SetupCreatePassphraseAbstractViewController.swift +++ b/FlowCrypt/Controllers/Setup/SetupCreatePassphraseAbstractViewController.swift @@ -15,6 +15,7 @@ import FlowCryptUI * - Has not to have an instance! */ +@MainActor class SetupCreatePassphraseAbstractViewController: TableNodeViewController, PassPhraseSaveable, NavigationChildController { enum Parts: Int, CaseIterable { diff --git a/FlowCrypt/Functionality/Mail Provider/Imap/ImapSessionProvider.swift b/FlowCrypt/Functionality/Mail Provider/Imap/ImapSessionProvider.swift index 45b517726..4880b1229 100644 --- a/FlowCrypt/Functionality/Mail Provider/Imap/ImapSessionProvider.swift +++ b/FlowCrypt/Functionality/Mail Provider/Imap/ImapSessionProvider.swift @@ -23,7 +23,6 @@ class ImapSessionProvider: ImapSessionProviderType { func imapSession() -> IMAPSession? { guard let imapSession = IMAPSession(user: self.user) else { - assertionFailure("couldn't create IMAP Session with this parameters") return nil } return imapSession diff --git a/FlowCrypt/Functionality/Mail Provider/Mail Sessions Providers/IMAPConnectionParameters.swift b/FlowCrypt/Functionality/Mail Provider/Mail Sessions Providers/IMAPConnectionParameters.swift index e20ee5f41..9414fe46d 100644 --- a/FlowCrypt/Functionality/Mail Provider/Mail Sessions Providers/IMAPConnectionParameters.swift +++ b/FlowCrypt/Functionality/Mail Provider/Mail Sessions Providers/IMAPConnectionParameters.swift @@ -25,7 +25,6 @@ extension IMAPSession { } guard let auth = user.authType, let connection = ConnectionType(rawValue: imap.connectionType) else { - assertionFailure("Authentication type should be defined on this step") return nil } diff --git a/FlowCrypt/Functionality/Mail Provider/MailProvider.swift b/FlowCrypt/Functionality/Mail Provider/MailProvider.swift index 39249c5f4..b7049329c 100644 --- a/FlowCrypt/Functionality/Mail Provider/MailProvider.swift +++ b/FlowCrypt/Functionality/Mail Provider/MailProvider.swift @@ -87,7 +87,7 @@ final class MailProvider { private func resolveService(of type: T.Type) -> T { guard let service = services.first(where: { $0.mailServiceProviderType == authType.mailServiceProviderType }) as? T else { - fatalError("Email Provider should support this functionality") + fatalError("Email Provider should support this functionality. Can't resolve dependency for \(type)") } return service } diff --git a/FlowCrypt/Functionality/Mail Provider/Threads/Imap+ThreadOperations.swift b/FlowCrypt/Functionality/Mail Provider/Threads/Imap+ThreadOperations.swift new file mode 100644 index 000000000..b7289720c --- /dev/null +++ b/FlowCrypt/Functionality/Mail Provider/Threads/Imap+ThreadOperations.swift @@ -0,0 +1,38 @@ +// +// Imap+ThreadOperations.swift +// FlowCrypt +// +// Created by Anton Kharchevskyi on 30.12.2021 +// Copyright © 2017-present FlowCrypt a. s. All rights reserved. +// + +import Foundation + +// TODO: - Rework in scope of https://github.com/FlowCrypt/flowcrypt-ios/issues/1260 +extension Imap: MessagesThreadOperationsProvider { + private var error: Error { AppErr.general("Doesn't support yet") } + + func mark(thread: MessageThread, asRead: Bool, in folder: String) async throws { + throw error + } + + func delete(thread: MessageThread) async throws { + throw error + } + + func moveThreadToTrash(thread: MessageThread) async throws { + throw error + } + + func markThreadAsUnread(thread: MessageThread, folder: String) async throws { + throw error + } + + func markThreadAsRead(thread: MessageThread, folder: String) async throws { + throw error + } + + func archive(thread: MessageThread, in folder: String) async throws { + throw error + } +}