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