Merged in fixes for ENGINE-400 and ENGINE-402
authorKrista Bennett <krista@pep-project.org>
Fri, 23 Mar 2018 01:02:53 +0100
changeset 2583170f1497ed67
parent 2577 d49c5486720c
parent 2582 1de69fc95e5e
child 2585 88d9763930cd
Merged in fixes for ENGINE-400 and ENGINE-402
     1.1 --- a/src/etpan_mime.c	Mon Mar 19 18:35:21 2018 +0100
     1.2 +++ b/src/etpan_mime.c	Fri Mar 23 01:02:53 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), false);    
    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, bool ignore_fws) {
    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 @@ -907,19 +915,21 @@
    1.28          // FIXME - do we need to deal with CRCRLF here?
    1.29          //         I guess in the worst case, it gets encoded, which
    1.30          //         is *supposed* to be harmless...
    1.31 -        if (cur_char == '\r') {
    1.32 -            const char* next = cur_char_ptr + 1;
    1.33 -            const char* nextnext = next + 1;
    1.34 -            if (next >= end_ptr || nextnext >= end_ptr
    1.35 -                || *next != '\n'
    1.36 -                || (*nextnext != ' ' && *nextnext != '\t')) {
    1.37 -                return true;
    1.38 -            }            
    1.39 -        }
    1.40 -        else if (cur_char == '\n') {
    1.41 -            const char* prev = cur_char_ptr - 1;
    1.42 -            if (prev == field_value || *prev != '\r')
    1.43 -                return true;
    1.44 +        if (!ignore_fws) {
    1.45 +            if (cur_char == '\r') {
    1.46 +                const char* next = cur_char_ptr + 1;
    1.47 +                const char* nextnext = next + 1;
    1.48 +                if (next >= end_ptr || nextnext >= end_ptr
    1.49 +                    || *next != '\n'
    1.50 +                    || (*nextnext != ' ' && *nextnext != '\t')) {
    1.51 +                    return true;
    1.52 +                }            
    1.53 +            }
    1.54 +            else if (cur_char == '\n') {
    1.55 +                const char* prev = cur_char_ptr - 1;
    1.56 +                if (prev == begin_ptr || *prev != '\r')
    1.57 +                    return true;
    1.58 +            }
    1.59          }
    1.60          cur_char_ptr++;
    1.61      }    
     2.1 --- a/src/etpan_mime.h	Mon Mar 19 18:35:21 2018 +0100
     2.2 +++ b/src/etpan_mime.h	Fri Mar 23 01:02:53 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, bool ignore_fws);
     2.8 +
     2.9  
    2.10  int _get_content_type(
    2.11          const struct mailmime_content *content,
     3.1 --- a/src/message_api.c	Mon Mar 19 18:35:21 2018 +0100
     3.2 +++ b/src/message_api.c	Fri Mar 23 01:02:53 2018 +0100
     3.3 @@ -2944,12 +2944,22 @@
     3.4      */
     3.5      
     3.6      // 1. Check to see if this message is to us and contains an own key imported 
     3.7 -    // from own trusted message 
     3.8 -    if (msg && *rating >= PEP_rating_trusted && imported_private_key_address &&
     3.9 -        msg->to && msg->to->ident && msg->to->ident->me) {
    3.10 -
    3.11 -        // flag it as such
    3.12 -        *flags |= PEP_decrypt_flag_own_private_key;
    3.13 +    // from own trusted message
    3.14 +    if (*rating >= PEP_rating_trusted && imported_private_key_address) {
    3.15 +
    3.16 +        if (msg && msg->to && msg->to->ident) {            
    3.17 +            // This will only happen rarely, so we can do this.
    3.18 +            PEP_STATUS _tmp_status = PEP_STATUS_OK;
    3.19 +            
    3.20 +            if (!is_me(session, msg->to->ident))
    3.21 +                _tmp_status = update_identity(session, msg->to->ident);
    3.22 +            
    3.23 +            if (_tmp_status == PEP_STATUS_OK && msg->to->ident->me) {
    3.24 +                // flag it as such
    3.25 +                *flags |= PEP_decrypt_flag_own_private_key;
    3.26 +            }
    3.27 +        }
    3.28 +        
    3.29      }
    3.30  
    3.31      // 2. Clean up message and prepare for return 
     4.1 --- a/src/mime.c	Mon Mar 19 18:35:21 2018 +0100
     4.2 +++ b/src/mime.c	Fri Mar 23 01:02:53 2018 +0100
     4.3 @@ -136,9 +136,12 @@
     4.4          mime_type = blob->mime_type;
     4.5  
     4.6      pEp_rid_list_t* resource = parse_uri(blob->filename);
     4.7 -    bool already_ascii = known_ascii_type(mime_type);
     4.8 +//    bool already_ascii = known_ascii_type(mime_type);
     4.9 +
    4.10 +    bool already_ascii = !(must_chunk_be_encoded(blob->value, blob->size, true));
    4.11 +
    4.12      mime = get_file_part(resource, mime_type, blob->value, blob->size, 
    4.13 -                         (already_ascii ? false : transport_encode));
    4.14 +                          (already_ascii ? false : transport_encode));
    4.15      free_rid_list(resource);
    4.16      
    4.17      assert(mime);