optional fields in MIME list
authorvb
Wed, 11 Mar 2015 17:17:22 +0100
changeset 110c51c34a97ba7
parent 109 297efc53ba70
child 111 817a757e03ad
optional fields in MIME
src/mime.c
     1.1 --- a/src/mime.c	Wed Mar 11 16:39:06 2015 +0100
     1.2 +++ b/src/mime.c	Wed Mar 11 17:17:22 2015 +0100
     1.3 @@ -548,9 +548,19 @@
     1.4      }
     1.5  
     1.6      if (msg->opt_fields) {
     1.7 -        r = _append_optional_field(fields_list, "X-pEp-Version", PEP_VERSION);
     1.8 -        if (r)
     1.9 -            goto enomem;
    1.10 +        stringpair_list_t *_l;
    1.11 +        for (_l = msg->opt_fields; _l; _l = _l->next) {
    1.12 +            char *key = _l->value->key;
    1.13 +            char *value = _l->value->value;
    1.14 +            char *_value = mailmime_encode_subject_header("utf-8", value, 0);
    1.15 +            if (_value == NULL)
    1.16 +                goto enomem;
    1.17 +
    1.18 +            r = _append_optional_field(fields_list, key, _value);
    1.19 +            free(_value);
    1.20 +            if (r)
    1.21 +                goto enomem;
    1.22 +        }
    1.23      }
    1.24  
    1.25      fields = mailimf_fields_new(fields_list);
    1.26 @@ -835,6 +845,7 @@
    1.27      clistiter *cur;
    1.28      size_t index;
    1.29      int r;
    1.30 +    stringpair_list_t *opt = msg->opt_fields;
    1.31  
    1.32      for (cur = clist_begin(fieldlist); cur != NULL; cur = clist_next(cur)) {
    1.33          _field = clist_content(cur);
    1.34 @@ -970,6 +981,34 @@
    1.35                          goto enomem;
    1.36                  }
    1.37                  break;
    1.38 +
    1.39 +            case MAILIMF_FIELD_OPTIONAL_FIELD:
    1.40 +                {
    1.41 +                    char * name =
    1.42 +                            _field->fld_data.fld_optional_field->fld_name;
    1.43 +                    char * value =
    1.44 +                            _field->fld_data.fld_optional_field->fld_value;
    1.45 +                    char *_value;
    1.46 +
    1.47 +                    index = 0;
    1.48 +                    r = mailmime_encoded_phrase_parse("utf-8", value,
    1.49 +                            strlen(value), &index, "utf-8", &_value);
    1.50 +                    if (r)
    1.51 +                        goto enomem;
    1.52 +
    1.53 +                    stringpair_t pair;
    1.54 +                    pair.key = name;
    1.55 +                    pair.value = _value;
    1.56 +
    1.57 +                    opt = stringpair_list_add(opt, &pair);
    1.58 +                    free(_value);
    1.59 +                    if (opt == NULL)
    1.60 +                        goto enomem;
    1.61 +
    1.62 +                    if (msg->opt_fields == NULL)
    1.63 +                        msg->opt_fields = opt;
    1.64 +                }
    1.65 +                break;
    1.66          }
    1.67      }
    1.68