Merged in default w/ ENGINE-298 in it test_diphoton
authorKrista Bennett <krista@pep-project.org>
Wed, 25 Oct 2017 11:17:36 +0200
branchtest_diphoton
changeset 2202b9c91491949f
parent 2199 6a4251cbe3b2
parent 2201 24b1ef4ba5fe
child 2205 1cb06c1241bd
Merged in default w/ ENGINE-298 in it
src/message_api.c
     1.1 --- a/src/etpan_mime.c	Tue Oct 24 15:36:54 2017 +0200
     1.2 +++ b/src/etpan_mime.c	Wed Oct 25 11:17:36 2017 +0200
     1.3 @@ -284,7 +284,8 @@
     1.4          pEp_rid_list_t* resource,
     1.5          const char * mime_type,
     1.6          char * data,
     1.7 -        size_t length
     1.8 +        size_t length,
     1.9 +        bool transport_encode
    1.10      )
    1.11  {
    1.12      char * disposition_name = NULL;
    1.13 @@ -330,10 +331,14 @@
    1.14      if (content == NULL)
    1.15          goto enomem;
    1.16  
    1.17 -    encoding_type = MAILMIME_MECHANISM_BASE64;
    1.18 -    encoding = mailmime_mechanism_new(encoding_type, NULL);
    1.19 -    if (encoding == NULL)
    1.20 -        goto enomem;
    1.21 +    encoding = NULL;
    1.22 +
    1.23 +    if (transport_encode) {
    1.24 +        encoding_type = MAILMIME_MECHANISM_BASE64;
    1.25 +        encoding = mailmime_mechanism_new(encoding_type, NULL);
    1.26 +        if (encoding == NULL)
    1.27 +            goto enomem;
    1.28 +    }
    1.29  
    1.30      mime_fields = mailmime_fields_new_with_data(encoding, content_id, NULL,
    1.31              disposition, NULL);
     2.1 --- a/src/etpan_mime.h	Tue Oct 24 15:36:54 2017 +0200
     2.2 +++ b/src/etpan_mime.h	Wed Oct 25 11:17:36 2017 +0200
     2.3 @@ -29,7 +29,8 @@
     2.4          pEp_rid_list_t* resource,
     2.5          const char * mime_type,
     2.6          char * data,
     2.7 -        size_t length
     2.8 +        size_t length,
     2.9 +        bool transport_encode
    2.10      );
    2.11  
    2.12  struct mailmime * part_multiple_new(const char *type);
     3.1 --- a/src/message_api.c	Tue Oct 24 15:36:54 2017 +0200
     3.2 +++ b/src/message_api.c	Wed Oct 25 11:17:36 2017 +0200
     3.3 @@ -797,7 +797,7 @@
     3.4      }
     3.5              
     3.6      /* Turn message into a MIME-blob */
     3.7 -    status = mime_encode_message(attachment, false, &message_text);
     3.8 +    status = _mime_encode_message_internal(attachment, false, &message_text, false);
     3.9          
    3.10      if (status != PEP_STATUS_OK)
    3.11          goto enomem;
    3.12 @@ -848,7 +848,7 @@
    3.13      _src->longmsg_formatted = src->longmsg_formatted;
    3.14      _src->attachments = src->attachments;
    3.15      _src->enc_format = PEP_enc_none;
    3.16 -    status = mime_encode_message(_src, true, &mimetext);
    3.17 +    status = _mime_encode_message_internal(_src, true, &mimetext, false);
    3.18      assert(status == PEP_STATUS_OK);
    3.19      if (status != PEP_STATUS_OK)
    3.20          goto pep_error;
    3.21 @@ -3056,7 +3056,7 @@
    3.22      }
    3.23  
    3.24      dec_msg->enc_format = PEP_enc_none; // is this the right thing to do? FIXME
    3.25 -    status = mime_encode_message(dec_msg, false, mime_plaintext);
    3.26 +    status = _mime_encode_message_internal(dec_msg, false, mime_plaintext, false);
    3.27  
    3.28      if (status == PEP_STATUS_OK)
    3.29      {
     4.1 --- a/src/mime.c	Tue Oct 24 15:36:54 2017 +0200
     4.2 +++ b/src/mime.c	Wed Oct 25 11:17:36 2017 +0200
     4.3 @@ -100,7 +100,8 @@
     4.4  
     4.5  static PEP_STATUS mime_attachment(
     4.6          bloblist_t *blob,
     4.7 -        struct mailmime **result
     4.8 +        struct mailmime **result,
     4.9 +        bool transport_encode
    4.10      )
    4.11  {
    4.12      PEP_STATUS status = PEP_STATUS_OK;
    4.13 @@ -121,7 +122,7 @@
    4.14          mime_type = blob->mime_type;
    4.15  
    4.16      pEp_rid_list_t* resource = parse_uri(blob->filename);
    4.17 -    mime = get_file_part(resource, mime_type, blob->value, blob->size);
    4.18 +    mime = get_file_part(resource, mime_type, blob->value, blob->size, transport_encode);
    4.19      free_rid_list(resource);
    4.20      
    4.21      assert(mime);
    4.22 @@ -144,7 +145,8 @@
    4.23          const char *plaintext,
    4.24          const char *htmltext,
    4.25          bloblist_t *attachments,
    4.26 -        struct mailmime **result
    4.27 +        struct mailmime **result,
    4.28 +        bool transport_encode
    4.29      )
    4.30  {
    4.31      PEP_STATUS status = PEP_STATUS_OK;
    4.32 @@ -166,8 +168,9 @@
    4.33  
    4.34      pEp_rid_list_t* resource = new_rid_node(PEP_RID_FILENAME, "msg.txt");
    4.35      
    4.36 +    int encoding_type = (transport_encode ? MAILMIME_MECHANISM_QUOTED_PRINTABLE : 0);
    4.37      submime = get_text_part(NULL, "text/plain", plaintext, strlen(plaintext),
    4.38 -            MAILMIME_MECHANISM_QUOTED_PRINTABLE);
    4.39 +            encoding_type);
    4.40      free_rid_list(resource);
    4.41      resource = NULL;
    4.42      
    4.43 @@ -222,7 +225,7 @@
    4.44  
    4.45  //    resource = new_rid_node(PEP_RID_FILENAME, "msg.html");
    4.46      submime = get_text_part(NULL, "text/html", htmltext, strlen(htmltext),
    4.47 -            MAILMIME_MECHANISM_QUOTED_PRINTABLE);
    4.48 +            encoding_type);
    4.49      free_rid_list(resource);
    4.50      resource = NULL;
    4.51      
    4.52 @@ -243,7 +246,7 @@
    4.53      for (_a = attachments; _a != NULL; _a = _a->next) {
    4.54          if (_a->disposition != PEP_CONTENT_DISP_INLINE)
    4.55              continue;
    4.56 -        status = mime_attachment(_a, &submime);
    4.57 +        status = mime_attachment(_a, &submime, transport_encode);
    4.58          if (status != PEP_STATUS_OK)
    4.59              return PEP_UNKNOWN_ERROR; // FIXME
    4.60  
    4.61 @@ -273,6 +276,8 @@
    4.62      return status;
    4.63  }
    4.64  
    4.65 +
    4.66 +// FIXME: maybe need to add transport_encode field here
    4.67  static struct mailimf_mailbox * identity_to_mailbox(const pEp_identity *ident)
    4.68  {
    4.69      char *_username = NULL;
    4.70 @@ -384,7 +389,7 @@
    4.71      return NULL;
    4.72  }
    4.73  
    4.74 -static clist * stringlist_to_clist(stringlist_t *sl)
    4.75 +static clist * stringlist_to_clist(stringlist_t *sl, bool transport_encode)
    4.76  {
    4.77      clist * cl = clist_new();
    4.78      assert(cl);
    4.79 @@ -397,7 +402,9 @@
    4.80      stringlist_t *_sl;
    4.81      for (_sl = sl; _sl; _sl = _sl->next) {
    4.82          int r;
    4.83 -        char * value = mailmime_encode_subject_header("utf-8", _sl->value, 0);
    4.84 +        char * value = (transport_encode ?
    4.85 +                        mailmime_encode_subject_header("utf-8", _sl->value, 0) :
    4.86 +                        strdup(_sl->value));
    4.87          assert(value);
    4.88          if (value == NULL) {
    4.89              clist_free(cl);
    4.90 @@ -415,7 +422,8 @@
    4.91      return cl;
    4.92  }
    4.93  
    4.94 -static PEP_STATUS build_fields(const message *msg, struct mailimf_fields **result)
    4.95 +static PEP_STATUS build_fields(const message *msg, struct mailimf_fields **result,
    4.96 +                               bool transport_encode)
    4.97  {
    4.98      PEP_STATUS status = PEP_STATUS_OK;
    4.99      struct mailimf_fields * fields = NULL;
   4.100 @@ -490,7 +498,9 @@
   4.101      }
   4.102  
   4.103      /* if (subject) */ {
   4.104 -        char *_subject = mailmime_encode_subject_header("utf-8", subject, 1);
   4.105 +        char *_subject = (transport_encode ? 
   4.106 +                          mailmime_encode_subject_header("utf-8", subject, 1) :
   4.107 +                          strdup(subject));
   4.108          if (_subject == NULL)
   4.109              goto enomem;
   4.110  
   4.111 @@ -542,7 +552,7 @@
   4.112      }
   4.113  
   4.114      if (msg->in_reply_to) {
   4.115 -        clist *in_reply_to = stringlist_to_clist(msg->in_reply_to);
   4.116 +        clist *in_reply_to = stringlist_to_clist(msg->in_reply_to, transport_encode);
   4.117          if (in_reply_to == NULL)
   4.118              goto enomem;
   4.119  
   4.120 @@ -555,7 +565,7 @@
   4.121      }
   4.122  
   4.123      if (msg->references) {
   4.124 -        clist *references = stringlist_to_clist(msg->references);
   4.125 +        clist *references = stringlist_to_clist(msg->references, transport_encode);
   4.126          if (references == NULL)
   4.127              goto enomem;
   4.128  
   4.129 @@ -568,7 +578,7 @@
   4.130      }
   4.131  
   4.132      if (msg->keywords) {
   4.133 -        clist *keywords = stringlist_to_clist(msg->keywords);
   4.134 +        clist *keywords = stringlist_to_clist(msg->keywords, transport_encode);
   4.135          if (keywords == NULL)
   4.136              goto enomem;
   4.137  
   4.138 @@ -581,8 +591,9 @@
   4.139      }
   4.140  
   4.141      if (msg->comments) {
   4.142 -        char *comments = mailmime_encode_subject_header("utf-8", msg->comments,
   4.143 -                0);
   4.144 +        char *comments = (transport_encode ?
   4.145 +                          mailmime_encode_subject_header("utf-8", msg->comments, 0) :
   4.146 +                          strdup(msg->comments));
   4.147          if (comments == NULL)
   4.148              goto enomem;
   4.149  
   4.150 @@ -600,7 +611,9 @@
   4.151              char *key = _l->value->key;
   4.152              char *value = _l->value->value;
   4.153              if (key && value) {
   4.154 -                char *_value = mailmime_encode_subject_header("utf-8", value, 0);
   4.155 +                char *_value = (transport_encode ?
   4.156 +                                mailmime_encode_subject_header("utf-8", value, 0) :
   4.157 +                                strdup(value));
   4.158                  if (_value == NULL)
   4.159                      goto enomem;
   4.160  
   4.161 @@ -698,7 +711,8 @@
   4.162  static PEP_STATUS mime_encode_message_plain(
   4.163          const message *msg,
   4.164          bool omit_fields,
   4.165 -        struct mailmime **result
   4.166 +        struct mailmime **result,
   4.167 +        bool transport_encode
   4.168      )
   4.169  {
   4.170      struct mailmime * mime = NULL;
   4.171 @@ -720,7 +734,8 @@
   4.172          /* first, we need to strip out the inlined attachments to ensure this
   4.173             gets set up correctly */
   4.174             
   4.175 -        status = mime_html_text(plaintext, htmltext, msg->attachments, &mime);
   4.176 +        status = mime_html_text(plaintext, htmltext, msg->attachments, &mime,
   4.177 +                                transport_encode);
   4.178                  
   4.179          if (status != PEP_STATUS_OK)
   4.180              goto pep_error;
   4.181 @@ -729,13 +744,15 @@
   4.182          pEp_rid_list_t* resource = NULL;
   4.183          if (is_PGP_message_text(plaintext)) {
   4.184              resource = new_rid_node(PEP_RID_FILENAME, "msg.asc");
   4.185 +            int encoding_type = (transport_encode ? MAILMIME_MECHANISM_7BIT : 0);
   4.186              mime = get_text_part(resource, "application/octet-stream", plaintext,
   4.187 -                    strlen(plaintext), MAILMIME_MECHANISM_7BIT);
   4.188 +                    strlen(plaintext), encoding_type);
   4.189          }
   4.190          else {
   4.191              resource = new_rid_node(PEP_RID_FILENAME, "msg.txt");
   4.192 +            int encoding_type = (transport_encode ? MAILMIME_MECHANISM_QUOTED_PRINTABLE : 0);
   4.193              mime = get_text_part(resource, "text/plain", plaintext, strlen(plaintext),
   4.194 -                    MAILMIME_MECHANISM_QUOTED_PRINTABLE);
   4.195 +                    encoding_type);
   4.196          }
   4.197          free_rid_list(resource);
   4.198          
   4.199 @@ -779,7 +796,7 @@
   4.200              if (_a->disposition == PEP_CONTENT_DISP_INLINE)
   4.201                  continue;
   4.202  
   4.203 -            status = mime_attachment(_a, &submime);
   4.204 +            status = mime_attachment(_a, &submime, transport_encode);
   4.205              if (status != PEP_STATUS_OK)
   4.206                  goto pep_error;
   4.207  
   4.208 @@ -895,6 +912,16 @@
   4.209          char **mimetext
   4.210      )
   4.211  {
   4.212 +    return _mime_encode_message_internal(msg, omit_fields, mimetext, true);
   4.213 +}
   4.214 +
   4.215 +PEP_STATUS _mime_encode_message_internal(
   4.216 +        const message * msg,
   4.217 +        bool omit_fields,
   4.218 +        char **mimetext,
   4.219 +        bool transport_encode
   4.220 +    )
   4.221 +{
   4.222      PEP_STATUS status = PEP_STATUS_OK;
   4.223      struct mailmime * msg_mime = NULL;
   4.224      struct mailmime * mime = NULL;
   4.225 @@ -912,11 +939,11 @@
   4.226  
   4.227      switch (msg->enc_format) {
   4.228          case PEP_enc_none:
   4.229 -            status = mime_encode_message_plain(msg, omit_fields, &mime);
   4.230 +            status = mime_encode_message_plain(msg, omit_fields, &mime, transport_encode);
   4.231              break;
   4.232  
   4.233          case PEP_enc_pieces:
   4.234 -            status = mime_encode_message_plain(msg, omit_fields, &mime);
   4.235 +            status = mime_encode_message_plain(msg, omit_fields, &mime, transport_encode);
   4.236              break;
   4.237  
   4.238          case PEP_enc_S_MIME:
   4.239 @@ -949,7 +976,7 @@
   4.240      mime = NULL;
   4.241  
   4.242      if (!omit_fields) {
   4.243 -        status = build_fields(msg, &fields);
   4.244 +        status = build_fields(msg, &fields, transport_encode);
   4.245          if (status != PEP_STATUS_OK)
   4.246              goto pep_error;
   4.247  
     5.1 --- a/src/mime.h	Tue Oct 24 15:36:54 2017 +0200
     5.2 +++ b/src/mime.h	Wed Oct 25 11:17:36 2017 +0200
     5.3 @@ -78,6 +78,15 @@
     5.4          message **msg
     5.5      );
     5.6  
     5.7 +/* sometimes we don't want to transport encode */
     5.8 +PEP_STATUS _mime_encode_message_internal(
     5.9 +        const message * msg,
    5.10 +        bool omit_fields,
    5.11 +        char **mimetext,
    5.12 +        bool transport_encode
    5.13 +    );
    5.14 +
    5.15 +
    5.16  #ifdef __cplusplus
    5.17  }
    5.18  #endif