even nicer
authorVolker Birk <vb@pep-project.org>
Sat, 28 Mar 2015 11:39:05 +0100
changeset 151ece2659f90f6
parent 150 a8672133ab9d
child 152 f97cd2862f49
even nicer
Makefile
src/etpan_mime.c
src/etpan_mime.h
src/mime.c
     1.1 --- a/Makefile	Sat Mar 28 11:18:20 2015 +0100
     1.2 +++ b/Makefile	Sat Mar 28 11:39:05 2015 +0100
     1.3 @@ -17,6 +17,7 @@
     1.4  
     1.5  test: all
     1.6  	$(MAKE) -C test test
     1.7 +	$(MAKE) -C test unit_tests
     1.8  
     1.9  unit_tests: all
    1.10  	$(MAKE) -C test unit_tests
     2.1 --- a/src/etpan_mime.c	Sat Mar 28 11:18:20 2015 +0100
     2.2 +++ b/src/etpan_mime.c	Sat Mar 28 11:39:05 2015 +0100
     2.3 @@ -578,10 +578,12 @@
     2.4  {
     2.5      clistiter *cur;
     2.6  
     2.7 -    assert(list);
     2.8      assert(name);
     2.9      assert(value);
    2.10  
    2.11 +    if (list == NULL)
    2.12 +        return false;
    2.13 +
    2.14      for (cur = clist_begin(list); cur != NULL ; cur = clist_next(cur)) {
    2.15          struct mailmime_parameter * param = clist_content(cur);
    2.16          if (param &&
    2.17 @@ -619,48 +621,34 @@
    2.18      return content;
    2.19  }
    2.20  
    2.21 -bool _is_multipart(struct mailmime_content *content)
    2.22 +bool _is_multipart(struct mailmime_content *content, const char *subtype)
    2.23  {
    2.24 -    bool result = false;
    2.25 -
    2.26      assert(content);
    2.27  
    2.28      if (content->ct_type && content->ct_type->tp_type ==
    2.29              MAILMIME_TYPE_COMPOSITE_TYPE &&
    2.30              content->ct_type->tp_data.tp_composite_type &&
    2.31              content->ct_type->tp_data.tp_composite_type->ct_type ==
    2.32 -            MAILMIME_COMPOSITE_TYPE_MULTIPART)
    2.33 -        result = true;
    2.34 +            MAILMIME_COMPOSITE_TYPE_MULTIPART) {
    2.35 +        if (subtype)
    2.36 +            return content->ct_subtype &&
    2.37 +                    strcmp(content->ct_subtype, subtype) == 0;
    2.38 +        else
    2.39 +            return true;
    2.40 +    }
    2.41  
    2.42 -    return result;
    2.43 -}
    2.44 -
    2.45 -bool _is_multipart_alternative(struct mailmime_content *content)
    2.46 -{
    2.47 -    bool result = false;
    2.48 -
    2.49 -    assert(content);
    2.50 -
    2.51 -    if (_is_multipart(content) && content->ct_subtype &&
    2.52 -            strcmp(content->ct_subtype, "alternative") == 0)
    2.53 -        result = true;
    2.54 -
    2.55 -    return result;
    2.56 +    return false;
    2.57  }
    2.58  
    2.59  bool _is_PGP_MIME(struct mailmime_content *content)
    2.60  {
    2.61 -    bool result = false;
    2.62 -
    2.63      assert(content);
    2.64  
    2.65 -    if (_is_multipart(content) && content->ct_subtype &&
    2.66 -            strcmp(content->ct_subtype, "encrypted") == 0 &&
    2.67 -            content->ct_parameters &&
    2.68 +    if (_is_multipart(content, "encrypted") &&
    2.69              parameter_has_value(content->ct_parameters, "protocol",
    2.70                      "application/pgp-encrypted"))
    2.71 -        result = true;
    2.72 +        return true;
    2.73  
    2.74 -    return result;
    2.75 +    return false;
    2.76  }
    2.77  
     3.1 --- a/src/etpan_mime.h	Sat Mar 28 11:18:20 2015 +0100
     3.2 +++ b/src/etpan_mime.h	Sat Mar 28 11:39:05 2015 +0100
     3.3 @@ -67,7 +67,6 @@
     3.4  
     3.5  clist * _get_fields(struct mailmime * mime);
     3.6  struct mailmime_content * _get_content(struct mailmime * mime);
     3.7 -bool _is_multipart(struct mailmime_content *content);
     3.8 -bool _is_multipart_alternative(struct mailmime_content * content);
     3.9 +bool _is_multipart(struct mailmime_content *content, const char *subtype);
    3.10  bool _is_PGP_MIME(struct mailmime_content *content);
    3.11  
     4.1 --- a/src/mime.c	Sat Mar 28 11:18:20 2015 +0100
     4.2 +++ b/src/mime.c	Sat Mar 28 11:39:05 2015 +0100
     4.3 @@ -1239,7 +1239,7 @@
     4.4  
     4.5      struct mailmime_content *content = mime->mm_content_type;
     4.6      if (content) {
     4.7 -        if (msg->longmsg == NULL && _is_multipart_alternative(content)) {
     4.8 +        if (msg->longmsg == NULL && _is_multipart(content, "alternative")) {
     4.9              clist *partlist = mime->mm_data.mm_multipart.mm_mp_list;
    4.10              if (partlist == NULL)
    4.11                  return PEP_ILLEGAL_VALUE;
    4.12 @@ -1314,7 +1314,7 @@
    4.13                  }
    4.14              }
    4.15          }
    4.16 -        if (_is_multipart(content)) {
    4.17 +        if (_is_multipart(content, NULL)) {
    4.18              clist *partlist = mime->mm_data.mm_multipart.mm_mp_list;
    4.19              if (partlist == NULL)
    4.20                  return PEP_ILLEGAL_VALUE;