From bf18d8779e980da0cda4ec87609340c0fc4b18c9 Mon Sep 17 00:00:00 2001 From: Ioan Moldovan Date: Fri, 25 Oct 2024 07:56:24 -0500 Subject: [PATCH] fix: decryption error for message sent via encrypted contact page --- FlowCrypt/Core/CoreTypes.swift | 3 ++- .../Message Provider/MessageAttachment.swift | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/FlowCrypt/Core/CoreTypes.swift b/FlowCrypt/Core/CoreTypes.swift index 7675ba26e..b2407a9b7 100644 --- a/FlowCrypt/Core/CoreTypes.swift +++ b/FlowCrypt/Core/CoreTypes.swift @@ -215,9 +215,10 @@ struct MsgBlock: Decodable { struct AttMeta: Decodable { let name: String - let data: String + let data: String? let type: String let length: Int + let url: String? let treatAs: String? } diff --git a/FlowCrypt/Functionality/Mail Provider/Message Provider/MessageAttachment.swift b/FlowCrypt/Functionality/Mail Provider/Message Provider/MessageAttachment.swift index 819f7f048..b9525708d 100644 --- a/FlowCrypt/Functionality/Mail Provider/Message Provider/MessageAttachment.swift +++ b/FlowCrypt/Functionality/Mail Provider/Message Provider/MessageAttachment.swift @@ -54,10 +54,17 @@ extension MessageAttachment { } init?(attMeta: MsgBlock.AttMeta) { - guard let data = Data(base64Encoded: attMeta.data.data()) else { + if let urlString = attMeta.url, let url = URL(string: urlString) { + // Fetch data synchronously from the URL + if let urlData = try? Data(contentsOf: url) { + self.init(name: attMeta.name, data: urlData, mimeType: attMeta.type, treatAs: "encryptedFile") + return + } + return nil + } + guard let attData = attMeta.data, let data = Data(base64Encoded: attData.data()) else { return nil } - self.init(name: attMeta.name, data: data, mimeType: attMeta.type, treatAs: attMeta.treatAs) } }