src/etpan_mime.c
changeset 4719 b4d7c37ac808
parent 4592 f0e7ec9616c5
child 4771 4d01b38a013b
     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  }