ENGINE-400: (NOT 402 - that was a mistake in the last couple) - ignore fws checks when not checking headers ENGINE-402
authorKrista Bennett <krista@pep-project.org>
Fri, 23 Mar 2018 00:08:43 +0100
branchENGINE-402
changeset 2581752b9b14e0bc
parent 2580 44c030927c7e
child 2582 1de69fc95e5e
ENGINE-400: (NOT 402 - that was a mistake in the last couple) - ignore fws checks when not checking headers
src/etpan_mime.c
src/etpan_mime.h
src/mime.c
     1.1 --- a/src/etpan_mime.c	Thu Mar 22 23:41:21 2018 +0100
     1.2 +++ b/src/etpan_mime.c	Fri Mar 23 00:08:43 2018 +0100
     1.3 @@ -898,10 +898,10 @@
     1.4      if (!field_value)
     1.5          return false;
     1.6          
     1.7 -    return must_chunk_be_encoded((const void*)field_value, strlen(field_value));    
     1.8 +    return must_chunk_be_encoded((const void*)field_value, strlen(field_value), false);    
     1.9  }
    1.10  
    1.11 -bool must_chunk_be_encoded(const void* value, size_t size) {
    1.12 +bool must_chunk_be_encoded(const void* value, size_t size, bool ignore_fws) {
    1.13  
    1.14      const char* begin_ptr = (const char*)value;    
    1.15  
    1.16 @@ -915,19 +915,21 @@
    1.17          // FIXME - do we need to deal with CRCRLF here?
    1.18          //         I guess in the worst case, it gets encoded, which
    1.19          //         is *supposed* to be harmless...
    1.20 -        if (cur_char == '\r') {
    1.21 -            const char* next = cur_char_ptr + 1;
    1.22 -            const char* nextnext = next + 1;
    1.23 -            if (next >= end_ptr || nextnext >= end_ptr
    1.24 -                || *next != '\n'
    1.25 -                || (*nextnext != ' ' && *nextnext != '\t')) {
    1.26 -                return true;
    1.27 -            }            
    1.28 -        }
    1.29 -        else if (cur_char == '\n') {
    1.30 -            const char* prev = cur_char_ptr - 1;
    1.31 -            if (prev == begin_ptr || *prev != '\r')
    1.32 -                return true;
    1.33 +        if (!ignore_fws) {
    1.34 +            if (cur_char == '\r') {
    1.35 +                const char* next = cur_char_ptr + 1;
    1.36 +                const char* nextnext = next + 1;
    1.37 +                if (next >= end_ptr || nextnext >= end_ptr
    1.38 +                    || *next != '\n'
    1.39 +                    || (*nextnext != ' ' && *nextnext != '\t')) {
    1.40 +                    return true;
    1.41 +                }            
    1.42 +            }
    1.43 +            else if (cur_char == '\n') {
    1.44 +                const char* prev = cur_char_ptr - 1;
    1.45 +                if (prev == begin_ptr || *prev != '\r')
    1.46 +                    return true;
    1.47 +            }
    1.48          }
    1.49          cur_char_ptr++;
    1.50      }    
     2.1 --- a/src/etpan_mime.h	Thu Mar 22 23:41:21 2018 +0100
     2.2 +++ b/src/etpan_mime.h	Fri Mar 23 00:08:43 2018 +0100
     2.3 @@ -80,7 +80,7 @@
     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 +bool must_chunk_be_encoded(const void* value, size_t size, bool ignore_fws);
     2.9  
    2.10  
    2.11  int _get_content_type(
     3.1 --- a/src/mime.c	Thu Mar 22 23:41:21 2018 +0100
     3.2 +++ b/src/mime.c	Fri Mar 23 00:08:43 2018 +0100
     3.3 @@ -138,7 +138,7 @@
     3.4      pEp_rid_list_t* resource = parse_uri(blob->filename);
     3.5  //    bool already_ascii = known_ascii_type(mime_type);
     3.6  
     3.7 -    bool already_ascii = !(must_chunk_be_encoded(blob->value, blob->size));
     3.8 +    bool already_ascii = !(must_chunk_be_encoded(blob->value, blob->size, true));
     3.9  
    3.10      mime = get_file_part(resource, mime_type, blob->value, blob->size, 
    3.11                            (already_ascii ? false : transport_encode));