pEpObjCAdapter/NSMutableDictionary+PEP.m
author Dirk Zimmermann <dz@pep.security>
Wed, 20 Mar 2019 16:40:35 +0100
branchIOS-1480
changeset 902 32760267cd59
parent 851 e62e76f93075
child 1096 94a663ebfb1a
permissions -rw-r--r--
IOS-1480 Avoid framework imports.
     1 //
     2 //  NSMutableDictionary+PEP.m
     3 //  pEpObjCAdapter
     4 //
     5 //  Created by Dirk Zimmermann on 24.04.18.
     6 //  Copyright © 2018 p≡p. All rights reserved.
     7 //
     8 
     9 #import "NSMutableDictionary+PEP.h"
    10 
    11 #import "PEPConstants.h"
    12 
    13 #import "PEPMessageUtil.h"
    14 
    15 void replaceDictionaryContentsWithMessage(NSMutableDictionary *dict, message *message)
    16 {
    17     [dict removeAllObjects];
    18     
    19     [dict setValue:(message->dir == PEP_dir_outgoing) ? @YES : @NO forKey:kPepOutgoing];
    20     
    21     if (message->id) {
    22         [dict setValue:[NSString stringWithUTF8String:message->id] forKey:kPepID];
    23     }
    24     
    25     if (message->shortmsg) {
    26         [dict setValue:[NSString stringWithUTF8String:message->shortmsg] forKey:kPepShortMessage];
    27     }
    28     
    29     if (message->sent) {
    30         [dict setValue:[NSDate dateWithTimeIntervalSince1970:timegm(message->sent)]
    31                 forKey:kPepSent];
    32     }
    33     
    34     if (message->recv) {
    35         [dict setValue:[NSDate dateWithTimeIntervalSince1970:mktime(message->recv)]
    36                 forKey:kPepReceived];
    37     }
    38     
    39     if (message->from) {
    40         [dict setValue:PEP_identityFromStruct(message->from) forKey:kPepFrom];
    41     }
    42     
    43     if (message->to && message->to->ident) {
    44         [dict setValue:PEP_identityArrayFromList(message->to) forKey:kPepTo];
    45     }
    46     
    47     if (message->recv_by) {
    48         [dict setValue:PEP_identityFromStruct(message->recv_by) forKey:kPepReceivedBy];
    49     }
    50     
    51     if (message->cc && message->cc->ident) {
    52         [dict setValue:PEP_identityArrayFromList(message->cc) forKey:kPepCC];
    53     }
    54     
    55     if (message->bcc && message->bcc->ident) {
    56         [dict setValue:PEP_identityArrayFromList(message->bcc) forKey:kPepBCC];
    57     }
    58     
    59     if (message->reply_to && message->reply_to->ident) {
    60         [dict setValue:PEP_identityArrayFromList(message->reply_to) forKey:kPepReplyTo];
    61     }
    62     
    63     if (message->in_reply_to) {
    64         [dict setValue:PEP_arrayFromStringlist(message->in_reply_to) forKey:kPepInReplyTo];
    65     }
    66     
    67     if (message->references && message->references->value) {
    68         [dict setValue:PEP_arrayFromStringlist(message->references) forKey:kPepReferences];
    69     }
    70     
    71     if (message->keywords && message->keywords->value) {
    72         [dict setValue:PEP_arrayFromStringlist(message->keywords) forKey:kPepKeywords];
    73     }
    74     
    75     if (message->opt_fields) {
    76         [dict setValue:PEP_arrayFromStringPairlist(message->opt_fields) forKey:kPepOptFields];
    77     }
    78     
    79     if (message->longmsg_formatted) {
    80         [dict setValue:[NSString stringWithUTF8String:message->longmsg_formatted]
    81                 forKey:kPepLongMessageFormatted];
    82     }
    83     
    84     if (message->longmsg) {
    85         [dict setValue:[NSString stringWithUTF8String:message->longmsg] forKey:kPepLongMessage];
    86     }
    87     
    88     if (message->attachments && message->attachments->value) {
    89         [dict setValue: PEP_arrayFromBloblist(message->attachments) forKey:kPepAttachments];
    90     }
    91     
    92     if (message->rawmsg_size > 0 && *message->rawmsg_ref) {
    93         NSData *data = [NSData dataWithBytes:message->rawmsg_ref length:message->rawmsg_size];
    94         dict[kPepRawMessage] = data;
    95     }
    96 }
    97 
    98 @implementation NSMutableDictionary (PEP)
    99 
   100 - (void)replaceWithMessage:(message *)message
   101 {
   102     replaceDictionaryContentsWithMessage(self, message);
   103 }
   104 
   105 @end