From d68d5dc0ccfee62c4ce3ffb6ce28a8231b10f32a Mon Sep 17 00:00:00 2001
From: jakob <jakob.bode@fu-berlin.de>
Date: Mon, 21 Jan 2019 18:02:24 +0100
Subject: [PATCH] fix older core data bugs

---
 enzevalos_iphone/DataHandler.swift                        | 6 ++++++
 enzevalos_iphone/Folder+CoreDataProperties.swift          | 2 +-
 enzevalos_iphone/KeyRecord+CoreDataProperties.swift       | 2 +-
 enzevalos_iphone/Mail_Address+CoreDataProperties.swift    | 2 +-
 enzevalos_iphone/PersistentKey+CoreDataProperties.swift   | 2 +-
 enzevalos_iphone/PersistentMail +CoreDataProperties.swift | 1 +
 .../enzevalos_iphone 4.xcdatamodel/contents               | 8 ++++----
 7 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/enzevalos_iphone/DataHandler.swift b/enzevalos_iphone/DataHandler.swift
index 6b16d028..cb0142ce 100644
--- a/enzevalos_iphone/DataHandler.swift
+++ b/enzevalos_iphone/DataHandler.swift
@@ -218,6 +218,12 @@ class DataHandler {
         
         for key in keys {
             //let keyID = key.keyID!
+            if let mails = key.decryptedMails as? Set<PersistentMail> {
+                for mail in mails {
+                    mail.decryptedKey = nil
+                }
+            }
+            
             delete(key: key)
             //seems to be unnecassary, because there already exists a corresponding pubilc key, if we generated a keypair
             //_ = DataHandler.handler.newPublicKey(keyID: keyID, cryptoType: .PGP, adr: adr, autocrypt: false, newGenerated: false)
diff --git a/enzevalos_iphone/Folder+CoreDataProperties.swift b/enzevalos_iphone/Folder+CoreDataProperties.swift
index daa80f28..f83885de 100644
--- a/enzevalos_iphone/Folder+CoreDataProperties.swift
+++ b/enzevalos_iphone/Folder+CoreDataProperties.swift
@@ -23,7 +23,7 @@ extension Folder {
     @NSManaged public var path: String //backendFolderPath
     @NSManaged public var lastUpdate: Date?
     @NSManaged public var pseudonym: String
-    @NSManaged public var icon: String
+    @NSManaged public var icon: String?
 
     public var uidvalidity: UInt32? {
         set {
diff --git a/enzevalos_iphone/KeyRecord+CoreDataProperties.swift b/enzevalos_iphone/KeyRecord+CoreDataProperties.swift
index 2cbc65b7..c5db5bae 100644
--- a/enzevalos_iphone/KeyRecord+CoreDataProperties.swift
+++ b/enzevalos_iphone/KeyRecord+CoreDataProperties.swift
@@ -29,7 +29,7 @@ extension KeyRecord {
     }
 
     @NSManaged public var contact: EnzevalosContact
-    @NSManaged public var folder: Folder
+    @NSManaged public var folder: Folder?
     @NSManaged public var key: PersistentKey?
     @NSManaged public var persistentMails: NSSet?
 
diff --git a/enzevalos_iphone/Mail_Address+CoreDataProperties.swift b/enzevalos_iphone/Mail_Address+CoreDataProperties.swift
index 62284dc8..42da725c 100644
--- a/enzevalos_iphone/Mail_Address+CoreDataProperties.swift
+++ b/enzevalos_iphone/Mail_Address+CoreDataProperties.swift
@@ -35,7 +35,7 @@ extension Mail_Address {
     @NSManaged public var from: NSSet?
     @NSManaged public var to: NSSet?
     @NSManaged public var pseudonym: String
-    @NSManaged public var primaryKeyID: String
+    @NSManaged public var primaryKeyID: String?
     @NSManaged public var keys: NSSet?
     @NSManaged public var invitations: Int16
 
diff --git a/enzevalos_iphone/PersistentKey+CoreDataProperties.swift b/enzevalos_iphone/PersistentKey+CoreDataProperties.swift
index 65f0d6b0..db9cc8a3 100644
--- a/enzevalos_iphone/PersistentKey+CoreDataProperties.swift
+++ b/enzevalos_iphone/PersistentKey+CoreDataProperties.swift
@@ -82,7 +82,7 @@ extension PersistentKey {
 
 // MARK: Generated accessors for mailaddress
 extension PersistentKey {
-    @objc(addsignedMailsObject:)
+    @objc(addSignedMailsObject:)
     @NSManaged public func addSignedMails(_ value: PersistentMail)
     
     @objc(removeSignedMailsObject:)
diff --git a/enzevalos_iphone/PersistentMail +CoreDataProperties.swift b/enzevalos_iphone/PersistentMail +CoreDataProperties.swift
index 1b45811f..6c6b274a 100644
--- a/enzevalos_iphone/PersistentMail +CoreDataProperties.swift	
+++ b/enzevalos_iphone/PersistentMail +CoreDataProperties.swift	
@@ -84,6 +84,7 @@ extension PersistentMail {
     @NSManaged public var gmailThreadID: NSNumber?
     @NSManaged public var messageID: String?
     @NSManaged public var notLoadedMessages: String?
+    @NSManaged public var decryptedKey: PersistentKey?
 
     @NSManaged public var xMailer: String?
 
diff --git a/enzevalos_iphone/enzevalos_iphone.xcdatamodeld/enzevalos_iphone 4.xcdatamodel/contents b/enzevalos_iphone/enzevalos_iphone.xcdatamodeld/enzevalos_iphone 4.xcdatamodel/contents
index 9c24be69..9d8e3e73 100644
--- a/enzevalos_iphone/enzevalos_iphone.xcdatamodeld/enzevalos_iphone 4.xcdatamodel/contents	
+++ b/enzevalos_iphone/enzevalos_iphone.xcdatamodeld/enzevalos_iphone 4.xcdatamodel/contents	
@@ -20,7 +20,7 @@
         <attribute name="contentID" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES" syncable="YES"/>
         <attribute name="data" attributeType="Binary" syncable="YES"/>
         <attribute name="encryptionState" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES" syncable="YES"/>
-        <attribute name="isExplicitAttachment" attributeType="Boolean" usesScalarValueType="YES" syncable="YES"/>
+        <attribute name="isExplicitAttachment" optional="YES" attributeType="Boolean" usesScalarValueType="YES" syncable="YES"/>
         <attribute name="mcoPartType" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES" syncable="YES"/>
         <attribute name="mimeType" attributeType="String" syncable="YES"/>
         <attribute name="name" attributeType="String" syncable="YES"/>
@@ -87,7 +87,7 @@
         <relationship name="signedMails" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="PersistentMail" inverseName="signedKey" inverseEntity="PersistentMail" syncable="YES"/>
     </entity>
     <entity name="PersistentMail" representedClassName="PersistentMail" syncable="YES">
-        <attribute name="body" attributeType="String" syncable="YES"/>
+        <attribute name="body" optional="YES" attributeType="String" syncable="YES"/>
         <attribute name="date" attributeType="Date" defaultDateTimeInterval="-31582140" usesScalarValueType="NO" syncable="YES"/>
         <attribute name="decryptedBody" optional="YES" attributeType="String" syncable="YES"/>
         <attribute name="decrytionCode" optional="YES" attributeType="String" syncable="YES"/>
@@ -120,7 +120,7 @@
         <relationship name="decryptedKey" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="SecretKey" inverseName="decryptedMails" inverseEntity="SecretKey" syncable="YES"/>
         <relationship name="folder" maxCount="1" deletionRule="Nullify" destinationEntity="Folder" inverseName="mails" inverseEntity="Folder" syncable="YES"/>
         <relationship name="from" maxCount="1" deletionRule="Nullify" destinationEntity="Mail_Address" inverseName="from" inverseEntity="Mail_Address" syncable="YES"/>
-        <relationship name="record" maxCount="1" deletionRule="Nullify" destinationEntity="KeyRecord" inverseName="persistentMails" inverseEntity="KeyRecord" syncable="YES"/>
+        <relationship name="record" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="KeyRecord" inverseName="persistentMails" inverseEntity="KeyRecord" syncable="YES"/>
         <relationship name="referenceMails" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="PersistentMail" inverseName="referenceMails" inverseEntity="PersistentMail" syncable="YES"/>
         <relationship name="signedKey" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="PersistentKey" inverseName="signedMails" inverseEntity="PersistentKey" syncable="YES"/>
         <relationship name="to" toMany="YES" deletionRule="Nullify" destinationEntity="Mail_Address" inverseName="to" inverseEntity="Mail_Address" syncable="YES"/>
@@ -130,7 +130,7 @@
     </entity>
     <entity name="SecretKey" representedClassName="SecretKey" syncable="YES" codeGenerationType="class">
         <attribute name="exported" optional="YES" attributeType="Boolean" usesScalarValueType="YES" syncable="YES"/>
-        <attribute name="importedDate" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
+        <attribute name="importedDate" optional="YES" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
         <attribute name="keyID" optional="YES" attributeType="String" syncable="YES"/>
         <attribute name="obsolete" optional="YES" attributeType="Boolean" usesScalarValueType="YES" syncable="YES"/>
         <relationship name="account" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Account" inverseName="keys" inverseEntity="Account" syncable="YES"/>
-- 
GitLab