pEpObjCAdapter/NSMutableDictionary+PEP.m
author Dirk Zimmermann <dirk@pep-project.org>
Thu, 17 May 2018 09:33:33 +0200
changeset 616 9e50cc7cd612
parent 598 893ee5ebcd43
child 851 e62e76f93075
permissions -rw-r--r--
IOSAD-93 consistently using precomposedStringWithCanonicalMapping, stringWithUTF8String
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
dirk@597
    11
#import "PEPMessageUtil.h"
dirk@597
    12
dirk@598
    13
void replaceDictionaryContentsWithMessage(NSMutableDictionary *dict, message *message)
dirk@598
    14
{
dirk@598
    15
    [dict removeAllObjects];
dirk@598
    16
    
dirk@598
    17
    [dict setValue:(message->dir == PEP_dir_outgoing) ? @YES : @NO forKey:kPepOutgoing];
dirk@598
    18
    
dirk@598
    19
    if (message->id) {
dirk@598
    20
        [dict setValue:[NSString stringWithUTF8String:message->id] forKey:kPepID];
dirk@598
    21
    }
dirk@598
    22
    
dirk@598
    23
    if (message->shortmsg) {
dirk@598
    24
        [dict setValue:[NSString stringWithUTF8String:message->shortmsg] forKey:kPepShortMessage];
dirk@598
    25
    }
dirk@598
    26
    
dirk@598
    27
    if (message->sent) {
dirk@598
    28
        [dict setValue:[NSDate dateWithTimeIntervalSince1970:timegm(message->sent)]
dirk@598
    29
                forKey:kPepSent];
dirk@598
    30
    }
dirk@598
    31
    
dirk@598
    32
    if (message->recv) {
dirk@598
    33
        [dict setValue:[NSDate dateWithTimeIntervalSince1970:mktime(message->recv)]
dirk@598
    34
                forKey:kPepReceived];
dirk@598
    35
    }
dirk@598
    36
    
dirk@598
    37
    if (message->from) {
dirk@598
    38
        [dict setValue:PEP_identityFromStruct(message->from) forKey:kPepFrom];
dirk@598
    39
    }
dirk@598
    40
    
dirk@598
    41
    if (message->to && message->to->ident) {
dirk@598
    42
        [dict setValue:PEP_identityArrayFromList(message->to) forKey:kPepTo];
dirk@598
    43
    }
dirk@598
    44
    
dirk@598
    45
    if (message->recv_by) {
dirk@598
    46
        [dict setValue:PEP_identityFromStruct(message->recv_by) forKey:kPepReceivedBy];
dirk@598
    47
    }
dirk@598
    48
    
dirk@598
    49
    if (message->cc && message->cc->ident) {
dirk@598
    50
        [dict setValue:PEP_identityArrayFromList(message->cc) forKey:kPepCC];
dirk@598
    51
    }
dirk@598
    52
    
dirk@598
    53
    if (message->bcc && message->bcc->ident) {
dirk@598
    54
        [dict setValue:PEP_identityArrayFromList(message->bcc) forKey:kPepBCC];
dirk@598
    55
    }
dirk@598
    56
    
dirk@598
    57
    if (message->reply_to && message->reply_to->ident) {
dirk@598
    58
        [dict setValue:PEP_identityArrayFromList(message->reply_to) forKey:kPepReplyTo];
dirk@598
    59
    }
dirk@598
    60
    
dirk@598
    61
    if (message->in_reply_to) {
dirk@598
    62
        [dict setValue:PEP_arrayFromStringlist(message->in_reply_to) forKey:kPepInReplyTo];
dirk@598
    63
    }
dirk@598
    64
    
dirk@598
    65
    if (message->references && message->references->value) {
dirk@598
    66
        [dict setValue:PEP_arrayFromStringlist(message->references) forKey:kPepReferences];
dirk@598
    67
    }
dirk@598
    68
    
dirk@598
    69
    if (message->keywords && message->keywords->value) {
dirk@598
    70
        [dict setValue:PEP_arrayFromStringlist(message->keywords) forKey:kPepKeywords];
dirk@598
    71
    }
dirk@598
    72
    
dirk@598
    73
    if (message->opt_fields) {
dirk@598
    74
        [dict setValue:PEP_arrayFromStringPairlist(message->opt_fields) forKey:kPepOptFields];
dirk@598
    75
    }
dirk@598
    76
    
dirk@598
    77
    if (message->longmsg_formatted) {
dirk@598
    78
        [dict setValue:[NSString stringWithUTF8String:message->longmsg_formatted]
dirk@598
    79
                forKey:kPepLongMessageFormatted];
dirk@598
    80
    }
dirk@598
    81
    
dirk@598
    82
    if (message->longmsg) {
dirk@598
    83
        [dict setValue:[NSString stringWithUTF8String:message->longmsg] forKey:kPepLongMessage];
dirk@598
    84
    }
dirk@598
    85
    
dirk@598
    86
    if (message->attachments && message->attachments->value) {
dirk@598
    87
        [dict setValue: PEP_arrayFromBloblist(message->attachments) forKey:kPepAttachments];
dirk@598
    88
    }
dirk@598
    89
    
dirk@598
    90
    if (message->rawmsg_size > 0 && *message->rawmsg_ref) {
dirk@598
    91
        NSData *data = [NSData dataWithBytes:message->rawmsg_ref length:message->rawmsg_size];
dirk@598
    92
        dict[kPepRawMessage] = data;
dirk@598
    93
    }
dirk@598
    94
}
dirk@598
    95
dirk@597
    96
@implementation NSMutableDictionary (PEP)
dirk@597
    97
dirk@597
    98
- (void)replaceWithMessage:(message *)message
dirk@597
    99
{
dirk@598
   100
    replaceDictionaryContentsWithMessage(self, message);
dirk@597
   101
}
dirk@597
   102
dirk@597
   103
@end