IOSAD-91 migrate testEncryptedMailFromMutt
authorDirk Zimmermann <dirk@pep-project.org>
Mon, 16 Apr 2018 11:01:21 +0200
changeset 5791ddf35bfa4f3
parent 578 a05f108cc223
child 580 0a0ba4c4ba91
IOSAD-91 migrate testEncryptedMailFromMutt
pEpObjCTests/PEPSessionTest.m
pEpObjCTests/TestUtils/PEPTestUtils.h
pEpObjCTests/TestUtils/PEPTestUtils.m
     1.1 --- a/pEpObjCTests/PEPSessionTest.m	Mon Apr 16 11:01:20 2018 +0200
     1.2 +++ b/pEpObjCTests/PEPSessionTest.m	Mon Apr 16 11:01:21 2018 +0200
     1.3 @@ -867,6 +867,7 @@
     1.4      NSMutableDictionary *msgDict = [[PEPTestUtils
     1.5                                       unarchiveDictionary:@"msg_to_A3FC7F0A_from_mutt.ser"]
     1.6                                      mutableCopy];
     1.7 +    [PEPTestUtils migrateUnarchivedMessageDictionary:msgDict];
     1.8      [msgDict removeObjectForKey:kPepLongMessage];
     1.9      [msgDict removeObjectForKey:kPepLongMessageFormatted];
    1.10  
     2.1 --- a/pEpObjCTests/TestUtils/PEPTestUtils.h	Mon Apr 16 11:01:20 2018 +0200
     2.2 +++ b/pEpObjCTests/TestUtils/PEPTestUtils.h	Mon Apr 16 11:01:21 2018 +0200
     2.3 @@ -31,6 +31,8 @@
     2.4  
     2.5  + (NSDictionary *)unarchiveDictionary:(NSString *)fileName;
     2.6  
     2.7 ++ (void)migrateUnarchivedMessageDictionary:(NSMutableDictionary *)message;
     2.8 +
     2.9  + (PEPMessage * _Nonnull) mailFrom:(PEPIdentity * _Nullable) fromIdent
    2.10                             toIdent: (PEPIdentity * _Nullable) toIdent
    2.11                        shortMessage:(NSString *)shortMessage
     3.1 --- a/pEpObjCTests/TestUtils/PEPTestUtils.m	Mon Apr 16 11:01:20 2018 +0200
     3.2 +++ b/pEpObjCTests/TestUtils/PEPTestUtils.m	Mon Apr 16 11:01:21 2018 +0200
     3.3 @@ -15,6 +15,7 @@
     3.4  #import "PEPInternalSession.h"
     3.5  #import "PEPMessage.h"
     3.6  #import "PEPSession.h"
     3.7 +#import "PEPAttachment.h"
     3.8  
     3.9  /**
    3.10   For now, safer to use that, until the engine copes with our own.
    3.11 @@ -66,6 +67,24 @@
    3.12      return dict;
    3.13  }
    3.14  
    3.15 +/**
    3.16 + Converts a given message dict to a version with correct attachments, using PEPAttachment.
    3.17 + Using unarchiveDirectory for a message object will yield the old attachment format,
    3.18 + which was just an array of dictionaries. Now the correct way is to use PEPAttachments.
    3.19 + */
    3.20 ++ (void)migrateUnarchivedMessageDictionary:(NSMutableDictionary *)message
    3.21 +{
    3.22 +    NSMutableArray *attachments = [NSMutableArray new];
    3.23 +    for (NSDictionary *attachmentDict in [message objectForKey:kPepAttachments]) {
    3.24 +        PEPAttachment *attachment = [PEPAttachment new];
    3.25 +        attachment.data = [attachmentDict objectForKey:@"data"];
    3.26 +        attachment.filename = [attachmentDict objectForKey:@"filename"];
    3.27 +        attachment.mimeType = [attachmentDict objectForKey:@"mimeType"];
    3.28 +        [attachments addObject:attachment];
    3.29 +    }
    3.30 +    [message setValue:[NSArray arrayWithArray:attachments] forKey:kPepAttachments];
    3.31 +}
    3.32 +
    3.33  + (BOOL)importBundledKey:(NSString *)item session:(PEPSession *)session
    3.34  {
    3.35      if (!session) {