merge
authorKrista Bennett <krista@pep-project.org>
Fri, 09 Mar 2018 07:29:23 +0100
changeset 2560890946ee67ae
parent 2554 d7bbec46bd84
parent 2557 a83a5643b065
child 2561 46fccf362b21
merge
     1.1 --- a/src/message_api.c	Wed Mar 07 10:40:18 2018 +0100
     1.2 +++ b/src/message_api.c	Fri Mar 09 07:29:23 2018 +0100
     1.3 @@ -2559,6 +2559,79 @@
     1.4      return status;
     1.5  }
     1.6  
     1.7 +static PEP_STATUS reconcile_identity(pEp_identity* srcid,
     1.8 +                                     pEp_identity* resultid) {
     1.9 +    assert(srcid);
    1.10 +    assert(resultid);
    1.11 +
    1.12 +    if (!srcid || !resultid)
    1.13 +        return PEP_ILLEGAL_VALUE;
    1.14 +        
    1.15 +    if (!EMPTYSTR(srcid->user_id)) {
    1.16 +        if (EMPTYSTR(resultid->user_id) ||
    1.17 +             strcmp(srcid->user_id, resultid->user_id) != 0) {
    1.18 +            free(resultid->user_id);
    1.19 +            resultid->user_id = strdup(srcid->user_id);
    1.20 +        }
    1.21 +    }
    1.22 +    
    1.23 +    resultid->lang[0] = srcid->lang[0];
    1.24 +    resultid->me = srcid->me;
    1.25 +    resultid->flags = srcid->flags;
    1.26 +
    1.27 +    return PEP_STATUS_OK;
    1.28 +}
    1.29 +
    1.30 +static PEP_STATUS reconcile_identity_lists(identity_list* src_ids,
    1.31 +                                           identity_list* result_ids) {
    1.32 +                                           
    1.33 +    identity_list* curr_id = result_ids;
    1.34 +    
    1.35 +    PEP_STATUS status = PEP_STATUS_OK;
    1.36 +    
    1.37 +    while (curr_id) {
    1.38 +        identity_list* curr_src_id = src_ids;
    1.39 +        pEp_identity* result_identity = curr_id->ident;
    1.40 +        
    1.41 +        while (curr_src_id) {
    1.42 +            pEp_identity* source_identity = curr_src_id->ident;
    1.43 +            
    1.44 +            if (EMPTYSTR(source_identity->address) || EMPTYSTR(result_identity->address))
    1.45 +                return PEP_ILLEGAL_VALUE; // something went badly wrong
    1.46 +            
    1.47 +            if (strcasecmp(source_identity->address, result_identity->address) == 0) {
    1.48 +                status = reconcile_identity(source_identity, result_identity);
    1.49 +                if (status != PEP_STATUS_OK)
    1.50 +                    return status;
    1.51 +            }
    1.52 +            curr_src_id = curr_src_id->next;        
    1.53 +        }
    1.54 +        curr_id = curr_id->next;
    1.55 +    }
    1.56 +    return status;    
    1.57 +}
    1.58 +
    1.59 +static PEP_STATUS reconcile_src_and_inner_messages(message* src, 
    1.60 +                                             message* inner_message) {
    1.61 +
    1.62 +    PEP_STATUS status = PEP_STATUS_OK;
    1.63 +    
    1.64 +    if (strcasecmp(src->from->address, inner_message->from->address) == 0)
    1.65 +        status = reconcile_identity(src->from, inner_message->from);
    1.66 +    
    1.67 +    if (status == PEP_STATUS_OK && inner_message->to)
    1.68 +        status = reconcile_identity_lists(src->to, inner_message->to);
    1.69 +
    1.70 +    if (status == PEP_STATUS_OK && inner_message->cc)
    1.71 +        status = reconcile_identity_lists(src->cc, inner_message->cc);
    1.72 +
    1.73 +    if (status == PEP_STATUS_OK && inner_message->bcc)
    1.74 +        status = reconcile_identity_lists(src->bcc, inner_message->bcc);
    1.75 +
    1.76 +    return status;
    1.77 +    // FIXME - are there any flags or anything else we need to be sure are carried?
    1.78 +}
    1.79 +
    1.80  
    1.81  DYNAMIC_API PEP_STATUS _decrypt_message(
    1.82          PEP_SESSION session,
    1.83 @@ -2797,8 +2870,13 @@
    1.84                                                  free_message(inner_message);
    1.85                                                  goto pep_error;
    1.86                                              }
    1.87 -                                                
    1.88 +                                                    
    1.89                                              // THIS is our message
    1.90 +                                            // Now, let's make sure we've copied in 
    1.91 +                                            // any information sent in by the app if
    1.92 +                                            // needed...
    1.93 +                                            reconcile_src_and_inner_messages(src, inner_message);
    1.94 +                                            
    1.95                                              // FIXME: free msg, but check references
    1.96                                              src = msg = inner_message;
    1.97