src/etpan_mime.c
branchENGINE-9
changeset 1878 aa44c9c98214
parent 1873 2da96adc534e
child 1881 facb0b5b0bce
     1.1 --- a/src/etpan_mime.c	Tue Jun 20 14:35:51 2017 +0200
     1.2 +++ b/src/etpan_mime.c	Wed Jun 21 13:18:12 2017 +0200
     1.3 @@ -183,7 +183,7 @@
     1.4  }
     1.5  
     1.6  struct mailmime * get_text_part(
     1.7 -        const char * filename,
     1.8 +        pEp_rid_list_t* resource,
     1.9          const char * mime_type,
    1.10          const char * text,
    1.11          size_t length,
    1.12 @@ -197,33 +197,45 @@
    1.13  	struct mailmime_parameter * param = NULL;
    1.14  	struct mailmime_disposition * disposition = NULL;
    1.15  	struct mailmime_mechanism * encoding = NULL;
    1.16 +    char* content_id = NULL;
    1.17      int r;
    1.18 +                
    1.19 +    if (resource != NULL && resource->rid != NULL) {
    1.20 +        switch (resource->rid_type) {
    1.21 +            case PEP_RID_CID:
    1.22 +                content_id = strdup(resource->rid);
    1.23 +                break;
    1.24 +            case PEP_RID_FILENAME:
    1.25 +            default:
    1.26 +                disposition_name = strdup(resource->rid);
    1.27 +                if (disposition_name == NULL)
    1.28 +                    goto enomem;
    1.29 +                    
    1.30 +                disposition =
    1.31 +                        mailmime_disposition_new_with_data(MAILMIME_DISPOSITION_TYPE_INLINE,
    1.32 +                                disposition_name, NULL, NULL, NULL, (size_t) -1);
    1.33 +
    1.34 +                if (disposition == NULL)
    1.35 +                    goto enomem;
    1.36 +
    1.37 +                disposition_name = NULL;                
    1.38 +                break;
    1.39 +        }    
    1.40 +    }
    1.41      
    1.42 -    if (filename != NULL) {
    1.43 -        disposition_name = strdup(filename);
    1.44 -        if (disposition_name == NULL)
    1.45 -            goto enomem;
    1.46 -    }
    1.47 -
    1.48      if (encoding_type) {
    1.49          encoding = mailmime_mechanism_new(encoding_type, NULL);
    1.50          if (encoding == NULL)
    1.51              goto enomem;
    1.52      }
    1.53  
    1.54 -    disposition =
    1.55 -            mailmime_disposition_new_with_data(MAILMIME_DISPOSITION_TYPE_INLINE,
    1.56 -                    disposition_name, NULL, NULL, NULL, (size_t) -1);
    1.57 -    if (disposition == NULL)
    1.58 -        goto enomem;
    1.59 -    disposition_name = NULL;
    1.60 -
    1.61 -    mime_fields = mailmime_fields_new_with_data(encoding, NULL, NULL,
    1.62 +    mime_fields = mailmime_fields_new_with_data(encoding, content_id, NULL,
    1.63              disposition, NULL);
    1.64      if (mime_fields == NULL)
    1.65          goto enomem;
    1.66      encoding = NULL;
    1.67      disposition = NULL;
    1.68 +    content_id = NULL;
    1.69  
    1.70  	content = mailmime_content_new_with_str(mime_type);
    1.71      if (content == NULL)
    1.72 @@ -269,7 +281,7 @@
    1.73  }
    1.74  
    1.75  struct mailmime * get_file_part(
    1.76 -        const char * filename,
    1.77 +        pEp_rid_list_t* resource,
    1.78          const char * mime_type,
    1.79          char * data,
    1.80          size_t length
    1.81 @@ -282,20 +294,32 @@
    1.82      struct mailmime_content * content = NULL;
    1.83      struct mailmime * mime = NULL;
    1.84      struct mailmime_fields * mime_fields = NULL;
    1.85 +    char* content_id = NULL;
    1.86      int r;
    1.87 -
    1.88 -    if (filename != NULL) {
    1.89 -        disposition_name = strdup(filename);
    1.90 -        if (disposition_name == NULL)
    1.91 -            goto enomem;
    1.92 +                
    1.93 +    if (resource != NULL && resource->rid != NULL) {
    1.94 +        switch (resource->rid_type) {
    1.95 +            case PEP_RID_CID:
    1.96 +                content_id = strdup(resource->rid);
    1.97 +                break;
    1.98 +            case PEP_RID_FILENAME:
    1.99 +            default:
   1.100 +                disposition_name = strdup(resource->rid);
   1.101 +                if (disposition_name == NULL)
   1.102 +                    goto enomem;
   1.103 +                    
   1.104 +                disposition =
   1.105 +                        mailmime_disposition_new_with_data(MAILMIME_DISPOSITION_TYPE_ATTACHMENT,
   1.106 +                                disposition_name, NULL, NULL, NULL, (size_t) -1);
   1.107 +                                
   1.108 +                if (disposition == NULL)
   1.109 +                    goto enomem;
   1.110 +                disposition_name = NULL;
   1.111 +                
   1.112 +                break;
   1.113 +        }    
   1.114      }
   1.115 -
   1.116 -    disposition =
   1.117 -            mailmime_disposition_new_with_data(MAILMIME_DISPOSITION_TYPE_ATTACHMENT,
   1.118 -                    disposition_name, NULL, NULL, NULL, (size_t) -1);
   1.119 -    if (disposition == NULL)
   1.120 -        goto enomem;
   1.121 -    disposition_name = NULL;
   1.122 +    
   1.123  
   1.124      content = mailmime_content_new_with_str(mime_type);
   1.125      if (content == NULL)
   1.126 @@ -306,7 +330,7 @@
   1.127      if (encoding == NULL)
   1.128          goto enomem;
   1.129  
   1.130 -    mime_fields = mailmime_fields_new_with_data(encoding, NULL, NULL,
   1.131 +    mime_fields = mailmime_fields_new_with_data(encoding, content_id, NULL,
   1.132              disposition, NULL);
   1.133      if (mime_fields == NULL)
   1.134          goto enomem;
   1.135 @@ -340,7 +364,7 @@
   1.136          mailmime_fields_free(mime_fields);
   1.137      if (mime)
   1.138          mailmime_free(mime);
   1.139 -
   1.140 +    
   1.141      return NULL;
   1.142  }
   1.143