IOSAD-92 [NSMutableDictionary replaceWithMessage] IOSAD-92
authorDirk Zimmermann <dirk@pep-project.org>
Tue, 24 Apr 2018 17:11:58 +0200
branchIOSAD-92
changeset 597aa68b6d6a966
parent 596 2a2f52bb7e41
child 598 893ee5ebcd43
IOSAD-92 [NSMutableDictionary replaceWithMessage]
pEpObjCAdapter.xcodeproj/project.pbxproj
pEpObjCAdapter/NSMutableDictionary+PEP.h
pEpObjCAdapter/NSMutableDictionary+PEP.m
pEpObjCAdapter/PEPMessageUtil.h
pEpObjCAdapter/PEPMessageUtil.m
     1.1 --- a/pEpObjCAdapter.xcodeproj/project.pbxproj	Tue Apr 24 17:11:57 2018 +0200
     1.2 +++ b/pEpObjCAdapter.xcodeproj/project.pbxproj	Tue Apr 24 17:11:58 2018 +0200
     1.3 @@ -36,6 +36,7 @@
     1.4  		435796E31FB5E51A00395A9E /* PEPMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = 435796E21FB5E51A00395A9E /* PEPMessage.m */; };
     1.5  		43676B661C57EA1A00233933 /* B623F674_sec.asc in Resources */ = {isa = PBXBuildFile; fileRef = 43676B641C57EA1A00233933 /* B623F674_sec.asc */; };
     1.6  		439393E6208F375800EB1DBD /* NSObject+Extension.m in Sources */ = {isa = PBXBuildFile; fileRef = 439393E5208F375800EB1DBD /* NSObject+Extension.m */; };
     1.7 +		439393F8208F5B5E00EB1DBD /* NSMutableDictionary+PEP.m in Sources */ = {isa = PBXBuildFile; fileRef = 439393F7208F5B5E00EB1DBD /* NSMutableDictionary+PEP.m */; };
     1.8  		439D91A5208479EE003F6AC2 /* PEPAttachment.m in Sources */ = {isa = PBXBuildFile; fileRef = 439D91A4208479EE003F6AC2 /* PEPAttachment.m */; };
     1.9  		43D27DE61F5DA7B700795687 /* NSDictionary+Extension.m in Sources */ = {isa = PBXBuildFile; fileRef = 43D27DE51F5DA7B700795687 /* NSDictionary+Extension.m */; };
    1.10  		43DED786203C25E200D45CD6 /* NSError+PEP.m in Sources */ = {isa = PBXBuildFile; fileRef = 43DED785203C25E200D45CD6 /* NSError+PEP.m */; };
    1.11 @@ -170,6 +171,8 @@
    1.12  		43676B641C57EA1A00233933 /* B623F674_sec.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = B623F674_sec.asc; sourceTree = "<group>"; };
    1.13  		439393E4208F375800EB1DBD /* NSObject+Extension.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSObject+Extension.h"; sourceTree = "<group>"; };
    1.14  		439393E5208F375800EB1DBD /* NSObject+Extension.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSObject+Extension.m"; sourceTree = "<group>"; };
    1.15 +		439393F6208F5B5E00EB1DBD /* NSMutableDictionary+PEP.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSMutableDictionary+PEP.h"; sourceTree = "<group>"; };
    1.16 +		439393F7208F5B5E00EB1DBD /* NSMutableDictionary+PEP.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSMutableDictionary+PEP.m"; sourceTree = "<group>"; };
    1.17  		439D91A3208479EE003F6AC2 /* PEPAttachment.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PEPAttachment.h; sourceTree = "<group>"; };
    1.18  		439D91A4208479EE003F6AC2 /* PEPAttachment.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PEPAttachment.m; sourceTree = "<group>"; };
    1.19  		43D27DE41F5DA78700795687 /* NSDictionary+Extension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+Extension.h"; sourceTree = "<group>"; };
    1.20 @@ -320,6 +323,8 @@
    1.21  				435665CB2080A6CB00EC5B10 /* NSNumber+PEPRating.m */,
    1.22  				439393E4208F375800EB1DBD /* NSObject+Extension.h */,
    1.23  				439393E5208F375800EB1DBD /* NSObject+Extension.m */,
    1.24 +				439393F6208F5B5E00EB1DBD /* NSMutableDictionary+PEP.h */,
    1.25 +				439393F7208F5B5E00EB1DBD /* NSMutableDictionary+PEP.m */,
    1.26  			);
    1.27  			path = pEpObjCAdapter;
    1.28  			sourceTree = "<group>";
    1.29 @@ -500,6 +505,7 @@
    1.30  				43209B3E1ECC2DAB007E7E2E /* PEPCSVScanner.m in Sources */,
    1.31  				43209B421ECC2DBC007E7E2E /* PEPQueue.m in Sources */,
    1.32  				435665CC2080A6CB00EC5B10 /* NSNumber+PEPRating.m in Sources */,
    1.33 +				439393F8208F5B5E00EB1DBD /* NSMutableDictionary+PEP.m in Sources */,
    1.34  				15206CC71F8E078B003FF880 /* PEPSession.m in Sources */,
    1.35  			);
    1.36  			runOnlyForDeploymentPostprocessing = 0;
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/pEpObjCAdapter/NSMutableDictionary+PEP.h	Tue Apr 24 17:11:58 2018 +0200
     2.3 @@ -0,0 +1,20 @@
     2.4 +//
     2.5 +//  NSMutableDictionary+PEP.h
     2.6 +//  pEpObjCAdapter
     2.7 +//
     2.8 +//  Created by Dirk Zimmermann on 24.04.18.
     2.9 +//  Copyright © 2018 p≡p. All rights reserved.
    2.10 +//
    2.11 +
    2.12 +#import <Foundation/Foundation.h>
    2.13 +
    2.14 +#import "message.h"
    2.15 +
    2.16 +@interface NSMutableDictionary (PEP)
    2.17 +
    2.18 +/**
    2.19 + Replaces all content with `message`.
    2.20 + */
    2.21 +- (void)replaceWithMessage:(message *)message;
    2.22 +
    2.23 +@end
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/pEpObjCAdapter/NSMutableDictionary+PEP.m	Tue Apr 24 17:11:58 2018 +0200
     3.3 @@ -0,0 +1,98 @@
     3.4 +//
     3.5 +//  NSMutableDictionary+PEP.m
     3.6 +//  pEpObjCAdapter
     3.7 +//
     3.8 +//  Created by Dirk Zimmermann on 24.04.18.
     3.9 +//  Copyright © 2018 p≡p. All rights reserved.
    3.10 +//
    3.11 +
    3.12 +#import "NSMutableDictionary+PEP.h"
    3.13 +
    3.14 +#import "PEPMessageUtil.h"
    3.15 +
    3.16 +@implementation NSMutableDictionary (PEP)
    3.17 +
    3.18 +- (void)replaceWithMessage:(message *)message
    3.19 +{
    3.20 +    [self removeAllObjects];
    3.21 +
    3.22 +    [self setObject:(message->dir == PEP_dir_outgoing) ? @YES : @NO forKey:kPepOutgoing];
    3.23 +
    3.24 +    if (message->id) {
    3.25 +        [self setObject:[NSString stringWithUTF8String:message->id] forKey:kPepID];
    3.26 +    }
    3.27 +
    3.28 +    if (message->shortmsg) {
    3.29 +        [self setObject:[NSString stringWithUTF8String:message->shortmsg] forKey:kPepShortMessage];
    3.30 +    }
    3.31 +
    3.32 +    if (message->sent) {
    3.33 +        [self setObject:[NSDate dateWithTimeIntervalSince1970:timegm(message->sent)]
    3.34 +                 forKey:kPepSent];
    3.35 +    }
    3.36 +
    3.37 +    if (message->recv) {
    3.38 +        [self setObject:[NSDate dateWithTimeIntervalSince1970:mktime(message->recv)]
    3.39 +                 forKey:kPepReceived];
    3.40 +    }
    3.41 +
    3.42 +    if (message->from) {
    3.43 +        [self setObject:PEP_identityFromStruct(message->from) forKey:kPepFrom];
    3.44 +    }
    3.45 +
    3.46 +    if (message->to && message->to->ident) {
    3.47 +        [self setObject:PEP_identityArrayFromList(message->to) forKey:kPepTo];
    3.48 +    }
    3.49 +
    3.50 +    if (message->recv_by) {
    3.51 +        [self setObject:PEP_identityFromStruct(message->recv_by) forKey:kPepReceivedBy];
    3.52 +    }
    3.53 +
    3.54 +    if (message->cc && message->cc->ident) {
    3.55 +        [self setObject:PEP_identityArrayFromList(message->cc) forKey:kPepCC];
    3.56 +    }
    3.57 +
    3.58 +    if (message->bcc && message->bcc->ident) {
    3.59 +        [self setObject:PEP_identityArrayFromList(message->bcc) forKey:kPepBCC];
    3.60 +    }
    3.61 +
    3.62 +    if (message->reply_to && message->reply_to->ident) {
    3.63 +        [self setObject:PEP_identityArrayFromList(message->reply_to) forKey:kPepReplyTo];
    3.64 +    }
    3.65 +
    3.66 +    if (message->in_reply_to) {
    3.67 +        [self setObject:PEP_arrayFromStringlist(message->in_reply_to) forKey:kPepInReplyTo];
    3.68 +    }
    3.69 +
    3.70 +    if (message->references && message->references->value) {
    3.71 +        [self setObject:PEP_arrayFromStringlist(message->references) forKey:kPepReferences];
    3.72 +    }
    3.73 +
    3.74 +    if (message->keywords && message->keywords->value) {
    3.75 +        [self setObject:PEP_arrayFromStringlist(message->keywords) forKey:kPepKeywords];
    3.76 +    }
    3.77 +
    3.78 +    if (message->opt_fields) {
    3.79 +        [self setObject:PEP_arrayFromStringPairlist(message->opt_fields) forKey:kPepOptFields];
    3.80 +    }
    3.81 +
    3.82 +    if (message->longmsg_formatted) {
    3.83 +        [self setObject:[NSString stringWithUTF8String:message->longmsg_formatted]
    3.84 +                 forKey:kPepLongMessageFormatted];
    3.85 +    }
    3.86 +
    3.87 +    if (message->longmsg) {
    3.88 +        [self setObject:[NSString stringWithUTF8String:message->longmsg] forKey:kPepLongMessage];
    3.89 +    }
    3.90 +
    3.91 +    if (message->attachments && message->attachments->value) {
    3.92 +        [self setObject: PEP_arrayFromBloblist(message->attachments) forKey:kPepAttachments];
    3.93 +    }
    3.94 +
    3.95 +    if (message->rawmsg_size > 0 && *message->rawmsg_ref) {
    3.96 +        NSData *data = [NSData dataWithBytes:message->rawmsg_ref length:message->rawmsg_size];
    3.97 +        self[kPepRawMessage] = data;
    3.98 +    }
    3.99 +}
   3.100 +
   3.101 +@end
     4.1 --- a/pEpObjCAdapter/PEPMessageUtil.h	Tue Apr 24 17:11:57 2018 +0200
     4.2 +++ b/pEpObjCAdapter/PEPMessageUtil.h	Tue Apr 24 17:11:58 2018 +0200
     4.3 @@ -31,6 +31,10 @@
     4.4  message * _Nullable PEP_messageDictToStruct(NSDictionary * _Nullable dict);
     4.5  NSDictionary * _Nonnull PEP_messageDictFromStruct(message * _Nullable msg);
     4.6  
     4.7 +NSArray *PEP_identityArrayFromList(identity_list *il);
     4.8 +NSArray *PEP_arrayFromStringPairlist(stringpair_list_t *sl);
     4.9 +NSArray *PEP_arrayFromBloblist(bloblist_t *bl);
    4.10 +
    4.11  #pragma mark -- Constants
    4.12  
    4.13  /** The name of the user */
     5.1 --- a/pEpObjCAdapter/PEPMessageUtil.m	Tue Apr 24 17:11:57 2018 +0200
     5.2 +++ b/pEpObjCAdapter/PEPMessageUtil.m	Tue Apr 24 17:11:58 2018 +0200
     5.3 @@ -11,6 +11,7 @@
     5.4  #import "PEPIdentity.h"
     5.5  #import "PEPMessage.h"
     5.6  #import "PEPAttachment.h"
     5.7 +#import "NSMutableDictionary+PEP.h"
     5.8  
     5.9  #import "pEp_string.h"
    5.10  
    5.11 @@ -343,64 +344,7 @@
    5.12  {
    5.13      NSMutableDictionary *dict = [NSMutableDictionary new];
    5.14      if (msg && dict) {
    5.15 -        [dict setObject:(msg->dir==PEP_dir_outgoing)?@YES:@NO forKey:@"outgoing"];
    5.16 -
    5.17 -        if (msg->id)
    5.18 -            [dict setObject:[NSString stringWithUTF8String:msg->id] forKey:@"id"];
    5.19 -        
    5.20 -        if (msg->shortmsg)
    5.21 -            [dict setObject:[NSString stringWithUTF8String:msg->shortmsg] forKey:@"shortmsg"];
    5.22 -
    5.23 -        if (msg->sent)
    5.24 -            [dict setObject:[NSDate dateWithTimeIntervalSince1970:timegm(msg->sent)] forKey:@"sent"];
    5.25 -        
    5.26 -        if (msg->recv)
    5.27 -            [dict setObject:[NSDate dateWithTimeIntervalSince1970:mktime(msg->recv)] forKey:@"recv"];
    5.28 -        
    5.29 -        if (msg->from)
    5.30 -            [dict setObject:PEP_identityFromStruct(msg->from) forKey:kPepFrom];
    5.31 -        
    5.32 -        if (msg->to && msg->to->ident)
    5.33 -            [dict setObject:PEP_identityArrayFromList(msg->to) forKey:@"to"];
    5.34 -        
    5.35 -        if (msg->recv_by)
    5.36 -            [dict setObject:PEP_identityFromStruct(msg->recv_by) forKey:@"recv_by"];
    5.37 -        
    5.38 -        if (msg->cc && msg->cc->ident)
    5.39 -            [dict setObject:PEP_identityArrayFromList(msg->cc) forKey:@"cc"];
    5.40 -        
    5.41 -        if (msg->bcc && msg->bcc->ident)
    5.42 -            [dict setObject:PEP_identityArrayFromList(msg->bcc) forKey:@"bcc"];
    5.43 -        
    5.44 -        if (msg->reply_to && msg->reply_to->ident)
    5.45 -            [dict setObject:PEP_identityArrayFromList(msg->reply_to) forKey:@"reply_to"];
    5.46 -        
    5.47 -        if (msg->in_reply_to)
    5.48 -            [dict setObject:PEP_arrayFromStringlist(msg->in_reply_to) forKey:@"in_reply_to"];
    5.49 -
    5.50 -        if (msg->references && msg->references->value)
    5.51 -            [dict setObject:PEP_arrayFromStringlist(msg->references) forKey:kPepReferences];
    5.52 -
    5.53 -        if (msg->keywords && msg->keywords->value)
    5.54 -            [dict setObject:PEP_arrayFromStringlist(msg->keywords) forKey:@"keywords"];
    5.55 -
    5.56 -        if (msg->opt_fields)
    5.57 -            [dict setObject:PEP_arrayFromStringPairlist(msg->opt_fields) forKey:@"opt_fields"];
    5.58 -        
    5.59 -        if (msg->longmsg_formatted)
    5.60 -            [dict setObject:[NSString stringWithUTF8String:msg->longmsg_formatted]
    5.61 -                     forKey:@"longmsg_formatted"];
    5.62 -
    5.63 -        if (msg->longmsg)
    5.64 -            [dict setObject:[NSString stringWithUTF8String:msg->longmsg] forKey:@"longmsg"];
    5.65 -        
    5.66 -        if (msg->attachments && msg->attachments->value)
    5.67 -            [dict setObject: PEP_arrayFromBloblist(msg->attachments) forKey:@"attachments"];
    5.68 -
    5.69 -        if (msg->rawmsg_size > 0 && *msg->rawmsg_ref) {
    5.70 -            NSData *data = [NSData dataWithBytes:msg->rawmsg_ref length:msg->rawmsg_size];
    5.71 -            dict[kPepRawMessage] = data;
    5.72 -        }
    5.73 +        [dict replaceWithMessage:msg];
    5.74      }
    5.75      return dict;
    5.76  }