src/etpan_mime.c
branchENGINE-9
changeset 1873 2da96adc534e
parent 1872 23b14ab93b11
child 1878 aa44c9c98214
     1.1 --- a/src/etpan_mime.c	Mon Jun 19 09:32:00 2017 +0200
     1.2 +++ b/src/etpan_mime.c	Tue Jun 20 14:28:31 2017 +0200
     1.3 @@ -596,7 +596,7 @@
     1.4      return content;
     1.5  }
     1.6  
     1.7 -char* _get_uri(char* uri_prefix, char* resource) {
     1.8 +char* _build_uri(char* uri_prefix, char* resource) {
     1.9      if (!uri_prefix || !resource)
    1.10          return NULL;
    1.11      const char* delim = "://";
    1.12 @@ -613,7 +613,61 @@
    1.13      return retval;
    1.14  }
    1.15  
    1.16 +/* Return a list of identifier_type and resource id (filename, cid, etc) */
    1.17 +pEp_rid_list_t* _get_resource_id_list(struct mailmime *mime)
    1.18 +{
    1.19 +    clist * _fieldlist = NULL;
    1.20  
    1.21 +    assert(mime);
    1.22 +
    1.23 +    if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list)
    1.24 +        _fieldlist = mime->mm_mime_fields->fld_list;
    1.25 +    else
    1.26 +        return NULL;
    1.27 +
    1.28 +    clistiter *cur;
    1.29 +
    1.30 +    pEp_rid_list_t* rid_list = NULL; 
    1.31 +    pEp_rid_list_t** rid_list_curr_p = &rid_list; 
    1.32 +        
    1.33 +    for (cur = clist_begin(_fieldlist); cur; cur = clist_next(cur)) {
    1.34 +        struct mailmime_field * _field = clist_content(cur);
    1.35 +        /* content_id */
    1.36 +        if (_field && _field->fld_type == MAILMIME_FIELD_ID) {
    1.37 +            pEp_rid_list_t* new_rid = (pEp_rid_list_t*)calloc(1, sizeof(pEp_rid_list_t*));
    1.38 +            new_rid->rid_type = PEP_RID_CID;
    1.39 +            new_rid->rid = _field->fld_data.fld_id;
    1.40 +            *rid_list_curr_p = new_rid;
    1.41 +            rid_list_curr_p = &new_rid->next;
    1.42 +        }
    1.43 +        else if (_field && _field->fld_type == MAILMIME_FIELD_DISPOSITION) {
    1.44 +            /* filename */
    1.45 +            if (_field->fld_data.fld_disposition &&
    1.46 +                    _field->fld_data.fld_disposition->dsp_parms) {
    1.47 +                clist * _parmlist =
    1.48 +                        _field->fld_data.fld_disposition->dsp_parms;
    1.49 +                clistiter *cur2;
    1.50 +                for (cur2 = clist_begin(_parmlist); cur2; cur2 =
    1.51 +                        clist_next(cur2)) {
    1.52 +                    struct mailmime_disposition_parm * param =
    1.53 +                            clist_content(cur2);
    1.54 +                    if (param->pa_type == MAILMIME_DISPOSITION_PARM_FILENAME) {
    1.55 +                        pEp_rid_list_t* new_rid = (pEp_rid_list_t*)calloc(1, sizeof(pEp_rid_list_t*));
    1.56 +                        new_rid->rid_type = PEP_RID_FILENAME;
    1.57 +                        new_rid->rid = param->pa_data.pa_filename;
    1.58 +                        *rid_list_curr_p = new_rid;
    1.59 +                        rid_list_curr_p = &new_rid->next;
    1.60 +                    }                
    1.61 +                }
    1.62 +            }
    1.63 +        }
    1.64 +    }
    1.65 +    /* Will almost certainly usually be a singleton, but we need to be able to decide */
    1.66 +    return rid_list;
    1.67 +}
    1.68 +
    1.69 +
    1.70 +/* FIXME: about to be obsoleted? */
    1.71  char * _get_filename_or_cid(struct mailmime *mime)
    1.72  {
    1.73      clist * _fieldlist = NULL;
    1.74 @@ -626,11 +680,20 @@
    1.75          return NULL;
    1.76  
    1.77      clistiter *cur;
    1.78 +    
    1.79 +    char* _temp_filename_ptr = NULL;
    1.80 +    
    1.81      for (cur = clist_begin(_fieldlist); cur; cur = clist_next(cur)) {
    1.82          struct mailmime_field * _field = clist_content(cur);
    1.83 -        if (_field && _field->fld_type == MAILMIME_FIELD_DISPOSITION) {
    1.84 +        if (_field && _field->fld_type == MAILMIME_FIELD_ID) {
    1.85 +            /* We prefer CIDs to filenames when both are present */
    1.86 +            free(_temp_filename_ptr); /* can be null, it's ok */
    1.87 +            return _build_uri("cid", _field->fld_data.fld_id); 
    1.88 +        }
    1.89 +        else if (_field && _field->fld_type == MAILMIME_FIELD_DISPOSITION) {
    1.90              if (_field->fld_data.fld_disposition &&
    1.91 -                    _field->fld_data.fld_disposition->dsp_parms) {
    1.92 +                    _field->fld_data.fld_disposition->dsp_parms &&
    1.93 +                    !_temp_filename_ptr) {
    1.94                  clist * _parmlist =
    1.95                          _field->fld_data.fld_disposition->dsp_parms;
    1.96                  clistiter *cur2;
    1.97 @@ -638,16 +701,16 @@
    1.98                          clist_next(cur2)) {
    1.99                      struct mailmime_disposition_parm * param =
   1.100                              clist_content(cur2);
   1.101 -                    if (param->pa_type == MAILMIME_DISPOSITION_PARM_FILENAME)
   1.102 -                        return _get_uri("file", param->pa_data.pa_filename);
   1.103 +                    if (param->pa_type == MAILMIME_DISPOSITION_PARM_FILENAME) {
   1.104 +                        _temp_filename_ptr = _build_uri("file", param->pa_data.pa_filename);
   1.105 +                        break;
   1.106 +                    }                
   1.107                  }
   1.108              }
   1.109          }
   1.110 -        else if (_field && _field->fld_type == MAILMIME_FIELD_ID) 
   1.111 -            return _get_uri("cid", _field->fld_data.fld_id); 
   1.112      }
   1.113 -
   1.114 -    return NULL;
   1.115 +    /* Ok, it wasn't a CID */
   1.116 +    return _temp_filename_ptr;
   1.117  }
   1.118  
   1.119  static bool parameter_has_value(