Check attachments on encoding for non-ASCII characters ENGINE-402
authorKrista Bennett <krista@pep-project.org>
Thu, 22 Mar 2018 23:32:01 +0100
branchENGINE-402
changeset 2579cc878b3193a6
parent 2577 d49c5486720c
child 2580 44c030927c7e
Check attachments on encoding for non-ASCII characters
src/etpan_mime.c
src/etpan_mime.h
src/mime.c
     1.1 --- a/src/etpan_mime.c	Mon Mar 19 18:35:21 2018 +0100
     1.2 +++ b/src/etpan_mime.c	Thu Mar 22 23:32:01 2018 +0100
     1.3 @@ -895,11 +895,19 @@
     1.4  // (See rfc2822, section 2.2.3 - libetpan's handling isn't quite what
     1.5  // we need here.)
     1.6  bool must_field_value_be_encoded(const char* field_value) {
     1.7 -    
     1.8 -    int val_len = strlen(field_value);
     1.9 -    const char* end_ptr = field_value + val_len;
    1.10 +    if (!field_value)
    1.11 +        return false;
    1.12 +        
    1.13 +    return must_chunk_be_encoded((const void*)field_value, strlen(field_value));    
    1.14 +}
    1.15  
    1.16 -    const char* cur_char_ptr = field_value;
    1.17 +bool must_chunk_be_encoded(const void* value, size_t size) {
    1.18 +
    1.19 +    const char* begin_ptr = (const char*)value;    
    1.20 +
    1.21 +    const char* end_ptr = begin_ptr + size;
    1.22 +
    1.23 +    const char* cur_char_ptr = begin_ptr;
    1.24      while (cur_char_ptr < end_ptr) {
    1.25          char cur_char = *cur_char_ptr;
    1.26          if (cur_char > 127 || cur_char < 0)
    1.27 @@ -918,7 +926,7 @@
    1.28          }
    1.29          else if (cur_char == '\n') {
    1.30              const char* prev = cur_char_ptr - 1;
    1.31 -            if (prev == field_value || *prev != '\r')
    1.32 +            if (prev == begin_ptr || *prev != '\r')
    1.33                  return true;
    1.34          }
    1.35          cur_char_ptr++;
     2.1 --- a/src/etpan_mime.h	Mon Mar 19 18:35:21 2018 +0100
     2.2 +++ b/src/etpan_mime.h	Thu Mar 22 23:32:01 2018 +0100
     2.3 @@ -80,6 +80,8 @@
     2.4  bool _is_PGP_MIME(struct mailmime_content *content);
     2.5  bool _is_text_part(struct mailmime_content *content, const char *subtype);
     2.6  bool must_field_value_be_encoded(const char* field_value);
     2.7 +bool must_chunk_be_encoded(const void* value, size_t size);
     2.8 +
     2.9  
    2.10  int _get_content_type(
    2.11          const struct mailmime_content *content,
     3.1 --- a/src/mime.c	Mon Mar 19 18:35:21 2018 +0100
     3.2 +++ b/src/mime.c	Thu Mar 22 23:32:01 2018 +0100
     3.3 @@ -136,7 +136,10 @@
     3.4          mime_type = blob->mime_type;
     3.5  
     3.6      pEp_rid_list_t* resource = parse_uri(blob->filename);
     3.7 -    bool already_ascii = known_ascii_type(mime_type);
     3.8 +//    bool already_ascii = known_ascii_type(mime_type);
     3.9 +
    3.10 +    bool already_ascii = must_chunk_be_encoded(blob->value, blob->size);
    3.11 +
    3.12      mime = get_file_part(resource, mime_type, blob->value, blob->size, 
    3.13                           (already_ascii ? false : transport_encode));
    3.14      free_rid_list(resource);