Merged in ENGINE-442
authorKrista Bennett <krista@pep-project.org>
Wed, 27 Jun 2018 17:10:24 +0200
changeset 27797618e2247a78
parent 2775 a513ca50bcd9
parent 2778 aef57434e32b
child 2781 50318bebf6ef
child 2784 dcb0d2263697
Merged in ENGINE-442
     1.1 --- a/src/message_api.c	Wed Jun 27 16:55:18 2018 +0200
     1.2 +++ b/src/message_api.c	Wed Jun 27 17:10:24 2018 +0200
     1.3 @@ -206,7 +206,10 @@
     1.4      }
     1.5  }
     1.6  
     1.7 -void replace_opt_field(message *msg, const char *name, const char *value)
     1.8 +void replace_opt_field(message *msg, 
     1.9 +                       const char *name, 
    1.10 +                       const char *value,
    1.11 +                       bool clobber)
    1.12  {
    1.13      assert(msg && name && value);
    1.14      
    1.15 @@ -226,8 +229,10 @@
    1.16          }
    1.17          
    1.18          if (pair) {
    1.19 -            free(pair->value);
    1.20 -            pair->value = strdup(value);
    1.21 +            if (clobber) {
    1.22 +                free(pair->value);
    1.23 +                pair->value = strdup(value);
    1.24 +            }
    1.25          }
    1.26          else {
    1.27              add_opt_field(msg, name, value);
    1.28 @@ -235,25 +240,25 @@
    1.29      }
    1.30  }
    1.31  
    1.32 -
    1.33  static void decorate_message(
    1.34      message *msg,
    1.35      PEP_rating rating,
    1.36      stringlist_t *keylist,
    1.37 -    bool add_version
    1.38 +    bool add_version,
    1.39 +    bool clobber
    1.40      )
    1.41  {
    1.42      assert(msg);
    1.43  
    1.44      if (add_version)
    1.45 -        replace_opt_field(msg, "X-pEp-Version", PEP_VERSION);
    1.46 +        replace_opt_field(msg, "X-pEp-Version", PEP_VERSION, clobber);
    1.47  
    1.48      if (rating != PEP_rating_undefined)
    1.49 -        replace_opt_field(msg, "X-EncStatus", rating_to_string(rating));
    1.50 +        replace_opt_field(msg, "X-EncStatus", rating_to_string(rating), clobber);
    1.51  
    1.52      if (keylist) {
    1.53          char *_keylist = keylist_to_string(keylist);
    1.54 -        replace_opt_field(msg, "X-KeyList", _keylist);
    1.55 +        replace_opt_field(msg, "X-KeyList", _keylist, clobber);
    1.56          free(_keylist);
    1.57      }
    1.58  }
    1.59 @@ -903,7 +908,7 @@
    1.60  
    1.61      PEP_STATUS status = PEP_STATUS_OK;
    1.62  
    1.63 -    replace_opt_field(attachment, "X-pEp-Version", PEP_VERSION);
    1.64 +    replace_opt_field(attachment, "X-pEp-Version", PEP_VERSION, true);
    1.65          
    1.66      if (!_envelope) {
    1.67          _envelope = extract_minimal_envelope(attachment, PEP_dir_outgoing);
    1.68 @@ -1798,7 +1803,7 @@
    1.69              attach_own_key(session, src);
    1.70              added_key_to_real_src = true;
    1.71          }
    1.72 -        decorate_message(src, PEP_rating_undefined, NULL, true);
    1.73 +        decorate_message(src, PEP_rating_undefined, NULL, true, true);
    1.74          return PEP_UNENCRYPTED;
    1.75      }
    1.76      else {
    1.77 @@ -1858,7 +1863,7 @@
    1.78      }
    1.79  
    1.80      if (msg) {
    1.81 -        decorate_message(msg, PEP_rating_undefined, NULL, true);
    1.82 +        decorate_message(msg, PEP_rating_undefined, NULL, true, true);
    1.83          if (_src->id) {
    1.84              msg->id = strdup(_src->id);
    1.85              assert(msg->id);
    1.86 @@ -2187,7 +2192,7 @@
    1.87               if (msg->id == NULL)
    1.88                   goto enomem;
    1.89           }
    1.90 -         decorate_message(msg, PEP_rating_undefined, NULL, true);
    1.91 +         decorate_message(msg, PEP_rating_undefined, NULL, true, true);
    1.92       }
    1.93  
    1.94      *dst = msg;
    1.95 @@ -3394,7 +3399,7 @@
    1.96      if (msg) {
    1.97          
    1.98          /* add pEp-related status flags to header */
    1.99 -        decorate_message(msg, *rating, _keylist, false);
   1.100 +        decorate_message(msg, *rating, _keylist, false, false);
   1.101          
   1.102          if (imported_keys)
   1.103              remove_attached_keys(msg);