src/etpan_mime.c
changeset 147 b03a10242e4c
parent 130 507895068f83
child 151 ece2659f90f6
     1.1 --- a/src/etpan_mime.c	Fri Mar 27 13:36:57 2015 +0100
     1.2 +++ b/src/etpan_mime.c	Sat Mar 28 10:52:40 2015 +0100
     1.3 @@ -570,3 +570,97 @@
     1.4      return r;
     1.5  }
     1.6  
     1.7 +static bool parameter_has_value(
     1.8 +        clist *list,
     1.9 +        const char *name,
    1.10 +        const char *value
    1.11 +    )
    1.12 +{
    1.13 +    clistiter *cur;
    1.14 +
    1.15 +    assert(list);
    1.16 +    assert(name);
    1.17 +    assert(value);
    1.18 +
    1.19 +    for (cur = clist_begin(list); cur != NULL ; cur = clist_next(cur)) {
    1.20 +        struct mailmime_parameter * param = clist_content(cur);
    1.21 +        if (param &&
    1.22 +                param->pa_name && strcmp(name, param->pa_name) == 0 &&
    1.23 +                param->pa_value && strcmp(value, param->pa_value) == 0)
    1.24 +            return true;
    1.25 +    }
    1.26 +
    1.27 +    return false;
    1.28 +}
    1.29 +
    1.30 +clist * _get_fields(struct mailmime * mime)
    1.31 +{
    1.32 +    clist * _fieldlist = NULL;
    1.33 +
    1.34 +    assert(mime);
    1.35 +
    1.36 +    if (mime->mm_data.mm_message.mm_fields &&
    1.37 +            mime->mm_data.mm_message.mm_fields->fld_list) {
    1.38 +        _fieldlist = mime->mm_data.mm_message.mm_fields->fld_list;
    1.39 +    }
    1.40 +
    1.41 +    return _fieldlist;
    1.42 +}
    1.43 +
    1.44 +struct mailmime_content * _get_content(struct mailmime * mime)
    1.45 +{
    1.46 +    struct mailmime_content * content = NULL;
    1.47 +
    1.48 +    assert(mime);
    1.49 +
    1.50 +    if (mime->mm_data.mm_message.mm_msg_mime)
    1.51 +        content = mime->mm_data.mm_message.mm_msg_mime->mm_content_type;
    1.52 +
    1.53 +    return content;
    1.54 +}
    1.55 +
    1.56 +bool _is_multipart(struct mailmime_content *content)
    1.57 +{
    1.58 +    bool result = false;
    1.59 +
    1.60 +    assert(content);
    1.61 +
    1.62 +    if (content->ct_type && content->ct_type->tp_type ==
    1.63 +            MAILMIME_TYPE_COMPOSITE_TYPE &&
    1.64 +            content->ct_type->tp_data.tp_composite_type &&
    1.65 +            content->ct_type->tp_data.tp_composite_type->ct_type ==
    1.66 +            MAILMIME_COMPOSITE_TYPE_MULTIPART)
    1.67 +        result = true;
    1.68 +
    1.69 +    return result;
    1.70 +}
    1.71 +
    1.72 +bool _is_multipart_alternative(struct mailmime_content *content)
    1.73 +{
    1.74 +    bool result = false;
    1.75 +
    1.76 +    assert(content);
    1.77 +
    1.78 +    if (_is_multipart(content) && content->ct_subtype &&
    1.79 +            strcmp(content->ct_subtype, "alternative") == 0)
    1.80 +        result = true;
    1.81 +
    1.82 +    return result;
    1.83 +}
    1.84 +
    1.85 +bool _is_PGP_MIME(struct mailmime_content *content)
    1.86 +{
    1.87 +    bool result = false;
    1.88 +
    1.89 +    assert(content);
    1.90 +
    1.91 +    if (_is_multipart(content) && content->ct_subtype &&
    1.92 +            strcmp(content->ct_subtype, "encrypted") == 0 &&
    1.93 +            content->ct_parameters &&
    1.94 +            parameter_has_value(content->ct_parameters, "protocol",
    1.95 +                    "application/pgp-encrypted"))
    1.96 +        result = true;
    1.97 +
    1.98 +    return result;
    1.99 +}
   1.100 +