1.1 --- a/src/etpan_mime.c Thu Apr 16 12:17:23 2020 +0200
1.2 +++ b/src/etpan_mime.c Mon Apr 20 17:32:53 2020 +0200
1.3 @@ -1129,33 +1129,35 @@
1.4
1.5 *result = NULL;
1.6
1.7 - mime = part_multiple_new("multipart/alternative");
1.8 - assert(mime);
1.9 - if (mime == NULL)
1.10 - goto enomem;
1.11 -
1.12 + int encoding_type = (transport_encode ? MAILMIME_MECHANISM_QUOTED_PRINTABLE : 0);
1.13 pEp_rid_list_t* resource = NULL;
1.14 -
1.15 - int encoding_type = (transport_encode ? MAILMIME_MECHANISM_QUOTED_PRINTABLE : 0);
1.16 - submime = get_text_part(NULL, "text/plain", plaintext, strlen(plaintext),
1.17 - encoding_type);
1.18 - free_rid_list(resource);
1.19 - resource = NULL;
1.20 +
1.21 + if (*plaintext != '\0') {
1.22 + mime = part_multiple_new("multipart/alternative");
1.23 + assert(mime);
1.24 + if (mime == NULL)
1.25 + goto enomem;
1.26 +
1.27 + submime = get_text_part(NULL, "text/plain", plaintext, strlen(plaintext),
1.28 + encoding_type);
1.29 + free_rid_list(resource);
1.30 + resource = NULL;
1.31 +
1.32 + assert(submime);
1.33 + if (submime == NULL)
1.34 + goto enomem;
1.35 +
1.36 + r = mailmime_smart_add_part(mime, submime);
1.37 + assert(r == MAILIMF_NO_ERROR);
1.38 + if (r == MAILIMF_ERROR_MEMORY) {
1.39 + goto enomem;
1.40 + }
1.41 + else {
1.42 + // mailmime_smart_add_part() takes ownership of submime
1.43 + submime = NULL;
1.44 + }
1.45 + }
1.46
1.47 - assert(submime);
1.48 - if (submime == NULL)
1.49 - goto enomem;
1.50 -
1.51 - r = mailmime_smart_add_part(mime, submime);
1.52 - assert(r == MAILIMF_NO_ERROR);
1.53 - if (r == MAILIMF_ERROR_MEMORY) {
1.54 - goto enomem;
1.55 - }
1.56 - else {
1.57 - // mailmime_smart_add_part() takes ownership of submime
1.58 - submime = NULL;
1.59 - }
1.60 -
1.61 bool inlined_attachments = false;
1.62
1.63 bloblist_t* traversal_ptr = attachments;
1.64 @@ -1175,19 +1177,26 @@
1.65 if (submime == NULL)
1.66 goto enomem;
1.67
1.68 + // This is where all of the html MIME stuff will go
1.69 top_level_html_mime = submime;
1.70
1.71 - r = mailmime_smart_add_part(mime, top_level_html_mime);
1.72 - assert(r == MAILIMF_NO_ERROR);
1.73 - if (r == MAILIMF_ERROR_MEMORY) {
1.74 - goto enomem;
1.75 - }
1.76 - else {
1.77 - // mailmime_smart_add_part() takes ownership of submime
1.78 - submime = NULL;
1.79 - }
1.80 + if (!mime)
1.81 + mime = top_level_html_mime;
1.82 + else {
1.83 + r = mailmime_smart_add_part(mime, top_level_html_mime);
1.84 + assert(r == MAILIMF_NO_ERROR);
1.85 + if (r == MAILIMF_ERROR_MEMORY) {
1.86 + goto enomem;
1.87 + }
1.88 + else {
1.89 + // mailmime_smart_add_part() takes ownership of submime
1.90 + submime = NULL;
1.91 + }
1.92 + }
1.93 }
1.94 else {
1.95 + // Otherwise, html MIME stuff gets added to the top node
1.96 + // - may be NULL if there's no multipart!
1.97 top_level_html_mime = mime;
1.98 }
1.99
1.100 @@ -1200,35 +1209,45 @@
1.101 assert(submime);
1.102 if (submime == NULL)
1.103 goto enomem;
1.104 -
1.105 - r = mailmime_smart_add_part(top_level_html_mime, submime);
1.106 - assert(r == MAILIMF_NO_ERROR);
1.107 - if (r == MAILIMF_ERROR_MEMORY)
1.108 - goto enomem;
1.109 - else {
1.110 - // mailmime_smart_add_part() takes ownership of submime
1.111 +
1.112 + // IF there are no inlined attachments AND mime is NULL, then
1.113 + // we just have an HTML body here and won't need to
1.114 + // process inlined attachments - submime will actually be
1.115 + // the mime root of from this function, at least.
1.116 +
1.117 + if (!top_level_html_mime) {
1.118 + mime = submime;
1.119 submime = NULL;
1.120 }
1.121 -
1.122 - bloblist_t *_a;
1.123 - for (_a = attachments; _a != NULL; _a = _a->next) {
1.124 - if (_a->disposition != PEP_CONTENT_DISP_INLINE)
1.125 - continue;
1.126 - status = mime_attachment(_a, &submime, transport_encode, false);
1.127 - if (status != PEP_STATUS_OK)
1.128 - return PEP_UNKNOWN_ERROR; // FIXME
1.129 -
1.130 + else {
1.131 r = mailmime_smart_add_part(top_level_html_mime, submime);
1.132 assert(r == MAILIMF_NO_ERROR);
1.133 - if (r == MAILIMF_ERROR_MEMORY) {
1.134 + if (r == MAILIMF_ERROR_MEMORY)
1.135 goto enomem;
1.136 - }
1.137 else {
1.138 // mailmime_smart_add_part() takes ownership of submime
1.139 submime = NULL;
1.140 }
1.141 - }
1.142 -
1.143 +
1.144 + bloblist_t *_a;
1.145 + for (_a = attachments; _a != NULL; _a = _a->next) {
1.146 + if (_a->disposition != PEP_CONTENT_DISP_INLINE)
1.147 + continue;
1.148 + status = mime_attachment(_a, &submime, transport_encode, false);
1.149 + if (status != PEP_STATUS_OK)
1.150 + return PEP_UNKNOWN_ERROR; // FIXME
1.151 +
1.152 + r = mailmime_smart_add_part(top_level_html_mime, submime);
1.153 + assert(r == MAILIMF_NO_ERROR);
1.154 + if (r == MAILIMF_ERROR_MEMORY) {
1.155 + goto enomem;
1.156 + }
1.157 + else {
1.158 + // mailmime_smart_add_part() takes ownership of submime
1.159 + submime = NULL;
1.160 + }
1.161 + }
1.162 + }
1.163 *result = mime;
1.164 return PEP_STATUS_OK;
1.165
1.166 @@ -1700,13 +1719,12 @@
1.167 int r;
1.168 PEP_STATUS status;
1.169 //char *subject;
1.170 - char *plaintext;
1.171 + const char *plaintext;
1.172 char *htmltext;
1.173
1.174 assert(msg);
1.175 assert(result);
1.176
1.177 - //subject = (msg->shortmsg) ? msg->shortmsg : "pEp"; // not used, yet.
1.178 plaintext = (msg->longmsg) ? msg->longmsg : "";
1.179 htmltext = msg->longmsg_formatted;
1.180