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