ENGINE-9: Now with uri's and cids ENGINE-9
authorKrista Bennett <krista@pep-project.org>
Mon, 19 Jun 2017 09:32:00 +0200
branchENGINE-9
changeset 187223b14ab93b11
parent 1871 51337eb65533
child 1873 2da96adc534e
ENGINE-9: Now with uri's and cids
src/etpan_mime.c
src/etpan_mime.h
src/mime.c
     1.1 --- a/src/etpan_mime.c	Mon Jun 19 09:01:06 2017 +0200
     1.2 +++ b/src/etpan_mime.c	Mon Jun 19 09:32:00 2017 +0200
     1.3 @@ -596,7 +596,25 @@
     1.4      return content;
     1.5  }
     1.6  
     1.7 -char * _get_filename(struct mailmime *mime)
     1.8 +char* _get_uri(char* uri_prefix, char* resource) {
     1.9 +    if (!uri_prefix || !resource)
    1.10 +        return NULL;
    1.11 +    const char* delim = "://";
    1.12 +    const int delim_len = 3;
    1.13 +    int prefix_len = strlen(uri_prefix);
    1.14 +    int resource_len = strlen(resource);
    1.15 +    int retval_len = prefix_len + delim_len + resource_len;
    1.16 +
    1.17 +    char* retval = calloc(1, retval_len + 1);
    1.18 +    strlcpy(retval, uri_prefix, retval_len);
    1.19 +    strlcat(retval, delim, retval_len);
    1.20 +    strlcat(retval, resource, retval_len);
    1.21 +    
    1.22 +    return retval;
    1.23 +}
    1.24 +
    1.25 +
    1.26 +char * _get_filename_or_cid(struct mailmime *mime)
    1.27  {
    1.28      clist * _fieldlist = NULL;
    1.29  
    1.30 @@ -621,10 +639,12 @@
    1.31                      struct mailmime_disposition_parm * param =
    1.32                              clist_content(cur2);
    1.33                      if (param->pa_type == MAILMIME_DISPOSITION_PARM_FILENAME)
    1.34 -                        return param->pa_data.pa_filename;
    1.35 +                        return _get_uri("file", param->pa_data.pa_filename);
    1.36                  }
    1.37              }
    1.38          }
    1.39 +        else if (_field && _field->fld_type == MAILMIME_FIELD_ID) 
    1.40 +            return _get_uri("cid", _field->fld_data.fld_id); 
    1.41      }
    1.42  
    1.43      return NULL;
    1.44 @@ -784,4 +804,3 @@
    1.45  
    1.46      return EINVAL;
    1.47  }
    1.48 -
     2.1 --- a/src/etpan_mime.h	Mon Jun 19 09:01:06 2017 +0200
     2.2 +++ b/src/etpan_mime.h	Mon Jun 19 09:32:00 2017 +0200
     2.3 @@ -70,7 +70,7 @@
     2.4  
     2.5  clist * _get_fields(struct mailmime * mime);
     2.6  struct mailmime_content * _get_content(struct mailmime * mime);
     2.7 -char * _get_filename(struct mailmime *mime);
     2.8 +char * _get_filename_or_cid(struct mailmime *mime);
     2.9  bool _is_multipart(struct mailmime_content *content, const char *subtype);
    2.10  bool _is_PGP_MIME(struct mailmime_content *content);
    2.11  bool _is_text_part(struct mailmime_content *content, const char *subtype);
    2.12 @@ -80,4 +80,3 @@
    2.13          char **type,
    2.14          char **charset
    2.15      );
    2.16 -
     3.1 --- a/src/mime.c	Mon Jun 19 09:01:06 2017 +0200
     3.2 +++ b/src/mime.c	Mon Jun 19 09:32:00 2017 +0200
     3.3 @@ -1343,14 +1343,16 @@
     3.4                  if (status)
     3.5                      return status;
     3.6  
     3.7 -                filename = _get_filename(mime);
     3.8 +                filename = _get_filename_or_cid(mime);
     3.9                  char *_filename = NULL;
    3.10                  if (filename) {
    3.11                      size_t index = 0;
    3.12                      r = mailmime_encoded_phrase_parse("utf-8", filename,
    3.13                              strlen(filename), &index, "utf-8", &_filename);
    3.14 -                    if (r)
    3.15 +                    free(filename); /* new - _get_filename returns malloc'd str */
    3.16 +                    if (r) {
    3.17                          goto enomem;
    3.18 +                    }
    3.19                  }
    3.20  
    3.21                  bloblist_t *_a = bloblist_add(msg->attachments, data, size,