ENGINE-109 - Now with appropriate handling of CIDs in generated messages! ENGINE-9
authorKrista Bennett <krista@pep-project.org>
Wed, 21 Jun 2017 13:18:12 +0200
branchENGINE-9
changeset 1878aa44c9c98214
parent 1874 ca396bbc2124
child 1879 8b28ba5fbeb0
ENGINE-109 - Now with appropriate handling of CIDs in generated messages!
src/etpan_mime.c
src/etpan_mime.h
src/mime.c
     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  
     2.1 --- a/src/etpan_mime.h	Tue Jun 20 14:35:51 2017 +0200
     2.2 +++ b/src/etpan_mime.h	Wed Jun 21 13:18:12 2017 +0200
     2.3 @@ -7,19 +7,7 @@
     2.4  #include <libetpan/mailmime.h>
     2.5  #include <libetpan/mailmime_encode.h>
     2.6  
     2.7 -/* structs to contain info about parsed resource ids (filenames, uids) */
     2.8 -typedef enum _resource_id_type {
     2.9 -    PEP_RID_FILENAME,
    2.10 -    PEP_RID_CID
    2.11 -} pEp_resource_id_type;
    2.12 -
    2.13 -typedef struct pEp_rid_list_t pEp_rid_list_t;
    2.14 -
    2.15 -struct pEp_rid_list_t {
    2.16 -    pEp_resource_id_type rid_type;
    2.17 -    char* rid;
    2.18 -    pEp_rid_list_t* next;    
    2.19 -};
    2.20 +#include "resource_id.h"
    2.21  
    2.22  struct mailmime * part_new_empty(
    2.23          struct mailmime_content * content,
    2.24 @@ -30,7 +18,7 @@
    2.25  struct mailmime * get_pgp_encrypted_part(void);
    2.26  
    2.27  struct mailmime * get_text_part(
    2.28 -        const char * filename,
    2.29 +        pEp_rid_list_t* resource,
    2.30          const char * mime_type,
    2.31          const char * text,
    2.32          size_t length,
    2.33 @@ -38,7 +26,7 @@
    2.34      );
    2.35  
    2.36  struct mailmime * get_file_part(
    2.37 -        const char * filename,
    2.38 +        pEp_rid_list_t* resource,
    2.39          const char * mime_type,
    2.40          char * data,
    2.41          size_t length
     3.1 --- a/src/mime.c	Tue Jun 20 14:35:51 2017 +0200
     3.2 +++ b/src/mime.c	Wed Jun 21 13:18:12 2017 +0200
     3.3 @@ -9,6 +9,7 @@
     3.4  #include <assert.h>
     3.5  #include <errno.h>
     3.6  
     3.7 +#include "resource_id.h"
     3.8  #include "etpan_mime.h"
     3.9  #include "wrappers.h"
    3.10  
    3.11 @@ -118,8 +119,13 @@
    3.12      if (mime == NULL)
    3.13          goto enomem;
    3.14  
    3.15 -    submime = get_text_part("msg.txt", "text/plain", plaintext, strlen(plaintext),
    3.16 +    pEp_rid_list_t* resource = new_rid_node(PEP_RID_FILENAME, "msg.txt");
    3.17 +    
    3.18 +    submime = get_text_part(resource, "text/plain", plaintext, strlen(plaintext),
    3.19              MAILMIME_MECHANISM_QUOTED_PRINTABLE);
    3.20 +    free_rid_list(resource);
    3.21 +    resource = NULL;
    3.22 +    
    3.23      assert(submime);
    3.24      if (submime == NULL)
    3.25          goto enomem;
    3.26 @@ -134,8 +140,12 @@
    3.27          submime = NULL;
    3.28      }
    3.29  
    3.30 -    submime = get_text_part("msg.html", "text/html", htmltext, strlen(htmltext),
    3.31 +    resource = new_rid_node(PEP_RID_FILENAME, "msg.html");
    3.32 +    submime = get_text_part(resource, "text/html", htmltext, strlen(htmltext),
    3.33              MAILMIME_MECHANISM_QUOTED_PRINTABLE);
    3.34 +    free_rid_list(resource);
    3.35 +    resource = NULL;
    3.36 +    
    3.37      assert(submime);
    3.38      if (submime == NULL)
    3.39          goto enomem;
    3.40 @@ -186,7 +196,10 @@
    3.41      else
    3.42          mime_type = blob->mime_type;
    3.43  
    3.44 -    mime = get_file_part(blob->filename, mime_type, blob->value, blob->size);
    3.45 +    pEp_rid_list_t* resource = parse_uri(blob->filename);
    3.46 +    mime = get_file_part(resource, mime_type, blob->value, blob->size);
    3.47 +    free_rid_list(resource);
    3.48 +    
    3.49      assert(mime);
    3.50      if (mime == NULL)
    3.51          goto enomem;
    3.52 @@ -619,12 +632,19 @@
    3.53              goto pep_error;
    3.54      }
    3.55      else {
    3.56 -        if (is_PGP_message_text(plaintext))
    3.57 -            mime = get_text_part("msg.asc", "application/octet-stream", plaintext,
    3.58 +        pEp_rid_list_t* resource = NULL;
    3.59 +        if (is_PGP_message_text(plaintext)) {
    3.60 +            resource = new_rid_node(PEP_RID_FILENAME, "msg.asc");
    3.61 +            mime = get_text_part(resource, "application/octet-stream", plaintext,
    3.62                      strlen(plaintext), MAILMIME_MECHANISM_7BIT);
    3.63 -        else
    3.64 -            mime = get_text_part("msg.txt", "text/plain", plaintext, strlen(plaintext),
    3.65 +        }
    3.66 +        else {
    3.67 +            resource = new_rid_node(PEP_RID_FILENAME, "msg.txt");
    3.68 +            mime = get_text_part(resource, "text/plain", plaintext, strlen(plaintext),
    3.69                      MAILMIME_MECHANISM_QUOTED_PRINTABLE);
    3.70 +        }
    3.71 +        free_rid_list(resource);
    3.72 +        
    3.73          assert(mime);
    3.74          if (mime == NULL)
    3.75              goto enomem;
    3.76 @@ -727,8 +747,12 @@
    3.77          submime = NULL;
    3.78      }
    3.79  
    3.80 -    submime = get_text_part("msg.asc", "application/octet-stream", plaintext,
    3.81 +    pEp_rid_list_t* resource = new_rid_node(PEP_RID_FILENAME, "msg.asc");
    3.82 +    submime = get_text_part(resource, "application/octet-stream", plaintext,
    3.83              plaintext_size, MAILMIME_MECHANISM_7BIT);
    3.84 +            
    3.85 +    free_rid_list(resource);
    3.86 +    
    3.87      assert(submime);
    3.88      if (submime == NULL)
    3.89          goto enomem;