IOS-1480 rm obsolte duplicated code workaround IOS-1480
authorbuff <andreas@pep-project.org>
Thu, 07 Mar 2019 20:08:15 +0100
branchIOS-1480
changeset 79103382a2bd3693
parent 7909 009d4ad1a260
child 7911 6ae0a74566a8
IOS-1480 rm obsolte duplicated code workaround
pEpForiOS.xcodeproj/project.pbxproj
pEpForiOS/Util/PEPUtil.swift
     1.1 --- a/pEpForiOS.xcodeproj/project.pbxproj	Thu Mar 07 20:06:01 2019 +0100
     1.2 +++ b/pEpForiOS.xcodeproj/project.pbxproj	Thu Mar 07 20:08:15 2019 +0100
     1.3 @@ -356,7 +356,6 @@
     1.4  		43B2C31B1D2280ED00A08557 /* 5A90_3590_0E48_AB85_F3DB__045E_4623_C5D1_EAB6_643E.asc in Resources */ = {isa = PBXBuildFile; fileRef = 43B2C3161D2280ED00A08557 /* 5A90_3590_0E48_AB85_F3DB__045E_4623_C5D1_EAB6_643E.asc */; };
     1.5  		43B54F961FE02D02008EC427 /* AppAuth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 43B54F971FE02D02008EC427 /* AppAuth.framework */; };
     1.6  		43B7154D1CECAADA0027861A /* ViewWidthsAligner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43B7154C1CECAADA0027861A /* ViewWidthsAligner.swift */; };
     1.7 -		43BCF01D222FF66A00148303 /* PEPUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43BCF01C222FF66A00148303 /* PEPUtil.swift */; };
     1.8  		43C046BF1CF48EA500BD0D9D /* AddressBook.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 43C046BE1CF48EA500BD0D9D /* AddressBook.framework */; };
     1.9  		43C273DD21C9024A002EB4C8 /* LoggerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43C273DC21C9024A002EB4C8 /* LoggerTest.swift */; };
    1.10  		43C322051EA89EED005073FB /* HandshakePartnerTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43C322041EA89EED005073FB /* HandshakePartnerTableViewCell.swift */; };
    1.11 @@ -893,7 +892,6 @@
    1.12  		43B2C3161D2280ED00A08557 /* 5A90_3590_0E48_AB85_F3DB__045E_4623_C5D1_EAB6_643E.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = 5A90_3590_0E48_AB85_F3DB__045E_4623_C5D1_EAB6_643E.asc; sourceTree = "<group>"; };
    1.13  		43B54F971FE02D02008EC427 /* AppAuth.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = AppAuth.framework; sourceTree = BUILT_PRODUCTS_DIR; };
    1.14  		43B7154C1CECAADA0027861A /* ViewWidthsAligner.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewWidthsAligner.swift; sourceTree = "<group>"; };
    1.15 -		43BCF01C222FF66A00148303 /* PEPUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PEPUtil.swift; sourceTree = "<group>"; };
    1.16  		43C046BE1CF48EA500BD0D9D /* AddressBook.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AddressBook.framework; path = System/Library/Frameworks/AddressBook.framework; sourceTree = SDKROOT; };
    1.17  		43C273DC21C9024A002EB4C8 /* LoggerTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoggerTest.swift; sourceTree = "<group>"; };
    1.18  		43C322041EA89EED005073FB /* HandshakePartnerTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HandshakePartnerTableViewCell.swift; sourceTree = "<group>"; };
    1.19 @@ -2070,7 +2068,6 @@
    1.20  				43AE48E61EEFC93900B92BB6 /* DebugMergePolicy.swift */,
    1.21  				15255B021F825CD100A2CFC9 /* IdentityImageTool.swift */,
    1.22  				155050EF1FE82356009CEAD2 /* UserNotificationTool.swift */,
    1.23 -				43BCF01C222FF66A00148303 /* PEPUtil.swift */,
    1.24  			);
    1.25  			path = Util;
    1.26  			sourceTree = "<group>";
    1.27 @@ -3183,7 +3180,6 @@
    1.28  				B78CF8291E76E0F1008C1739 /* FilterViewModel.swift in Sources */,
    1.29  				43293EFB1EB9DD6700EEE010 /* UIViewController+Extension.swift in Sources */,
    1.30  				152A39D521905C3E00D9F8E4 /* SubjectCellViewModel.swift in Sources */,
    1.31 -				43BCF01D222FF66A00148303 /* PEPUtil.swift in Sources */,
    1.32  				4341EBD1208A0961004CE6B8 /* QualifyServerIsLocalServiceProtocol.swift in Sources */,
    1.33  				43D0702F2133DB3F0013B120 /* AppSettings.swift in Sources */,
    1.34  				00FD0CE62101F7D700BA0C56 /* ScreenComposerProtocol.swift in Sources */,
     2.1 --- a/pEpForiOS/Util/PEPUtil.swift	Thu Mar 07 20:06:01 2019 +0100
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,587 +0,0 @@
     2.4 -////
     2.5 -////  PEPUtil.swift
     2.6 -////  pEp
     2.7 -////
     2.8 -////  Created by Dirk Zimmermann on 06.03.19.
     2.9 -////  Copyright © 2019 p≡p Security S.A. All rights reserved.
    2.10 -////
    2.11 -//
    2.12 -//import Foundation
    2.13 -//
    2.14 -//import pEpIOSToolbox
    2.15 -//import PantomimeFramework
    2.16 -//import PEPObjCAdapterFramework
    2.17 -//import MessageModel
    2.18 -//
    2.19 -///**
    2.20 -// - Note: TODO: This is a duplicate of `PEPUtil` in MessageModel, disguised
    2.21 -// as extension.
    2.22 -// Whenever swiftc sorts out name mangling of methods involving 3rd frameworks
    2.23 -// (one framework using a class and its methods with parameters from a third framework),
    2.24 -// these methods might lead to errors. This is a feature, since you will then be able
    2.25 -// to delete this file and just use the MessageModel version.
    2.26 -// */
    2.27 -//extension PEPUtil {
    2.28 -//    static let comp = "PEPUtil"
    2.29 -//  
    2.30 -//    /**
    2.31 -//     Default pEpRating value when there's none, i.e. the message has never been decrypted.
    2.32 -//     */
    2.33 -//    static let pEpRatingNone = CdMessage.pEpRatingNone
    2.34 -//
    2.35 -//    /**
    2.36 -//     Content type for MIME multipart/alternative.
    2.37 -//     */
    2.38 -//    static let kMimeTypeMultipartAlternative = "multipart/alternative"
    2.39 -//
    2.40 -//    static func identity(account: CdAccount) -> PEPIdentity {
    2.41 -//        if let id = account.identity {
    2.42 -//            return pEpDict(cdIdentity: id)
    2.43 -//        } else {
    2.44 -//            Logger.utilLogger.errorAndCrash(
    2.45 -//                "account without identity: %{public}@", account)
    2.46 -//            return PEPIdentity(address: "none")
    2.47 -//        }
    2.48 -//    }
    2.49 -//
    2.50 -//    static func pEp(identity: Identity) -> PEPIdentity {
    2.51 -//        return PEPIdentity(
    2.52 -//            address: identity.address, userID: identity.userID, userName: identity.userName,
    2.53 -//            isOwn: identity.isMySelf, fingerPrint: nil,
    2.54 -//            commType: PEPCommType.unknown, language: nil)
    2.55 -//    }
    2.56 -//
    2.57 -//    /**
    2.58 -//     Like the corresponding `pEpDict(cdIdentity)`, but dealing with optional parameters.
    2.59 -//     */
    2.60 -//    static func pEpDict(cdIdentityOptional: CdIdentity?) -> PEPIdentity? {
    2.61 -//        guard let cdIdentity = cdIdentityOptional else {
    2.62 -//            return nil
    2.63 -//        }
    2.64 -//        return pEpDict(cdIdentity: cdIdentity)
    2.65 -//    }
    2.66 -//
    2.67 -//    /**
    2.68 -//     Converts a `CdIdentity` to a pEp contact (`PEPId`).
    2.69 -//     - Parameter cdIdentity: The core data contact object.
    2.70 -//     - Returns: An `PEPIdentity` contact for pEp.
    2.71 -//     */
    2.72 -//    static func pEpDict(cdIdentity: CdIdentity) -> PEPIdentity {
    2.73 -//        if let address = cdIdentity.address {
    2.74 -//            return PEPIdentity(address: address, userID: cdIdentity.userID,
    2.75 -//                               userName: cdIdentity.userName, isOwn: cdIdentity.isMySelf,
    2.76 -//                               fingerPrint: nil, commType: PEPCommType.unknown, language: nil)
    2.77 -//        } else {
    2.78 -//            Logger.utilLogger.errorAndCrash(
    2.79 -//                "missing address: %{public}@", cdIdentity)
    2.80 -//            return PEPIdentity(address: "none")
    2.81 -//        }
    2.82 -//    }
    2.83 -//
    2.84 -//    /**
    2.85 -//     Creates pEp contact just from name and address.
    2.86 -//     */
    2.87 -//    static func pEpIdentity(email: String, name: String) -> PEPIdentityDict {
    2.88 -//        var identity = PEPIdentityDict()
    2.89 -//        identity[kPepAddress] = email as AnyObject
    2.90 -//        identity[kPepUsername] = name as AnyObject
    2.91 -//        return identity
    2.92 -//    }
    2.93 -//
    2.94 -//    static func pEpOptional(identity: Identity?) -> PEPIdentity? {
    2.95 -//        guard let id = identity else {
    2.96 -//            return nil
    2.97 -//        }
    2.98 -//        return pEp(identity: id)
    2.99 -//    }
   2.100 -//
   2.101 -//    static func pEpAttachment(
   2.102 -//        fileName: String?, mimeType: String?, data: Data?,
   2.103 -//        contentDispositionType: PEPContentDisposition) -> PEPAttachment {
   2.104 -//        let attachment = PEPAttachment(data: data ?? Data())
   2.105 -//        attachment.filename = fileName
   2.106 -//        attachment.mimeType = mimeType
   2.107 -//        attachment.contentDisposition = contentDispositionType
   2.108 -//        return attachment
   2.109 -//    }
   2.110 -//
   2.111 -//    /**
   2.112 -//     Converts a `CdAttachment` into a PEPAttachment.
   2.113 -//     */
   2.114 -//    static func pEpAttachment(cdAttachment: CdAttachment) -> PEPAttachment {
   2.115 -//        let contentDispoType = PEPContentDisposition(rawValue:
   2.116 -//            Int(cdAttachment.contentDispositionTypeRawValue))
   2.117 -//        if contentDispoType == nil {
   2.118 -//            Logger.backendLogger.errorAndCrash(
   2.119 -//                "Unsupported PEPContentDisposition %d",
   2.120 -//                cdAttachment.contentDispositionTypeRawValue)
   2.121 -//        }
   2.122 -//        return pEpAttachment(fileName: cdAttachment.fileName,
   2.123 -//                             mimeType: cdAttachment.mimeType,
   2.124 -//                             data: cdAttachment.data as Data?,
   2.125 -//                             contentDispositionType: contentDispoType ?? .attachment)
   2.126 -//    }
   2.127 -//
   2.128 -//    /**
   2.129 -//     Converts a `Attachment` into a PEPAttachment.
   2.130 -//     */
   2.131 -//    static func pEpAttachment(attachment: Attachment) -> PEPAttachment {
   2.132 -//        let contentDispoType = PEPContentDisposition(rawValue:
   2.133 -//            Int(attachment.contentDisposition.rawValue))
   2.134 -//        if contentDispoType == nil {
   2.135 -//            Logger.backendLogger.errorAndCrash(
   2.136 -//                "Unsupported PEPContentDisposition %d",
   2.137 -//                attachment.contentDisposition.rawValue)
   2.138 -//        }
   2.139 -//        return pEpAttachment(fileName: attachment.fileName,
   2.140 -//                             mimeType: attachment.mimeType,
   2.141 -//                             data: attachment.data as Data?,
   2.142 -//                             contentDispositionType: contentDispoType ?? .attachment)
   2.143 -//    }
   2.144 -//
   2.145 -//    /**
   2.146 -//     Converts a core data message into the format required by pEp.
   2.147 -//     - Parameter message: The core data message to convert
   2.148 -//     - Returns: An object (`NSMutableDictionary`) suitable for processing with pEp.
   2.149 -//     */
   2.150 -//    static func pEpDict(cdMessage: CdMessage, outgoing: Bool = true) -> PEPMessageDict {
   2.151 -//        var dict = PEPMessageDict()
   2.152 -//
   2.153 -//        if let sent = cdMessage.sent {
   2.154 -//            dict[kPepSent] = sent as NSDate
   2.155 -//        }
   2.156 -//
   2.157 -//        if let subject = cdMessage.shortMessage {
   2.158 -//            dict[kPepShortMessage] = subject as NSString
   2.159 -//        }
   2.160 -//
   2.161 -//        dict[kPepTo] = NSArray(array: cdMessage.to!.map()
   2.162 -//            { return pEpDict(cdIdentity: $0 as! CdIdentity) })
   2.163 -//        dict[kPepCC] = NSArray(array: cdMessage.cc!.map()
   2.164 -//            { return pEpDict(cdIdentity: $0 as! CdIdentity) })
   2.165 -//        dict[kPepBCC] = NSArray(array: cdMessage.bcc!.map()
   2.166 -//            { return pEpDict(cdIdentity: $0 as! CdIdentity) })
   2.167 -//
   2.168 -//        if let longMessage = cdMessage.longMessage {
   2.169 -//            dict[kPepLongMessage] = longMessage as AnyObject
   2.170 -//        }
   2.171 -//        if let longMessageFormatted = cdMessage.longMessageFormatted {
   2.172 -//            dict[kPepLongMessageFormatted] = longMessageFormatted as AnyObject
   2.173 -//        }
   2.174 -//        if let from = cdMessage.from {
   2.175 -//            dict[kPepFrom]  = self.pEpDict(cdIdentity: from) as AnyObject
   2.176 -//        }
   2.177 -//        if let messageID = cdMessage.uuid {
   2.178 -//            dict[kPepID] = messageID as AnyObject
   2.179 -//        }
   2.180 -//        dict[kPepOutgoing] = NSNumber(booleanLiteral: outgoing)
   2.181 -//
   2.182 -//        let theAttachments = NSArray(
   2.183 -//            array: (cdMessage.attachments?.array as? [CdAttachment] ?? []).map() {
   2.184 -//                return pEpAttachment(cdAttachment: $0)
   2.185 -//        })
   2.186 -//        dict[kPepAttachments] = theAttachments
   2.187 -//
   2.188 -//        var refs = [String]()
   2.189 -//        for ref in cdMessage.references?.array as? [CdMessageReference] ?? [] {
   2.190 -//            if let refString = ref.reference {
   2.191 -//                refs.append(refString)
   2.192 -//            }
   2.193 -//        }
   2.194 -//
   2.195 -//        if refs.count > 0 {
   2.196 -//            dict[kPepReferences] = refs as AnyObject
   2.197 -//        }
   2.198 -//
   2.199 -//        if let replyTos = cdMessage.replyTo, replyTos.count > 0 {
   2.200 -//            dict[kPepReplyTo] = NSArray(array: replyTos
   2.201 -//                .map { pEpDict(cdIdentity: $0 as! CdIdentity) })
   2.202 -//        }
   2.203 -//
   2.204 -//        let headerFields = cdMessage.optionalFields?.array as? [CdHeaderField] ?? []
   2.205 -//        var theFields = [(String, String)]()
   2.206 -//        for field in headerFields {
   2.207 -//            if let name = field.name, let value = field.value {
   2.208 -//                theFields.append((name, value))
   2.209 -//            }
   2.210 -//        }
   2.211 -//        if !theFields.isEmpty {
   2.212 -//            dict[kPepOptFields] = NSArray(
   2.213 -//                array: theFields.map() {
   2.214 -//                    return NSArray(array: [$0.0, $0.1])
   2.215 -//            })
   2.216 -//        }
   2.217 -//
   2.218 -//        return dict
   2.219 -//    }
   2.220 -//
   2.221 -//    /**
   2.222 -//     Converts a typical core data set of CdIdentities into pEp identities.
   2.223 -//     */
   2.224 -//    static func pEpIdentities(cdIdentitiesSet: NSOrderedSet?) -> [PEPIdentity]? {
   2.225 -//        guard let cdIdentities = cdIdentitiesSet?.array as? [CdIdentity] else {
   2.226 -//            return nil
   2.227 -//        }
   2.228 -//        return cdIdentities.map {
   2.229 -//            return pEpDict(cdIdentity: $0)
   2.230 -//        }
   2.231 -//    }
   2.232 -//
   2.233 -//    /**
   2.234 -//     Converts a core data message into the format required by pEp.
   2.235 -//     - Parameter message: The core data message to convert
   2.236 -//     - Returns: A PEPMessage suitable for processing with pEp.
   2.237 -//     */
   2.238 -//    static func pEp(cdMessage: CdMessage, outgoing: Bool = true) -> PEPMessage {
   2.239 -//        let pEpMessage = PEPMessage()
   2.240 -//
   2.241 -//        pEpMessage.sentDate = cdMessage.sent
   2.242 -//        pEpMessage.shortMessage = cdMessage.shortMessage
   2.243 -//        pEpMessage.longMessage = cdMessage.longMessage
   2.244 -//        pEpMessage.longMessageFormatted = cdMessage.longMessageFormatted
   2.245 -//
   2.246 -//        pEpMessage.to = pEpIdentities(cdIdentitiesSet: cdMessage.to)
   2.247 -//        pEpMessage.cc = pEpIdentities(cdIdentitiesSet: cdMessage.cc)
   2.248 -//        pEpMessage.bcc = pEpIdentities(cdIdentitiesSet: cdMessage.bcc)
   2.249 -//
   2.250 -//        pEpMessage.from = pEpDict(cdIdentityOptional: cdMessage.from)
   2.251 -//        pEpMessage.messageID = cdMessage.uuid
   2.252 -//        pEpMessage.direction = outgoing ? .outgoing : .incoming
   2.253 -//
   2.254 -//        if let cdAttachments = cdMessage.attachments?.array as? [CdAttachment] {
   2.255 -//            pEpMessage.attachments = cdAttachments.map {
   2.256 -//                return pEpAttachment(cdAttachment: $0)
   2.257 -//            }
   2.258 -//        }
   2.259 -//
   2.260 -//        var refs = [String]()
   2.261 -//        for ref in cdMessage.references?.array as? [CdMessageReference] ?? [] {
   2.262 -//            if let refString = ref.reference {
   2.263 -//                refs.append(refString)
   2.264 -//            }
   2.265 -//        }
   2.266 -//        if !refs.isEmpty {
   2.267 -//            pEpMessage.references = refs
   2.268 -//        }
   2.269 -//
   2.270 -//        var replyTos = [PEPIdentity]()
   2.271 -//        if let r = cdMessage.replyTo {
   2.272 -//            for ident in r.array {
   2.273 -//                if let cdIdent = ident as? CdIdentity {
   2.274 -//                    replyTos.append(pEpDict(cdIdentity: cdIdent))
   2.275 -//                }
   2.276 -//            }
   2.277 -//            if !replyTos.isEmpty {
   2.278 -//                pEpMessage.replyTo = replyTos
   2.279 -//            }
   2.280 -//        }
   2.281 -//
   2.282 -//        if let headerFields = cdMessage.optionalFields?.array as? [CdHeaderField] {
   2.283 -//            var theFields = [(String, String)]()
   2.284 -//            for field in headerFields {
   2.285 -//                if let name = field.name, let value = field.value {
   2.286 -//                    theFields.append((name, value))
   2.287 -//                }
   2.288 -//            }
   2.289 -//            if !theFields.isEmpty {
   2.290 -//                pEpMessage.optionalFields = theFields.map { (s1, s2) in
   2.291 -//                    return [s1, s2]
   2.292 -//                }
   2.293 -//            }
   2.294 -//        }
   2.295 -//
   2.296 -//        return pEpMessage
   2.297 -//    }
   2.298 -//
   2.299 -//    /**
   2.300 -//     For a PEPMessage, checks whether it is probably PGP/MIME encrypted.
   2.301 -//     */
   2.302 -//    static func isProbablyPGPMime(pEpMessageDict: PEPMessageDict) -> Bool {
   2.303 -//        guard let attachments = pEpMessageDict[kPepAttachments] as? NSArray else {
   2.304 -//            return false
   2.305 -//        }
   2.306 -//
   2.307 -//        var foundAttachmentPGPEncrypted = false
   2.308 -//        for atch in attachments {
   2.309 -//            guard let at = atch as? PEPAttachment else {
   2.310 -//                continue
   2.311 -//            }
   2.312 -//            guard let filename = at.mimeType else {
   2.313 -//                continue
   2.314 -//            }
   2.315 -//            if filename.lowercased() == Constants.contentTypePGPEncrypted {
   2.316 -//                foundAttachmentPGPEncrypted = true
   2.317 -//                break
   2.318 -//            }
   2.319 -//        }
   2.320 -//        return foundAttachmentPGPEncrypted
   2.321 -//    }
   2.322 -//
   2.323 -//    /**
   2.324 -//     For a CdMessage, checks whether it is probably PGP/MIME encrypted.
   2.325 -//     */
   2.326 -//    static func isProbablyPGPMime(cdMessage: CdMessage) -> Bool {
   2.327 -//        return isProbablyPGPMime(pEpMessageDict: pEpDict(cdMessage: cdMessage))
   2.328 -//    }
   2.329 -//
   2.330 -//    /**
   2.331 -//     Converts a pEp identity dict to a pantomime address.
   2.332 -//     */
   2.333 -//    static func pantomime(pEpIdentity: PEPIdentity) -> CWInternetAddress {
   2.334 -//        return CWInternetAddress(personal: pEpIdentity.userName, address: pEpIdentity.address)
   2.335 -//    }
   2.336 -//
   2.337 -//    /**
   2.338 -//     Converts a list of pEp identities of a given receiver type to a list of pantomime recipients.
   2.339 -//     */
   2.340 -//    static func pantomime(pEpIdentities: [PEPIdentity], recipientType: PantomimeRecipientType)
   2.341 -//        -> [CWInternetAddress] {
   2.342 -//            return pEpIdentities.map {
   2.343 -//                let pant = pantomime(pEpIdentity: $0)
   2.344 -//                pant.setType(recipientType)
   2.345 -//                return pant
   2.346 -//            }
   2.347 -//    }
   2.348 -//
   2.349 -//    static func add(pEpIdentities: [PEPIdentity], toPantomimeMessage: CWIMAPMessage,
   2.350 -//                           recipientType: PantomimeRecipientType) {
   2.351 -//        let addresses = pantomime(
   2.352 -//            pEpIdentities: pEpIdentities, recipientType: recipientType)
   2.353 -//        for a in addresses {
   2.354 -//            toPantomimeMessage.addRecipient(a)
   2.355 -//        }
   2.356 -//    }
   2.357 -//
   2.358 -//    /**
   2.359 -//     Converts a given `CdMessage` into the equivalent `CWIMAPMessage`.
   2.360 -//     */
   2.361 -//    static func pantomime(cdMessage: CdMessage) -> CWIMAPMessage {
   2.362 -//        return pantomime(pEpMessageDict: pEpDict(cdMessage: cdMessage))
   2.363 -//    }
   2.364 -//
   2.365 -//    static func pantomime(pEpMessageDict: PEPMessageDict,
   2.366 -//                                 mailboxName: String? = nil) -> CWIMAPMessage {
   2.367 -//        return CWIMAPMessage(pEpMessageDict: pEpMessageDict, mailboxName: mailboxName)
   2.368 -//    }
   2.369 -//
   2.370 -//    /**
   2.371 -//     Extracts the body of a pEp mail as a pantomime part object.
   2.372 -//     - Returns: Either a single CWPart,
   2.373 -//     if there is only one text content (either pure text or HTML),
   2.374 -//     or a "multipart/alternative" if there is both text and HTML,
   2.375 -//     or nil.
   2.376 -//     */
   2.377 -//    static func bodyPart(pEpMessageDict: PEPMessageDict) -> CWPart? {
   2.378 -//        let theBodyParts = bodyParts(pEpMessageDict: pEpMessageDict)
   2.379 -//        if theBodyParts.count == 1 {
   2.380 -//            return theBodyParts[0]
   2.381 -//        } else if theBodyParts.count > 1 {
   2.382 -//            let partAlt = CWPart()
   2.383 -//            partAlt.setContentType(Constants.contentTypeMultipartAlternative)
   2.384 -//            let partMulti = CWMIMEMultipart()
   2.385 -//            for part in theBodyParts {
   2.386 -//                partMulti.add(part)
   2.387 -//            }
   2.388 -//            partAlt.setContent(partMulti)
   2.389 -//            return partAlt
   2.390 -//        }
   2.391 -//        return nil
   2.392 -//    }
   2.393 -//
   2.394 -//    /**
   2.395 -//     Builds an optional pantomime part object from an optional text,
   2.396 -//     with the given content type.
   2.397 -//     Useful for creating text/HTML parts.
   2.398 -//     */
   2.399 -//    static func makePart(text: String?, contentType: String) -> CWPart? {
   2.400 -//        if let t = text {
   2.401 -//            let part = CWPart()
   2.402 -//            part.setContentType(contentType)
   2.403 -//            part.setContent(t.data(using: String.Encoding.utf8) as NSObject?)
   2.404 -//            part.setCharset("UTF-8")
   2.405 -//            part.setContentTransferEncoding(PantomimeEncoding8bit)
   2.406 -//            return part
   2.407 -//        }
   2.408 -//        return nil
   2.409 -//    }
   2.410 -//
   2.411 -//    /**
   2.412 -//     Extracts text content from a pEp mail as a list of pantomime part object.
   2.413 -//     - Returns: A list of pantomime parts. This list can have 0, 1 or 2 elements.
   2.414 -//     */
   2.415 -//    static func bodyParts(pEpMessageDict: PEPMessageDict) -> [CWPart] {
   2.416 -//        var parts: [CWPart] = []
   2.417 -//
   2.418 -//        if let part = makePart(text: pEpMessageDict[kPepLongMessage] as? String,
   2.419 -//                               contentType: Constants.contentTypeText) {
   2.420 -//            parts.append(part)
   2.421 -//        }
   2.422 -//        if let part = makePart(text: pEpMessageDict[kPepLongMessageFormatted] as? String,
   2.423 -//                               contentType: Constants.contentTypeHtml) {
   2.424 -//            parts.append(part)
   2.425 -//        }
   2.426 -//
   2.427 -//        return parts
   2.428 -//    }
   2.429 -//
   2.430 -//    static func pEpRating(cdIdentity: CdIdentity,
   2.431 -//                                 session: PEPSession = PEPSession()) -> PEPRating {
   2.432 -//        let pepC = pEpDict(cdIdentity: cdIdentity)
   2.433 -//        do {
   2.434 -//            return try session.rating(for: pepC).pEpRating
   2.435 -//        } catch let error as NSError {
   2.436 -//            assertionFailure("\(error)")
   2.437 -//            return .undefined
   2.438 -//        }
   2.439 -//    }
   2.440 -//
   2.441 -//    static func pEpColor(cdIdentity: CdIdentity,
   2.442 -//                                session: PEPSession = PEPSession()) -> PEPColor {
   2.443 -//        return pEpColor(pEpRating: pEpRating(cdIdentity: cdIdentity, session: session))
   2.444 -//    }
   2.445 -//
   2.446 -//    static func pEpRating(identity: Identity,
   2.447 -//                                 session: PEPSession = PEPSession()) -> PEPRating {
   2.448 -//        let pepC = pEp(identity: identity)
   2.449 -//        do {
   2.450 -//            return try session.rating(for: pepC).pEpRating
   2.451 -//        } catch {
   2.452 -//            Logger.utilLogger.errorAndCrash(
   2.453 -//                "Identity: %{public}@ caused error: %{public}@",
   2.454 -//                identity.description, error.localizedDescription)
   2.455 -//            return .undefined
   2.456 -//        }
   2.457 -//    }
   2.458 -//
   2.459 -//    static func pEpColor(identity: Identity,
   2.460 -//                                session: PEPSession = PEPSession()) -> PEPColor {
   2.461 -//        return pEpColor(pEpRating: pEpRating(identity: identity, session: session))
   2.462 -//    }
   2.463 -//
   2.464 -//    static func pEpColor(pEpRating: PEPRating?,
   2.465 -//                                session: PEPSession = PEPSession()) -> PEPColor {
   2.466 -//        if let rating = pEpRating {
   2.467 -//            return session.color(from: rating)
   2.468 -//        } else {
   2.469 -//            return PEPColor.noColor
   2.470 -//        }
   2.471 -//    }
   2.472 -//
   2.473 -//    static func pEpRatingFromInt(_ i: Int?) -> PEPRating? {
   2.474 -//        guard let theInt = i else {
   2.475 -//            return nil
   2.476 -//        }
   2.477 -//        if theInt == Int(pEpRatingNone) {
   2.478 -//            return .undefined
   2.479 -//        }
   2.480 -//        return PEPRating(rawValue: theInt)
   2.481 -//    }
   2.482 -//
   2.483 -//    /**
   2.484 -//     Uses the adapter's update to determine the fingerprint of the given identity.
   2.485 -//     - Note: Also works for own identities without triggering key generation.
   2.486 -//     */
   2.487 -//    static func fingerPrint(identity: Identity, session: PEPSession = PEPSession()) throws
   2.488 -//        -> String? {
   2.489 -//            let pEpID = pEp(identity: identity)
   2.490 -//            if pEpID.isOwn {
   2.491 -//                // If we have an own identity, avoid a call to myself by nulling userID
   2.492 -//                pEpID.userID = nil
   2.493 -//                pEpID.isOwn = false
   2.494 -//            }
   2.495 -//            try session.update(pEpID)
   2.496 -//            return pEpID.fingerPrint
   2.497 -//    }
   2.498 -//
   2.499 -//    static func fingerPrint(cdIdentity: CdIdentity,
   2.500 -//                                   session: PEPSession = PEPSession()) throws -> String? {
   2.501 -//        if let theID = cdIdentity.identity() {
   2.502 -//            return try fingerPrint(identity: theID, session: session)
   2.503 -//        } else {
   2.504 -//            return nil
   2.505 -//        }
   2.506 -//    }
   2.507 -//
   2.508 -//    /**
   2.509 -//     Trust that contact (yellow to green).
   2.510 -//     */
   2.511 -//    static func trust(identity: Identity, session: PEPSession = PEPSession()) throws {
   2.512 -//        let pEpID = pEp(identity: identity)
   2.513 -//        try session.update(pEpID)
   2.514 -//        try session.trustPersonalKey(pEpID)
   2.515 -//    }
   2.516 -//
   2.517 -//    /**
   2.518 -//     Mistrust the identity (yellow to red)
   2.519 -//     */
   2.520 -//    static func mistrust(identity: Identity, session: PEPSession = PEPSession()) throws {
   2.521 -//        let pEpID = pEp(identity: identity)
   2.522 -//        try session.update(pEpID)
   2.523 -//        try session.keyMistrusted(pEpID)
   2.524 -//    }
   2.525 -//
   2.526 -//    /**
   2.527 -//     Resets the trust for the given `Identity`. Use both for trusting again after
   2.528 -//     mistrusting a key, and for mistrusting a key after you have first trusted it.
   2.529 -//     */
   2.530 -//    static func resetTrust(identity: Identity, session: PEPSession = PEPSession()) throws {
   2.531 -//        let pEpID = pEp(identity: identity)
   2.532 -//        try session.update(pEpID)
   2.533 -//        try session.keyResetTrust(pEpID)
   2.534 -//    }
   2.535 -//
   2.536 -//    static func encrypt(
   2.537 -//        pEpMessageDict: PEPMessageDict, encryptionFormat: PEPEncFormat = .PEP,
   2.538 -//        forSelf: PEPIdentity? = nil,
   2.539 -//        extraKeys: [String]? = nil,
   2.540 -//        session: PEPSession = PEPSession()) throws -> (PEPStatus, NSDictionary?) {
   2.541 -//
   2.542 -//        var status = PEPStatus.unknownError
   2.543 -//        if let ident = forSelf {
   2.544 -//            let encryptedMessage = try session.encryptMessageDict(
   2.545 -//                pEpMessageDict,
   2.546 -//                forSelf: ident,
   2.547 -//                extraKeys: extraKeys,
   2.548 -//                status: &status) as NSDictionary
   2.549 -//            return (status, encryptedMessage)
   2.550 -//        } else {
   2.551 -//            let encMessage = try session.encryptMessageDict(
   2.552 -//                pEpMessageDict,
   2.553 -//                extraKeys: nil,
   2.554 -//                encFormat: encryptionFormat,
   2.555 -//                status: &status) as NSDictionary
   2.556 -//            return (status, encMessage)
   2.557 -//        }
   2.558 -//    }
   2.559 -//
   2.560 -//    static func encrypt(
   2.561 -//        pEpMessage: PEPMessage,
   2.562 -//        forSelf: PEPIdentity? = nil,
   2.563 -//        extraKeys: [String]? = nil,
   2.564 -//        session: PEPSession = PEPSession()) throws -> (PEPStatus, PEPMessage?) {
   2.565 -//
   2.566 -//        var status = PEPStatus.unknownError
   2.567 -//        if let ident = forSelf {
   2.568 -//            let encryptedMessage = try session.encryptMessage(
   2.569 -//                pEpMessage,
   2.570 -//                forSelf: ident,
   2.571 -//                extraKeys: extraKeys,
   2.572 -//                status: &status)
   2.573 -//            return (status, encryptedMessage)
   2.574 -//        } else {
   2.575 -//            let encMessage = try session.encryptMessage(pEpMessage,
   2.576 -//                                                        extraKeys: nil,
   2.577 -//                                                        status: &status)
   2.578 -//            return (status, encMessage)
   2.579 -//        }
   2.580 -//    }
   2.581 -//
   2.582 -//    static func ownIdentity(message: Message) -> Identity? {
   2.583 -//        return message.parent.account.user
   2.584 -//    }
   2.585 -//
   2.586 -//    static func systemLanguage() -> String {
   2.587 -//        let language = Bundle.main.preferredLocalizations.first
   2.588 -//        return language!
   2.589 -//    }
   2.590 -//}