IOS-1480 Move MimeTypeUtil. IOS-1480
authorDirk Zimmermann <dz@pep.security>
Mon, 18 Feb 2019 13:21:12 +0100
branchIOS-1480
changeset 7685accbfaa4f796
parent 7684 d79e9c6f0b49
child 7686 fc544fea26cf
IOS-1480 Move MimeTypeUtil.
pEpForiOS.xcodeproj/project.pbxproj
pEpForiOS/Util/MimeTypeUtil.swift
     1.1 --- a/pEpForiOS.xcodeproj/project.pbxproj	Mon Feb 18 13:21:12 2019 +0100
     1.2 +++ b/pEpForiOS.xcodeproj/project.pbxproj	Mon Feb 18 13:21:12 2019 +0100
     1.3 @@ -499,7 +499,6 @@
     1.4  		B73119001FEBE2DB0006573B /* SwipeCellKit.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 439932311FEA9B7200E92C35 /* SwipeCellKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
     1.5  		B7365CDE1EAF45F30036ECC7 /* UITextField+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = B7365CDD1EAF45F30036ECC7 /* UITextField+Extension.swift */; };
     1.6  		B740B75D1E4B1C2D002585E1 /* jsonMimeType.txt in Resources */ = {isa = PBXBuildFile; fileRef = B740B75C1E4B1C2D002585E1 /* jsonMimeType.txt */; };
     1.7 -		B740B75F1E4B1C46002585E1 /* MimeTypeUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = B740B75E1E4B1C46002585E1 /* MimeTypeUtil.swift */; };
     1.8  		B74F81021EB0E20000519FCC /* LoginViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B74F81011EB0E20000519FCC /* LoginViewModel.swift */; };
     1.9  		B75FF00B1EFD420F00C57289 /* EmailListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B75FF00A1EFD420F00C57289 /* EmailListViewModel.swift */; };
    1.10  		B761A80A20F5F0A6000832C2 /* UIBarButtonItem+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = B761A80920F5F0A6000832C2 /* UIBarButtonItem+Extension.swift */; };
    1.11 @@ -1082,7 +1081,6 @@
    1.12  		B729BEC51E7C35E200793110 /* FilterUpdateProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FilterUpdateProtocol.swift; path = Filter/ViewModel/FilterUpdateProtocol.swift; sourceTree = "<group>"; };
    1.13  		B7365CDD1EAF45F30036ECC7 /* UITextField+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UITextField+Extension.swift"; sourceTree = "<group>"; };
    1.14  		B740B75C1E4B1C2D002585E1 /* jsonMimeType.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = jsonMimeType.txt; sourceTree = "<group>"; };
    1.15 -		B740B75E1E4B1C46002585E1 /* MimeTypeUtil.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MimeTypeUtil.swift; sourceTree = "<group>"; };
    1.16  		B74F81011EB0E20000519FCC /* LoginViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoginViewModel.swift; sourceTree = "<group>"; };
    1.17  		B75FF00A1EFD420F00C57289 /* EmailListViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EmailListViewModel.swift; sourceTree = "<group>"; };
    1.18  		B761A80920F5F0A6000832C2 /* UIBarButtonItem+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIBarButtonItem+Extension.swift"; sourceTree = "<group>"; };
    1.19 @@ -2684,7 +2682,6 @@
    1.20  			isa = PBXGroup;
    1.21  			children = (
    1.22  				B740B75C1E4B1C2D002585E1 /* jsonMimeType.txt */,
    1.23 -				B740B75E1E4B1C46002585E1 /* MimeTypeUtil.swift */,
    1.24  			);
    1.25  			name = MimeTypes;
    1.26  			sourceTree = "<group>";
    1.27 @@ -3062,7 +3059,6 @@
    1.28  				B729BEC61E7C35E200793110 /* FilterUpdateProtocol.swift in Sources */,
    1.29  				431798771CF87FE6007DD655 /* ReferenceCounter.swift in Sources */,
    1.30  				15874BC62127493E00A3A4A6 /* SettingsTableViewController.swift in Sources */,
    1.31 -				B740B75F1E4B1C46002585E1 /* MimeTypeUtil.swift in Sources */,
    1.32  				002375D320DCDC7300663961 /* FullMessageCell+SecureWebViewControllerDelegate.swift in Sources */,
    1.33  				4351C2C91F4441190053381F /* buffer.c in Sources */,
    1.34  				152A39C621905C3E00D9F8E4 /* ComposeViewModelState.swift in Sources */,
     2.1 --- a/pEpForiOS/Util/MimeTypeUtil.swift	Mon Feb 18 13:21:12 2019 +0100
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,69 +0,0 @@
     2.4 -//
     2.5 -//  MimeTypeUtil.swift
     2.6 -//  pEpForiOS
     2.7 -//
     2.8 -//  Created by Xavier Algarra on 08/02/17.
     2.9 -//  Copyright © 2017 p≡p Security S.A. All rights reserved.
    2.10 -//
    2.11 -
    2.12 -import Foundation
    2.13 -
    2.14 -open class MimeTypeUtil {
    2.15 -    public static let defaultMimeType = "application/octet-stream"
    2.16 -    public static let jpegMimeType = "image/jpeg"
    2.17 -
    2.18 -    /**
    2.19 -     Content type/mime type for attached keys.
    2.20 -     */
    2.21 -    public static let contentTypeApplicationPGPKeys = "application/pgp-keys"
    2.22 -
    2.23 -    private let comp = "MimeTypeUtil"
    2.24 -    private var mimeTypeToExtension = [String: String]()
    2.25 -    private var extensionToMimeType = [String: String]()
    2.26 -
    2.27 -    public init?() {
    2.28 -        let resource = "jsonMimeType"
    2.29 -        let type = "txt"
    2.30 -        do {
    2.31 -            if let file = Bundle.main.path(forResource: resource, ofType: type) {
    2.32 -                let data = try Data(contentsOf: URL(fileURLWithPath: file))
    2.33 -                guard let json = try JSONSerialization.jsonObject(with: data, options: [])
    2.34 -                    as? [String:Any] else {
    2.35 -                        return nil
    2.36 -                }
    2.37 -                guard let theData = json["mimeType"] as? [String: String] else {
    2.38 -                    return nil
    2.39 -                }
    2.40 -                for (theExtension, mimeType) in theData {
    2.41 -                    mimeTypeToExtension[mimeType.lowercased()] = theExtension
    2.42 -                    extensionToMimeType[theExtension.lowercased()] = mimeType
    2.43 -                }
    2.44 -                // "image/jpeg" is missing in ourt data. Fix it.
    2.45 -                mimeTypeToExtension[MimeTypeUtil.jpegMimeType] = "jpg"
    2.46 -            }
    2.47 -        } catch {
    2.48 -            Logger.utilLogger.log(error: error)
    2.49 -            return nil
    2.50 -        }
    2.51 -    }
    2.52 -
    2.53 -    open func fileExtension(mimeType: String) -> String? {
    2.54 -        return mimeTypeToExtension[mimeType.lowercased()]
    2.55 -    }
    2.56 -
    2.57 -    open func mimeType(fileExtension: String) -> String {
    2.58 -        return extensionToMimeType[fileExtension.lowercased()] ?? MimeTypeUtil.defaultMimeType
    2.59 -    }
    2.60 -
    2.61 -    /**
    2.62 -     Is the given mimetype suitable for creating an `UIImage`?
    2.63 -     */
    2.64 -    open func isImage(mimeType theMimeType: String) -> Bool {
    2.65 -        let lcMT = theMimeType.lowercased()
    2.66 -        if lcMT == mimeType(fileExtension: "png") || lcMT == mimeType(fileExtension: "jpg") ||
    2.67 -            lcMT == mimeType(fileExtension: "gif") {
    2.68 -            return true
    2.69 -        }
    2.70 -        return false
    2.71 -    }
    2.72 -}