ENGINE-755: now works and is tested, though if we want to do this right we should modify the rest of the test as well... !!!!!!!!REQUIRES LIBETPAN UPDATE!!!!!!!! Release_2.1.0-RC1
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Fri, 29 May 2020 14:39:48 +0200
changeset 4719b4d7c37ac808
parent 4716 f8a5313261e6
child 4724 71ceab3c46c2
ENGINE-755: now works and is tested, though if we want to do this right we should modify the rest of the test as well... !!!!!!!!REQUIRES LIBETPAN UPDATE!!!!!!!!
src/etpan_mime.c
src/message_api.c
test/src/EncryptForIdentityTest.cc
     1.1 --- a/src/etpan_mime.c	Thu May 28 11:48:42 2020 +0200
     1.2 +++ b/src/etpan_mime.c	Fri May 29 14:39:48 2020 +0200
     1.3 @@ -566,10 +566,25 @@
     1.4      if (_name == NULL)
     1.5          goto enomem;
     1.6  
     1.7 -    _address = strdup(address);
     1.8 -    if (_address == NULL)
     1.9 -        goto enomem;
    1.10 -
    1.11 +    char* at = strstr(address, "@");
    1.12 +    if (!at) {
    1.13 +        // Presumed URI
    1.14 +        int added_char_len = 6; // " " @URI 
    1.15 +        int new_addr_len = strlen(address) + added_char_len + 1;
    1.16 +        _address = calloc(new_addr_len, 1);
    1.17 +        if (_address == NULL)
    1.18 +            goto enomem;
    1.19 +        
    1.20 +        _address[0] = '"';
    1.21 +        strlcat(_address, address, new_addr_len);
    1.22 +        strlcat(_address, "\"@URI", new_addr_len);
    1.23 +    }
    1.24 +    else {
    1.25 +        _address = strdup(address);
    1.26 +        if (_address == NULL)
    1.27 +            goto enomem;
    1.28 +    }
    1.29 +            
    1.30      mb = mailimf_mailbox_new(_name, _address);
    1.31      assert(mb);
    1.32      if (mb == NULL)
    1.33 @@ -2071,6 +2086,7 @@
    1.34  static pEp_identity *mailbox_to_identity(const struct mailimf_mailbox * mb)
    1.35  {
    1.36      char *username = NULL;
    1.37 +    char *address = NULL;
    1.38  
    1.39      assert(mb);
    1.40      assert(mb->mb_addr_spec);
    1.41 @@ -2086,14 +2102,30 @@
    1.42              goto enomem;
    1.43      }
    1.44  
    1.45 -    pEp_identity *ident = new_identity(mb->mb_addr_spec, NULL, NULL, username);
    1.46 +    const char* raw_addr = mb->mb_addr_spec;
    1.47 +    if (raw_addr && raw_addr[0] == '"') {
    1.48 +        int addr_len = strlen(raw_addr);
    1.49 +        if (addr_len >= 6) { // ""@URI
    1.50 +            const char* endcheck = strstr(raw_addr + 1, "\"@URI");
    1.51 +            if (endcheck && *(endcheck + 5) == '\0') {
    1.52 +                int actual_size = addr_len - 6;
    1.53 +                address = calloc(actual_size + 1, 1);
    1.54 +                if (!address)
    1.55 +                    goto enomem;
    1.56 +                strlcpy(address, raw_addr + 1, actual_size + 1);    
    1.57 +            }
    1.58 +        }
    1.59 +    }
    1.60 +
    1.61 +    pEp_identity *ident = new_identity(address ? address : raw_addr, NULL, NULL, username);
    1.62      if (ident == NULL)
    1.63          goto enomem;
    1.64      free(username);
    1.65 -
    1.66 +    free(address);
    1.67      return ident;
    1.68  
    1.69  enomem:
    1.70 +    free(address);
    1.71      free(username);
    1.72      return NULL;
    1.73  }
     2.1 --- a/src/message_api.c	Thu May 28 11:48:42 2020 +0200
     2.2 +++ b/src/message_api.c	Fri May 29 14:39:48 2020 +0200
     2.3 @@ -3296,8 +3296,11 @@
     2.4  
     2.5      PEP_STATUS status = PEP_STATUS_OK;
     2.6      
     2.7 -    if (strcasecmp(src->from->address, inner_message->from->address) == 0)
     2.8 +    if (src->from && inner_message->from && 
     2.9 +           src->from->address && inner_message->from->address && 
    2.10 +           strcasecmp(src->from->address, inner_message->from->address) == 0) {
    2.11          status = reconcile_identity(src->from, inner_message->from);
    2.12 +    }    
    2.13      
    2.14      if (status == PEP_STATUS_OK && inner_message->to)
    2.15          status = reconcile_identity_lists(src->to, inner_message->to);
     3.1 --- a/test/src/EncryptForIdentityTest.cc	Thu May 28 11:48:42 2020 +0200
     3.2 +++ b/test/src/EncryptForIdentityTest.cc	Fri May 29 14:39:48 2020 +0200
     3.3 @@ -618,4 +618,3 @@
     3.4      }
     3.5      output_stream << "Encrypted ONLY for Alice! Test passed. Move along. These are not the bugs you are looking for." << endl;
     3.6  }
     3.7 -