IOS-1511 moving all mimeType and contentType to same place - part 1 IOS-1511
authorAlejandro Gelos <agp@pep.security>
Mon, 06 May 2019 18:09:11 +0200
branchIOS-1511
changeset 850492d2c5a38aec
parent 8503 ce7ee916b7eb
child 8505 d5c1397f65dd
IOS-1511 moving all mimeType and contentType to same place - part 1
Submodules/pEpIOSToolbox/pEpIOSToolbox/Other/Constants.swift
pEpForiOS/UI/Compose/Cells/AttachmentCell/AttachmentViewModel.swift
pEpForiOS/UI/Compose/Util/DocumentAttachmentPickerViewController/DocumentAttachmentPickerViewModel.swift
pEpForiOS/UI/Compose/Util/MediaAttachmentPickerProvider/MediaAttachmentPickerProviderViewModel.swift
pEpForiOS/UI/EmailDisplay/Background/AttachmentToLocalURLOperation.swift
pEpForiOS/UI/EmailDisplay/EmailViewController.swift
pEpForiOS/Util/Extensions/URL+MIME.swift
pEpForiOSTests/MiscTests.swift
pEpForiOSTests/TestUtils/PEPMessage+TestExtension.swift
     1.1 --- a/Submodules/pEpIOSToolbox/pEpIOSToolbox/Other/Constants.swift	Mon May 06 16:06:41 2019 +0200
     1.2 +++ b/Submodules/pEpIOSToolbox/pEpIOSToolbox/Other/Constants.swift	Mon May 06 18:09:11 2019 +0200
     1.3 @@ -9,44 +9,8 @@
     1.4  import Foundation
     1.5  
     1.6  public struct Constants {
     1.7 -    /** MIME content type for plain text */
     1.8 -    public static let contentTypeText = "text/plain"
     1.9 -
    1.10 -    /** MIME content type for HTML */
    1.11 -    public static let contentTypeHtml = "text/html"
    1.12 -
    1.13 -    /**
    1.14 -     Mime type for the "Version" attachment of PGP/MIME.
    1.15 -     */
    1.16 -    public static let contentTypePGPEncrypted = "application/pgp-encrypted"
    1.17 -
    1.18 -    /**
    1.19 -     Content type for MIME multipart/mixed.
    1.20 -     */
    1.21 -    public static let contentTypeMultipartMixed = "multipart/mixed"
    1.22 -
    1.23 -    /**
    1.24 -     Content type for MIME multipart/related.
    1.25 -     */
    1.26 -    public static let contentTypeMultipartRelated = "multipart/related"
    1.27 -
    1.28 -    /**
    1.29 -     Content type for MIME multipart/encrypted.
    1.30 -     */
    1.31 -    public static let contentTypeMultipartEncrypted = "multipart/encrypted"
    1.32 -
    1.33      /**
    1.34       Protocol for PGP/MIME application/pgp-encrypted.
    1.35       */
    1.36      public static let protocolPGPEncrypted = "application/pgp-encrypted"
    1.37 -
    1.38 -    /**
    1.39 -     Content type for MIME multipart/alternative.
    1.40 -     */
    1.41 -    public static let contentTypeMultipartAlternative = "multipart/alternative"
    1.42 -
    1.43 -    /**
    1.44 -     The MIME type for attached emails (e.g., when forwarding).
    1.45 -     */
    1.46 -    public static let attachedEmailMimeType = "message/rfc822"
    1.47  }
     2.1 --- a/pEpForiOS/UI/Compose/Cells/AttachmentCell/AttachmentViewModel.swift	Mon May 06 16:06:41 2019 +0200
     2.2 +++ b/pEpForiOS/UI/Compose/Cells/AttachmentCell/AttachmentViewModel.swift	Mon May 06 18:09:11 2019 +0200
     2.3 @@ -15,6 +15,7 @@
     2.4      public var fileName: String {
     2.5          return attachment.fileName ?? AttachmentViewModel.defaultFileName
     2.6      }
     2.7 +
     2.8      public var fileExtension: String {
     2.9          return mimeTypeUtil?.fileExtension(mimeType: attachment.mimeType) ?? ""
    2.10      }
     3.1 --- a/pEpForiOS/UI/Compose/Util/DocumentAttachmentPickerViewController/DocumentAttachmentPickerViewModel.swift	Mon May 06 16:06:41 2019 +0200
     3.2 +++ b/pEpForiOS/UI/Compose/Util/DocumentAttachmentPickerViewController/DocumentAttachmentPickerViewModel.swift	Mon May 06 18:09:11 2019 +0200
     3.3 @@ -67,7 +67,7 @@
     3.4                  completion(nil)
     3.5                  return
     3.6              }
     3.7 -            let mimeType = resourceUrl.mimeType() ?? MimeTypeUtil.defaultMimeType
     3.8 +            let mimeType = resourceUrl.mimeType() ?? MimeTypeUtil.MimesType.defaultMimeType
     3.9              let filename = resourceUrl.fileName(includingExtension: true)
    3.10              let attachment = Attachment.create(data: resourceData,
    3.11                                                 mimeType: mimeType,
     4.1 --- a/pEpForiOS/UI/Compose/Util/MediaAttachmentPickerProvider/MediaAttachmentPickerProviderViewModel.swift	Mon May 06 16:06:41 2019 +0200
     4.2 +++ b/pEpForiOS/UI/Compose/Util/MediaAttachmentPickerProvider/MediaAttachmentPickerProviderViewModel.swift	Mon May 06 18:09:11 2019 +0200
     4.3 @@ -91,7 +91,7 @@
     4.4                  completion(nil)
     4.5                  return
     4.6              }
     4.7 -            let mimeType = resourceUrl.mimeType() ?? MimeTypeUtil.defaultMimeType
     4.8 +            let mimeType = resourceUrl.mimeType() ?? MimeTypeUtil.MimesType.defaultMimeType
     4.9              let filename = me.fileName(forVideoAt: resourceUrl)
    4.10              let attachment =  Attachment.create(data: resourceData,
    4.11                                                  mimeType: mimeType,
    4.12 @@ -113,7 +113,7 @@
    4.13  
    4.14      private func createAttachment(forAssetWithUrl assetUrl: URL,
    4.15                                    image: UIImage) -> Attachment {
    4.16 -        let mimeType = assetUrl.mimeType() ?? MimeTypeUtil.defaultMimeType
    4.17 +        let mimeType = assetUrl.mimeType() ?? MimeTypeUtil.MimesType.defaultMimeType
    4.18          return Attachment.createFromAsset(mimeType: mimeType,
    4.19                                            assetUrl: assetUrl,
    4.20                                            image: image,
     5.1 --- a/pEpForiOS/UI/EmailDisplay/Background/AttachmentToLocalURLOperation.swift	Mon May 06 16:06:41 2019 +0200
     5.2 +++ b/pEpForiOS/UI/EmailDisplay/Background/AttachmentToLocalURLOperation.swift	Mon May 06 18:09:11 2019 +0200
     5.3 @@ -37,7 +37,7 @@
     5.4          
     5.5          var theURL = tmpDir.appendingPathComponent(fileName)
     5.6  
     5.7 -        if attachment.mimeType == "application/pdf" {
     5.8 +        if attachment.mimeType == MimeTypeUtil.MimesType.pdf {
     5.9              theURL = theURL.appendingPathExtension("pdf")
    5.10          }
    5.11          do {
     6.1 --- a/pEpForiOS/UI/EmailDisplay/EmailViewController.swift	Mon May 06 16:06:41 2019 +0200
     6.2 +++ b/pEpForiOS/UI/EmailDisplay/EmailViewController.swift	Mon May 06 18:09:11 2019 +0200
     6.3 @@ -649,7 +649,8 @@
     6.4  
     6.5      func didCreateLocally(attachment: Attachment, url: URL, cell: MessageCell, location: CGPoint,
     6.6                            inView: UIView?) {
     6.7 -        if attachment.mimeType == "application/pdf" && QLPreviewController.canPreview(url as QLPreviewItem){
     6.8 +        if attachment.mimeType == MimeTypeUtil.MimesType.pdf
     6.9 +            && QLPreviewController.canPreview(url as QLPreviewItem){
    6.10                  selectedAttachmentURL = url
    6.11                  let previewController = QLPreviewController()
    6.12                  previewController.dataSource = self
     7.1 --- a/pEpForiOS/Util/Extensions/URL+MIME.swift	Mon May 06 16:06:41 2019 +0200
     7.2 +++ b/pEpForiOS/Util/Extensions/URL+MIME.swift	Mon May 06 18:09:11 2019 +0200
     7.3 @@ -12,6 +12,6 @@
     7.4  
     7.5  extension URL {
     7.6      public func mimeType() -> String? {
     7.7 -        return MimeTypeUtil()?.mimeType(fileExtension: self.pathExtension)
     7.8 +        return MimeTypeUtil()?.mimeType(fileExtension: pathExtension)
     7.9      }
    7.10  }
     8.1 --- a/pEpForiOSTests/MiscTests.swift	Mon May 06 16:06:41 2019 +0200
     8.2 +++ b/pEpForiOSTests/MiscTests.swift	Mon May 06 18:09:11 2019 +0200
     8.3 @@ -35,7 +35,7 @@
     8.4      func testMimeTypeJson() {
     8.5          let mimeTypeController = MimeTypeUtil()
     8.6          let s = mimeTypeController?.mimeType(fileExtension: "pdf")
     8.7 -        XCTAssertEqual(s, "application/pdf")
     8.8 +        XCTAssertEqual(s, MimeTypeUtil.MimesType.pdf)
     8.9      }
    8.10  
    8.11      func testBinaryIndex() {
     9.1 --- a/pEpForiOSTests/TestUtils/PEPMessage+TestExtension.swift	Mon May 06 16:06:41 2019 +0200
     9.2 +++ b/pEpForiOSTests/TestUtils/PEPMessage+TestExtension.swift	Mon May 06 18:09:11 2019 +0200
     9.3 @@ -14,10 +14,12 @@
     9.4  
     9.5  extension PEPMessage {
     9.6      public func isLikelyPEPEncrypted() -> Bool {
     9.7 -        let theAttachments = attachments ?? []
     9.8 -        return theAttachments.count == 2 &&
     9.9 -            theAttachments[0].mimeType == "application/pgp-encrypted" &&
    9.10 -            theAttachments[1].mimeType == "application/octet-stream" &&
    9.11 -            theAttachments[1].filename == "file://msg.asc"
    9.12 +        guard let attachments = attachments else {
    9.13 +            return false
    9.14 +        }
    9.15 +        return attachments.count == 2 &&
    9.16 +            attachments[0].mimeType == MimeTypeUtil.MimesType.pgpEncrypted &&
    9.17 +            attachments[1].mimeType == MimeTypeUtil.MimesType.defaultMimeType &&
    9.18 +            attachments[1].filename == "file://msg.asc"
    9.19      }
    9.20  }