IOS-1521 App target builds again IOS-1521
authorbuff <andreas@pep-project.org>
Mon, 18 Mar 2019 18:37:11 +0100
branchIOS-1521
changeset 80185c633191f4ed
parent 8005 62899e6aadbf
child 8034 759933d37b5f
IOS-1521 App target builds again
pEpForiOS/Background/DecryptMessagesOperation.swift
pEpForiOS/Models/Account+Extentions.swift
pEpForiOS/Models/CdFolder+Extension.swift
pEpForiOS/Models/CdMessage+Extension.swift
pEpForiOS/Models/CdMessage+Pantomime.swift
pEpForiOS/Models/Filter/AttachmentFilter.swift
pEpForiOS/Models/Filter/UnifiedFilter.swift
pEpForiOS/Models/Folder+Extensions.swift
pEpForiOS/Models/FolderType+IMAP.swift
pEpForiOS/Models/ImapFlags+Pantomime.swift
pEpForiOS/Models/Message+FakeMessage.swift
pEpForiOS/Models/Message+IMAP.swift
pEpForiOS/Models/Message+pEp.swift
pEpForiOS/Models/UnifiedInbox.swift
pEpForiOS/UI/Compose/Cells/AttachmentCell/AttachmentViewModel.swift
pEpForiOS/UI/Compose/Util/ComposeUtil.swift
pEpForiOS/UI/Compose/ViewModel/ComposeViewModel.swift
pEpForiOS/UI/EmailDisplay/Background/AttachmentsViewOperation.swift
pEpForiOS/UI/EmailDisplay/EmailViewController.swift
pEpForiOS/UI/EmailDisplay/Stuff that is named Compose but is used only in EmailView/ComposeDataSource.swift
pEpForiOS/UI/EmailDisplay/Util/AttachmentsViewHelper.swift
pEpForiOS/UI/EmailDisplay/Util/FlagImages.swift
pEpForiOS/UI/EmailDisplayList/EmailListViewModel.swift
pEpForiOS/UI/EmailDisplayList/MessageViewModel.swift
pEpForiOS/UI/Settings/Setting/AccountSettings/ViewModel/AccountSettingsViewModel.swift
pEpForiOS/UI/Thread/ViewModel/ThreadedEmailViewModel.swift
pEpForiOS/Util/Extensions/Attachment+Extension.swift
pEpForiOS/Util/Extensions/NSAttributedString+pEp.swift
pEpForiOS/Util/ReplyUtil.swift
     1.1 --- a/pEpForiOS/Background/DecryptMessagesOperation.swift	Thu Mar 14 12:51:48 2019 +0100
     1.2 +++ b/pEpForiOS/Background/DecryptMessagesOperation.swift	Mon Mar 18 18:37:11 2019 +0100
     1.3 @@ -179,7 +179,7 @@
     1.4          updateMessage(cdMessage: cdMessage, keys: keys, pEpMessageDict: decrypted, rating: rating)
     1.5      }
     1.6  
     1.7 -    private func setFlags(_ flags: Message.ImapFlags?,
     1.8 +    private func setFlags(_ flags: ImapFlags?,
     1.9                            toCdMessage cdMessage: CdMessage) {
    1.10          guard let imapFlags = flags else {
    1.11              // That's OK.
     2.1 --- a/pEpForiOS/Models/Account+Extentions.swift	Thu Mar 14 12:51:48 2019 +0100
     2.2 +++ b/pEpForiOS/Models/Account+Extentions.swift	Mon Mar 18 18:37:11 2019 +0100
     2.3 @@ -61,10 +61,7 @@
     2.4  
     2.5      static func emailConnectInfo(account: Account, server: Server,
     2.6                            credentials: ServerCredentials) -> EmailConnectInfo? {
     2.7 -        guard
     2.8 -            let emailProtocol = EmailProtocol(serverType: server.serverType),
     2.9 -            let connectionTransport = server.transport
    2.10 -            else {
    2.11 +        guard let emailProtocol = EmailProtocol(serverType: server.serverType) else {
    2.12                  Logger.modelLogger.errorAndCrash("Missing emailProtocol")
    2.13                  return nil
    2.14          }
    2.15 @@ -82,7 +79,7 @@
    2.16                                  networkAddressType: nil,
    2.17                                  networkTransportType: nil,
    2.18                                  emailProtocol: emailProtocol,
    2.19 -                                connectionTransport: ConnectionTransport(fromInt: Int(connectionTransport.rawValue)),
    2.20 +                                connectionTransport: ConnectionTransport(fromInt: Int(server.transport.rawValue)),
    2.21                                  authMethod: AuthMethod(string: server.authMethod),
    2.22                                  trusted: trusedServer)
    2.23      }
     3.1 --- a/pEpForiOS/Models/CdFolder+Extension.swift	Thu Mar 14 12:51:48 2019 +0100
     3.2 +++ b/pEpForiOS/Models/CdFolder+Extension.swift	Mon Mar 18 18:37:11 2019 +0100
     3.3 @@ -141,7 +141,6 @@
     3.4          let folder = CdFolder.create(context: context)
     3.5          folder.name = folderName
     3.6          folder.account = account
     3.7 -        folder.uuid = MessageID.generate()
     3.8          if let type = folderType {
     3.9              folder.folderType = type
    3.10          }
     4.1 --- a/pEpForiOS/Models/CdMessage+Extension.swift	Thu Mar 14 12:51:48 2019 +0100
     4.2 +++ b/pEpForiOS/Models/CdMessage+Extension.swift	Mon Mar 18 18:37:11 2019 +0100
     4.3 @@ -56,7 +56,7 @@
     4.4          return msg
     4.5      }
     4.6  
     4.7 -    @discardableResult public static func create(withContentOf msg: Message) -> CdMessage? {
     4.8 +    @discardableResult public static func create(withContentOf msg: Message) -> CdMessage? {  //!!!: MUST NOT, be in app!?
     4.9          guard
    4.10              let cdParentFolder = msg.parent.cdFolder(),
    4.11              let from = msg.from?.cdIdentity() else {
    4.12 @@ -69,14 +69,13 @@
    4.13          createe.parent = cdParentFolder
    4.14  
    4.15          createe.imap = CdImapFields.create()
    4.16 -        createe.imap?.imapFlags().uid = Int32(msg.uid)
    4.17  
    4.18 -        createe.imap?.localFlags?.flagAnswered = msg.imapFlags?.answered ?? false
    4.19 -        createe.imap?.localFlags?.flagDeleted = msg.imapFlags?.deleted ?? false
    4.20 -        createe.imap?.localFlags?.flagDraft = msg.imapFlags?.draft ?? false
    4.21 -        createe.imap?.localFlags?.flagFlagged = msg.imapFlags?.flagged ?? false
    4.22 -        createe.imap?.localFlags?.flagRecent = msg.imapFlags?.recent ?? false
    4.23 -        createe.imap?.localFlags?.flagSeen = msg.imapFlags?.seen ?? false
    4.24 +        createe.imap?.localFlags?.flagAnswered = msg.imapFlags.answered
    4.25 +        createe.imap?.localFlags?.flagDeleted = msg.imapFlags.deleted
    4.26 +        createe.imap?.localFlags?.flagDraft = msg.imapFlags.draft
    4.27 +        createe.imap?.localFlags?.flagFlagged = msg.imapFlags.flagged
    4.28 +        createe.imap?.localFlags?.flagRecent = msg.imapFlags.recent
    4.29 +        createe.imap?.localFlags?.flagSeen = msg.imapFlags.seen
    4.30  
    4.31          createe.shortMessage = msg.shortMessage
    4.32          createe.longMessage = msg.longMessage
    4.33 @@ -86,7 +85,6 @@
    4.34          createe.attachments = NSOrderedSet(array: cdAttachments)
    4.35  
    4.36          createe.sent = msg.sent
    4.37 -        createe.received = msg.received
    4.38          createe.from = from
    4.39  
    4.40          let cdTos = msg.to.compactMap { $0.cdIdentity() }
    4.41 @@ -98,19 +96,8 @@
    4.42          let cdBccs = msg.bcc.compactMap { $0.cdIdentity() }
    4.43          createe.bcc = NSOrderedSet(array: cdBccs)
    4.44  
    4.45 -        createe.receivedBy = msg.receivedBy?.cdIdentity()
    4.46 -
    4.47 -        let cdReplyTo = msg.replyTo.compactMap { $0.cdIdentity() }
    4.48 -        createe.replyTo = NSOrderedSet(array: cdReplyTo)
    4.49 -
    4.50 -        createe.replace(referenceStrings: msg.references)
    4.51 -        createe.keywords = NSSet(array: msg.keywords)
    4.52 -        createe.comments = msg.comments
    4.53 -
    4.54          createe.pEpRating = Int16(msg.pEpRating().rawValue)
    4.55  
    4.56 -        createe.keysFromDecryption = NSOrderedSet(array: msg.keyListFromDecryption)
    4.57 -
    4.58          return createe
    4.59      }
    4.60  
     5.1 --- a/pEpForiOS/Models/CdMessage+Pantomime.swift	Thu Mar 14 12:51:48 2019 +0100
     5.2 +++ b/pEpForiOS/Models/CdMessage+Pantomime.swift	Mon Mar 18 18:37:11 2019 +0100
     5.3 @@ -449,10 +449,10 @@
     5.4      }
     5.5      
     5.6      static private func informDelegate(messageUpdated cdMmessage:CdMessage) {
     5.7 -        guard let msg = cdMmessage.message(), let flags = msg.imapFlags else {
     5.8 +        guard let msg = cdMmessage.message() else {
     5.9              return
    5.10          }
    5.11 -        if !flags.deleted {
    5.12 +        if !msg.imapFlags.deleted {
    5.13              MessageModelConfig.messageFolderDelegate?.didUpdate(message: msg)
    5.14          } else {
    5.15              MessageModelConfig.messageFolderDelegate?.didDelete(message: msg)
     6.1 --- a/pEpForiOS/Models/Filter/AttachmentFilter.swift	Thu Mar 14 12:51:48 2019 +0100
     6.2 +++ b/pEpForiOS/Models/Filter/AttachmentFilter.swift	Mon Mar 18 18:37:11 2019 +0100
     6.3 @@ -28,7 +28,7 @@
     6.4  
     6.5      public override func fulfillsFilter(message: Message) -> Bool {
     6.6          let viewableAttachments = message.attachments.filter {
     6.7 -            !AttachmentFilter.unviewableMimeTypes.contains($0.mimeType.lowercased())
     6.8 +            !AttachmentFilter.unviewableMimeTypes.contains($0.mimeType?.lowercased() ?? "DIRTY FIX - FILTER WILL BE REMOVED ANYWAY") //!!!:
     6.9          }
    6.10          return viewableAttachments.count > 0
    6.11      }
     7.1 --- a/pEpForiOS/Models/Filter/UnifiedFilter.swift	Thu Mar 14 12:51:48 2019 +0100
     7.2 +++ b/pEpForiOS/Models/Filter/UnifiedFilter.swift	Mon Mar 18 18:37:11 2019 +0100
     7.3 @@ -29,7 +29,7 @@
     7.4      public override func fulfillsFilter(message: Message) -> Bool {
     7.5          return message.parent.folderType == .inbox &&
     7.6              message.targetFolder == nil &&
     7.7 -            !(message.imapFlags?.deleted ?? false)
     7.8 +            !message.imapFlags.deleted
     7.9      }
    7.10  
    7.11      public override var hashValue: Int {
     8.1 --- a/pEpForiOS/Models/Folder+Extensions.swift	Thu Mar 14 12:51:48 2019 +0100
     8.2 +++ b/pEpForiOS/Models/Folder+Extensions.swift	Mon Mar 18 18:37:11 2019 +0100
     8.3 @@ -18,7 +18,7 @@
     8.4      }
     8.5  
     8.6      public func messageCount() -> Int {
     8.7 -        return allCdMessagesCount(ignoringPepRating: showsMessagesNeverSeenByEngine)
     8.8 +        return  allMessagesNonThreaded().count //allCdMessagesCount(ignoringPepRating: showsMessagesNeverSeenByEngine) //!!!: let CD count please
     8.9      }
    8.10  
    8.11      public func indexOf(message: Message) -> Int? {
     9.1 --- a/pEpForiOS/Models/FolderType+IMAP.swift	Thu Mar 14 12:51:48 2019 +0100
     9.2 +++ b/pEpForiOS/Models/FolderType+IMAP.swift	Mon Mar 18 18:37:11 2019 +0100
     9.3 @@ -16,10 +16,10 @@
     9.4      ///
     9.5      /// - Returns:  If flags are defined for this type:: the flags.
     9.6      ///             nil otherwize
     9.7 -    func defaultAppendImapFlags() -> Message.ImapFlags? {
     9.8 +    func defaultAppendImapFlags() -> ImapFlags? {
     9.9          switch self {
    9.10          case .sent:
    9.11 -            let result = Message.ImapFlags()
    9.12 +            let result = ImapFlags()
    9.13              result.seen = true
    9.14              return result
    9.15          case .archive, .drafts, .inbox, .normal, .trash, .spam, .all, .flagged, .outbox:
    10.1 --- a/pEpForiOS/Models/ImapFlags+Pantomime.swift	Thu Mar 14 12:51:48 2019 +0100
    10.2 +++ b/pEpForiOS/Models/ImapFlags+Pantomime.swift	Mon Mar 18 18:37:11 2019 +0100
    10.3 @@ -8,7 +8,7 @@
    10.4  
    10.5  import MessageModel
    10.6  
    10.7 -extension Message.ImapFlags {
    10.8 +extension ImapFlags {
    10.9  
   10.10      open func pantomimeFlags() -> CWFlags? {
   10.11          let n = Int(rawFlagsAsShort())
    11.1 --- a/pEpForiOS/Models/Message+FakeMessage.swift	Thu Mar 14 12:51:48 2019 +0100
    11.2 +++ b/pEpForiOS/Models/Message+FakeMessage.swift	Mon Mar 18 18:37:11 2019 +0100
    11.3 @@ -47,12 +47,12 @@
    11.4          let fakeMsg = Message(uid: Message.uidFakeResponsivenes,
    11.5                                message: self,
    11.6                                parentFolder: targetFolder)
    11.7 -        if let origFlags = self.imapFlags {
    11.8 -            // Take over user editable flags
    11.9 -            fakeMsg.imapFlags?.flagged = origFlags.flagged
   11.10 -            fakeMsg.imapFlags?.seen = origFlags.seen
   11.11 -            fakeMsg.imapFlags?.answered = origFlags.answered
   11.12 -        }
   11.13 +        let origFlags = self.imapFlags
   11.14 +        // Take over user editable flags
   11.15 +        fakeMsg.imapFlags.flagged = origFlags.flagged
   11.16 +        fakeMsg.imapFlags.seen = origFlags.seen
   11.17 +        fakeMsg.imapFlags.answered = origFlags.answered
   11.18 +
   11.19          fakeMsg.targetFolder = nil
   11.20          fakeMsg.save()
   11.21      }
    12.1 --- a/pEpForiOS/Models/Message+IMAP.swift	Thu Mar 14 12:51:48 2019 +0100
    12.2 +++ b/pEpForiOS/Models/Message+IMAP.swift	Mon Mar 18 18:37:11 2019 +0100
    12.3 @@ -45,7 +45,7 @@
    12.4                  "This method must not be called for messages in local folders.")
    12.5              return
    12.6          }
    12.7 -        let theFlags = imapFlags ?? ImapFlags()
    12.8 +        let theFlags = imapFlags
    12.9          theFlags.deleted = true
   12.10          self.save()
   12.11      }
    13.1 --- a/pEpForiOS/Models/Message+pEp.swift	Thu Mar 14 12:51:48 2019 +0100
    13.2 +++ b/pEpForiOS/Models/Message+pEp.swift	Mon Mar 18 18:37:11 2019 +0100
    13.3 @@ -53,7 +53,7 @@
    13.4          return PEP_rating.fromString(str: originalRatingStr)
    13.5      }
    13.6  
    13.7 -    private func setOriginalRatingHeader(rating: String) {
    13.8 +    private func setOriginalRatingHeader(rating: String) { //!!!: to MM please
    13.9          return optionalFields[Headers.originalRating.rawValue] = rating
   13.10      }
   13.11  
   13.12 @@ -97,7 +97,8 @@
   13.13  
   13.14      private var ratingIsOkToShowAttachments: Bool {
   13.15          var isOkToShowAttachments = true
   13.16 -        if let msgRatingInt = pEpRatingInt, let rating = PEPUtil.pEpRatingFromInt(msgRatingInt) {
   13.17 +        let msgRatingInt = pEpRatingInt
   13.18 +        if let rating = PEPUtil.pEpRatingFromInt(msgRatingInt) {
   13.19              isOkToShowAttachments = !rating.dontShowAttachments()
   13.20          }
   13.21          return isOkToShowAttachments
    14.1 --- a/pEpForiOS/Models/UnifiedInbox.swift	Thu Mar 14 12:51:48 2019 +0100
    14.2 +++ b/pEpForiOS/Models/UnifiedInbox.swift	Mon Mar 18 18:37:11 2019 +0100
    14.3 @@ -7,6 +7,7 @@
    14.4  
    14.5  import MessageModel
    14.6  import pEpIOSToolbox
    14.7 +import CoreData
    14.8  
    14.9  public class UnifiedInbox: Folder {
   14.10      static public let defaultUnifiedInboxName = "Unified Inbox"
   14.11 @@ -28,6 +29,7 @@
   14.12          }
   14.13      }
   14.14  
   14.15 +    //!!!: This is wrong! It creates a CdFolder!
   14.16      public init() {
   14.17          super.init(
   14.18              name: UnifiedInbox.defaultUnifiedInboxName,
   14.19 @@ -38,6 +40,10 @@
   14.20          resetFilter()
   14.21      }
   14.22  
   14.23 +    required init(cdObject: CdFolder, context: NSManagedObjectContext) {
   14.24 +        fatalError("init(cdObject:context:) has not been implemented. Actually MUST NOT be in UnifiedInbox")
   14.25 +    }
   14.26 +
   14.27      private func fakeAccount() -> Account {
   14.28          return UnifiedInbox.fakeAccount()
   14.29      }
   14.30 @@ -51,10 +57,6 @@
   14.31          return Account(user: fakeId, servers: [Server]())
   14.32      }
   14.33  
   14.34 -    override open func save() {
   14.35 -        // do nothing. Unified Inbox can not be saved
   14.36 -    }
   14.37 -
   14.38      override public var realName: String {
   14.39          return name
   14.40      }
   14.41 @@ -86,7 +88,7 @@
   14.42              return theFilter.fulfillsFilter(message: message)
   14.43          }
   14.44  
   14.45 -        var result = !(message.imapFlags?.deleted ?? false) && message.parent.folderType == .inbox
   14.46 +        var result = !message.imapFlags.deleted && message.parent.folderType == .inbox
   14.47          if !markedForMoveToFolderAreContained {
   14.48              result =
   14.49                  result && (message.targetFolder == nil || message.targetFolder == message.parent)
    15.1 --- a/pEpForiOS/UI/Compose/Cells/AttachmentCell/AttachmentViewModel.swift	Thu Mar 14 12:51:48 2019 +0100
    15.2 +++ b/pEpForiOS/UI/Compose/Cells/AttachmentCell/AttachmentViewModel.swift	Mon Mar 18 18:37:11 2019 +0100
    15.3 @@ -16,7 +16,10 @@
    15.4          return attachment.fileName ?? AttachmentViewModel.defaultFileName
    15.5      }
    15.6      public var fileExtension: String {
    15.7 -        return mimeTypeUtil?.fileExtension(mimeType: attachment.mimeType) ?? ""
    15.8 +        if let mimeType = attachment.mimeType {
    15.9 +            return mimeTypeUtil?.fileExtension(mimeType: mimeType) ?? ""
   15.10 +        }
   15.11 +        return ""
   15.12      }
   15.13  
   15.14      public let attachment: Attachment
    16.1 --- a/pEpForiOS/UI/Compose/Util/ComposeUtil.swift	Thu Mar 14 12:51:48 2019 +0100
    16.2 +++ b/pEpForiOS/UI/Compose/Util/ComposeUtil.swift	Mon Mar 18 18:37:11 2019 +0100
    16.3 @@ -171,9 +171,7 @@
    16.4              message.setOriginalRatingHeader(rating: state.rating)
    16.5          }
    16.6  
    16.7 -        message.imapFlags?.seen = imapSeenState(forMessageToSend: message)
    16.8 -
    16.9 -        updateReferences(of: message, accordingTo: state)
   16.10 +        message.imapFlags.seen = imapSeenState(forMessageToSend: message)
   16.11  
   16.12          return message
   16.13      }
   16.14 @@ -185,23 +183,4 @@
   16.15              return false
   16.16          }
   16.17      }
   16.18 -
   16.19 -    static private func updateReferences(of message: Message,
   16.20 -                                         accordingTo composeState:
   16.21 -        ComposeViewModel.ComposeViewModelState) {
   16.22 -        guard let composeMode = composeState.initData?.composeMode else {
   16.23 -            Logger.utilLogger.errorAndCrash("No init data")
   16.24 -            return
   16.25 -        }
   16.26 -        if composeMode == .replyFrom || composeMode == .replyAll,
   16.27 -            let om = composeState.initData?.originalMessage {
   16.28 -            // According to https://cr.yp.to/immhf/thread.html
   16.29 -            var refs = om.references
   16.30 -            refs.append(om.messageID)
   16.31 -            if refs.count > 11 {
   16.32 -                refs.remove(at: 1)
   16.33 -            }
   16.34 -            message.references = refs
   16.35 -        }
   16.36 -    }
   16.37  }
    17.1 --- a/pEpForiOS/UI/Compose/ViewModel/ComposeViewModel.swift	Thu Mar 14 12:51:48 2019 +0100
    17.2 +++ b/pEpForiOS/UI/Compose/ViewModel/ComposeViewModel.swift	Mon Mar 18 18:37:11 2019 +0100
    17.3 @@ -169,7 +169,7 @@
    17.4          }
    17.5          // Make sure the "draft" flag is not set to avoid the original msg will keep in virtual
    17.6          // mailboxes, that show all flagged messages.
    17.7 -        om.imapFlags?.draft = false
    17.8 +        om.imapFlags.draft = false
    17.9          om.imapMarkDeleted()
   17.10          resultDelegate?.composeViewModelDidDeleteMessage()
   17.11      }
   17.12 @@ -576,7 +576,7 @@
   17.13              return
   17.14          }
   17.15          msg.parent = f
   17.16 -        msg.imapFlags?.draft = true
   17.17 +        msg.imapFlags.draft = true
   17.18          msg.sent = Date()
   17.19          Message.saveForAppend(msg: msg)
   17.20          if data.isDrafts {
    18.1 --- a/pEpForiOS/UI/EmailDisplay/Background/AttachmentsViewOperation.swift	Thu Mar 14 12:51:48 2019 +0100
    18.2 +++ b/pEpForiOS/UI/EmailDisplay/Background/AttachmentsViewOperation.swift	Mon Mar 18 18:37:11 2019 +0100
    18.3 @@ -57,7 +57,14 @@
    18.4                      continue
    18.5                  }
    18.6              }
    18.7 -            if (mimeTypes?.isImage(mimeType: att.mimeType) ?? false),
    18.8 +
    18.9 +            let isImage: Bool
   18.10 +            if let mimeType = att.mimeType {
   18.11 +                isImage = mimeTypes?.isImage(mimeType: mimeType) ?? false
   18.12 +            } else {
   18.13 +                isImage = false
   18.14 +            }
   18.15 +            if (isImage),
   18.16                  let imgData = att.data,
   18.17                  let img = UIImage.image(gifData: imgData) ?? UIImage(data: imgData) {
   18.18                  attachmentContainers.append(.imageAttachment(att, img))
    19.1 --- a/pEpForiOS/UI/EmailDisplay/EmailViewController.swift	Thu Mar 14 12:51:48 2019 +0100
    19.2 +++ b/pEpForiOS/UI/EmailDisplay/EmailViewController.swift	Mon Mar 18 18:37:11 2019 +0100
    19.3 @@ -68,7 +68,7 @@
    19.4      // MARK: - UTIL
    19.5  
    19.6      private func updateFlaggedStatus() {
    19.7 -        changeFlagButtonTo(flagged: message?.imapFlags?.flagged ?? false)
    19.8 +        changeFlagButtonTo(flagged: message?.imapFlags.flagged ?? false)
    19.9      }
   19.10  
   19.11      internal func changeFlagButtonTo(flagged: Bool) {
   19.12 @@ -147,7 +147,7 @@
   19.13          DispatchQueue.main.async {
   19.14              self.checkMessageReEvaluation()
   19.15  
   19.16 -            if let message = self.message, !(message.imapFlags?.seen ?? false) {
   19.17 +            if let message = self.message, !message.imapFlags.seen{
   19.18                  message.markAsSeen()
   19.19                  self.delegate?.emailDisplayDidChangeMarkSeen(message: message)
   19.20              }
   19.21 @@ -387,11 +387,11 @@
   19.22              return
   19.23          }
   19.24  
   19.25 -        if (message.imapFlags?.flagged == true) {
   19.26 -            message.imapFlags?.flagged = false
   19.27 +        if (message.imapFlags.flagged == true) {
   19.28 +            message.imapFlags.flagged = false
   19.29              delegate?.emailDisplayDidUnflag(message: message)
   19.30          } else {
   19.31 -            message.imapFlags?.flagged = true
   19.32 +            message.imapFlags.flagged = true
   19.33              delegate?.emailDisplayDidFlag(message: message)
   19.34          }
   19.35          message.save()
    20.1 --- a/pEpForiOS/UI/EmailDisplay/Stuff that is named Compose but is used only in EmailView/ComposeDataSource.swift	Thu Mar 14 12:51:48 2019 +0100
    20.2 +++ b/pEpForiOS/UI/EmailDisplay/Stuff that is named Compose but is used only in EmailView/ComposeDataSource.swift	Mon Mar 18 18:37:11 2019 +0100
    20.3 @@ -78,8 +78,9 @@
    20.4                  return nil
    20.5              }
    20.6              let attachment = attachments[index]
    20.7 +            let mimeType = attachment.mimeType ?? ""
    20.8              return Row(fileName: attachment.fileName,
    20.9 -                       fileExtesion: mimeTypeUtil?.fileExtension(mimeType: attachment.mimeType) ?? "")
   20.10 +                       fileExtesion: mimeTypeUtil?.fileExtension(mimeType: mimeType) ?? "")
   20.11          }
   20.12  
   20.13          /// Adds an attachment to the data source and returns the index it has been inserted in.
    21.1 --- a/pEpForiOS/UI/EmailDisplay/Util/AttachmentsViewHelper.swift	Thu Mar 14 12:51:48 2019 +0100
    21.2 +++ b/pEpForiOS/UI/EmailDisplay/Util/AttachmentsViewHelper.swift	Mon Mar 18 18:37:11 2019 +0100
    21.3 @@ -44,9 +44,14 @@
    21.4      func attachmentInfo(attachment: Attachment) -> AttachmentSummaryView.AttachmentInfo {
    21.5          let (name, ext) =
    21.6              attachment.fileName?.splitFileExtension() ?? (Constants.defaultFileName, nil)
    21.7 +        var finalExt: String? = nil
    21.8 +        if let mimeType = attachment.mimeType{
    21.9 +            finalExt = ext ?? mimeTypes?.fileExtension(mimeType: mimeType)
   21.10 +        }
   21.11 +
   21.12          return AttachmentSummaryView.AttachmentInfo(
   21.13              filename: name.extractFileNameOrCid(),
   21.14 -            theExtension: ext ?? mimeTypes?.fileExtension(mimeType: attachment.mimeType))
   21.15 +            theExtension: finalExt)
   21.16      }
   21.17  
   21.18      func opFinished(theBuildOp: AttachmentsViewOperation) {
    22.1 --- a/pEpForiOS/UI/EmailDisplay/Util/FlagImages.swift	Thu Mar 14 12:51:48 2019 +0100
    22.2 +++ b/pEpForiOS/UI/EmailDisplay/Util/FlagImages.swift	Mon Mar 18 18:37:11 2019 +0100
    22.3 @@ -125,7 +125,7 @@
    22.4  
    22.5  extension FlagImages {
    22.6      public func flagsImage(message: Message) -> UIImage? {
    22.7 -        let flagged = message.imapFlags?.flagged ?? false
    22.8 +        let flagged = message.imapFlags.flagged
    22.9          if flagged {
   22.10              return flaggedImage
   22.11          } else {
    23.1 --- a/pEpForiOS/UI/EmailDisplayList/EmailListViewModel.swift	Thu Mar 14 12:51:48 2019 +0100
    23.2 +++ b/pEpForiOS/UI/EmailDisplayList/EmailListViewModel.swift	Mon Mar 18 18:37:11 2019 +0100
    23.3 @@ -313,7 +313,7 @@
    23.4          DispatchQueue.main.async { [] in
    23.5              previewMessage.isSeen = true
    23.6              let message = previewMessage.message()
    23.7 -            message?.imapFlags?.seen = true
    23.8 +            message?.imapFlags.seen = true
    23.9              message?.save()
   23.10          }
   23.11      }
   23.12 @@ -325,7 +325,7 @@
   23.13          DispatchQueue.main.async { [] in
   23.14              previewMessage.isSeen = false
   23.15              let message = previewMessage.message()
   23.16 -            message?.imapFlags?.seen = false
   23.17 +            message?.imapFlags.seen = false
   23.18              message?.save()
   23.19          }
   23.20      }
   23.21 @@ -374,7 +374,7 @@
   23.22                  return
   23.23          }
   23.24          previewMessage.isFlagged = flagged
   23.25 -        message.imapFlags?.flagged = flagged
   23.26 +        message.imapFlags.flagged = flagged
   23.27          DispatchQueue.main.async {
   23.28              message.save()
   23.29          }
   23.30 @@ -403,7 +403,7 @@
   23.31          if folderIsDraftOrOutbox(parentFolder) {
   23.32              return nil
   23.33          } else {
   23.34 -            let flagged = messages.object(at: index)?.message()?.imapFlags?.flagged ?? false
   23.35 +            let flagged = messages.object(at: index)?.message()?.imapFlags.flagged ?? false
   23.36              return flagged ? .unflag : .flag
   23.37          }
   23.38      }
    24.1 --- a/pEpForiOS/UI/EmailDisplayList/MessageViewModel.swift	Thu Mar 14 12:51:48 2019 +0100
    24.2 +++ b/pEpForiOS/UI/EmailDisplayList/MessageViewModel.swift	Mon Mar 18 18:37:11 2019 +0100
    24.3 @@ -76,8 +76,8 @@
    24.4          from = (message.from ?? Identity(address: "unknown@unknown.com")).userNameOrAddress
    24.5          displayedImageIdentity =  MessageViewModel.identityForImage(from: message)
    24.6          subject = message.shortMessage ?? ""
    24.7 -        isFlagged = message.imapFlags?.flagged ?? false
    24.8 -        isSeen = message.imapFlags?.seen ?? false
    24.9 +        isFlagged = message.imapFlags.flagged
   24.10 +        isSeen = message.imapFlags.seen
   24.11          dateText =  (message.sent ?? Date()).smartString()
   24.12          profilePictureComposer = PepProfilePictureComposer()
   24.13          displayedUsername = MessageViewModel.getDisplayedUsername(for: message)
    25.1 --- a/pEpForiOS/UI/Settings/Setting/AccountSettings/ViewModel/AccountSettingsViewModel.swift	Thu Mar 14 12:51:48 2019 +0100
    25.2 +++ b/pEpForiOS/UI/Settings/Setting/AccountSettings/ViewModel/AccountSettingsViewModel.swift	Mon Mar 18 18:37:11 2019 +0100
    25.3 @@ -74,7 +74,7 @@
    25.4              if let server = account.smtpServer {
    25.5                  return ServerViewModel(address: server.address,
    25.6                                         port: "\(server.port)",
    25.7 -                    transport: server.transport?.asString())
    25.8 +                    transport: server.transport.asString())
    25.9              }
   25.10              return ServerViewModel()
   25.11          }
   25.12 @@ -85,7 +85,7 @@
   25.13              if let server = account.imapServer {
   25.14                  return ServerViewModel(address: server.address,
   25.15                                         port: "\(server.port)",
   25.16 -                    transport: server.transport?.asString())
   25.17 +                    transport: server.transport.asString())
   25.18              }
   25.19              return ServerViewModel()
   25.20          }
   25.21 @@ -160,7 +160,10 @@
   25.22                  Logger.frontendLogger.errorAndCrash("viewModel misses required data.")
   25.23                  return nil
   25.24          }
   25.25 -        let transport = Server.Transport(fromString: viewModel.transport)
   25.26 +        guard let transport = Server.Transport(fromString: viewModel.transport) else {
   25.27 +            Log.shared.errorAndCrash(component: #function, errorString: "No transport")
   25.28 +            return nil
   25.29 +        }
   25.30  
   25.31          let credentials = ServerCredentials.create(loginName: loginName, key: key)
   25.32          if password != nil && password != "" {
    26.1 --- a/pEpForiOS/UI/Thread/ViewModel/ThreadedEmailViewModel.swift	Thu Mar 14 12:51:48 2019 +0100
    26.2 +++ b/pEpForiOS/UI/Thread/ViewModel/ThreadedEmailViewModel.swift	Mon Mar 18 18:37:11 2019 +0100
    26.3 @@ -38,7 +38,7 @@
    26.4          expandedMessages = Array(repeating: false, count: messages.count)
    26.5          
    26.6          for i in 0..<messages.count {
    26.7 -            if !(messages[i].imapFlags?.seen ?? true) || i == messages.count - 1 {
    26.8 +            if !messages[i].imapFlags.seen || i == messages.count - 1 {
    26.9                  markSeen(message: messages[i])
   26.10                  expandedMessages[i] = true
   26.11              }
   26.12 @@ -117,7 +117,7 @@
   26.13              return
   26.14          }
   26.15  
   26.16 -        let flagStatus = (messages[index].imapFlags?.flagged ?? false)
   26.17 +        let flagStatus = (messages[index].imapFlags.flagged ?? false)
   26.18          setFlag(to: !flagStatus, for: messages[index])
   26.19  
   26.20      }
   26.21 @@ -129,7 +129,7 @@
   26.22      }
   26.23  
   26.24      func setFlag(to status: Bool, for message: Message){
   26.25 -        message.imapFlags?.flagged = status
   26.26 +        message.imapFlags.flagged = status
   26.27          message.save()
   26.28          notifyFlag(status, message: message)
   26.29          delegate?.emailViewModeldidChangeFlag(viewModel: self)
   26.30 @@ -137,7 +137,7 @@
   26.31  
   26.32      func allMessagesFlagged() -> Bool {
   26.33          for message in messages {
   26.34 -            if message.imapFlags?.flagged == false {
   26.35 +            if message.imapFlags.flagged == false {
   26.36                  return false
   26.37              }
   26.38          }
   26.39 @@ -195,9 +195,9 @@
   26.40      }
   26.41  
   26.42      private func markSeen(message: Message?) {
   26.43 -        let currentSeen = message?.imapFlags?.seen ?? false
   26.44 +        let currentSeen = message?.imapFlags.seen ?? false
   26.45          if !currentSeen {
   26.46 -            message?.imapFlags?.seen = true
   26.47 +            message?.imapFlags.seen = true
   26.48              MessageModel.performAndWait {
   26.49                  message?.save()
   26.50              }
    27.1 --- a/pEpForiOS/Util/Extensions/Attachment+Extension.swift	Thu Mar 14 12:51:48 2019 +0100
    27.2 +++ b/pEpForiOS/Util/Extensions/Attachment+Extension.swift	Mon Mar 18 18:37:11 2019 +0100
    27.3 @@ -14,8 +14,11 @@
    27.4      /**
    27.5       Can this attachment be shown in the app?
    27.6       */
    27.7 -    public func isViewable() -> Bool {  
    27.8 -        if data == nil || AttachmentFilter.unviewableMimeTypes.contains(mimeType.lowercased()) {
    27.9 +    public func isViewable() -> Bool {
   27.10 +        guard let type = mimeType else {
   27.11 +            return false
   27.12 +        }
   27.13 +        if data == nil || AttachmentFilter.unviewableMimeTypes.contains(type.lowercased()) {
   27.14              return false
   27.15          }
   27.16          return true
    28.1 --- a/pEpForiOS/Util/Extensions/NSAttributedString+pEp.swift	Thu Mar 14 12:51:48 2019 +0100
    28.2 +++ b/pEpForiOS/Util/Extensions/NSAttributedString+pEp.swift	Mon Mar 18 18:37:11 2019 +0100
    28.3 @@ -22,7 +22,15 @@
    28.4              let count = attachments.count
    28.5  
    28.6              let theID = MessageID.generateUUID()
    28.7 -            let theExt = mimeUtil?.fileExtension(mimeType: theAttachment.mimeType) ?? "jpg"
    28.8 +
    28.9 +            let randomDefaultExtension = "jpg"
   28.10 +            let theExt: String
   28.11 +            if let mimeType = theAttachment.mimeType {
   28.12 +                theExt = mimeUtil?.fileExtension(mimeType: mimeType) ?? randomDefaultExtension
   28.13 +            } else {
   28.14 +                theExt = randomDefaultExtension
   28.15 +            }
   28.16 +
   28.17              let cidBase = "attached-inline-image-\(count)-\(theExt)-\(theID)"
   28.18              let cidSrc = "cid:\(cidBase)"
   28.19              let cidUrl = "cid://\(cidBase)"
    29.1 --- a/pEpForiOS/Util/ReplyUtil.swift	Thu Mar 14 12:51:48 2019 +0100
    29.2 +++ b/pEpForiOS/Util/ReplyUtil.swift	Mon Mar 18 18:37:11 2019 +0100
    29.3 @@ -137,7 +137,7 @@
    29.4          dateFormatter.dateStyle = DateFormatter.Style.long
    29.5          dateFormatter.timeStyle = DateFormatter.Style.long
    29.6  
    29.7 -        let theDate = message.received
    29.8 +        let theDate = message.sent
    29.9  
   29.10          var theNames = [String]()
   29.11          if replyAll {