ENGINE-92: #comment the real bug (if this behaviour is allowed) is in libetpan, but we now check for whitespace strings if MAILIMF_PARSE_ERROR is the return value from mailmime_encoded_phrase_parse ENGINE-92
authorKrista Grothoff <krista@pep-project.org>
Fri, 09 Sep 2016 17:07:01 +0200
branchENGINE-92
changeset 11741069203104ea
parent 1153 eaf7b2eeea87
ENGINE-92: #comment the real bug (if this behaviour is allowed) is in libetpan, but we now check for whitespace strings if MAILIMF_PARSE_ERROR is the return value from mailmime_encoded_phrase_parse
src/mime.c
     1.1 --- a/src/mime.c	Fri Sep 09 13:07:59 2016 +0200
     1.2 +++ b/src/mime.c	Fri Sep 09 17:07:01 2016 +0200
     1.3 @@ -5,6 +5,7 @@
     1.4  #include <stdlib.h>
     1.5  #include <assert.h>
     1.6  #include <errno.h>
     1.7 +#include <ctype.h>
     1.8  
     1.9  #include "etpan_mime.h"
    1.10  #include "wrappers.h"
    1.11 @@ -1111,10 +1112,33 @@
    1.12                      char *_value;
    1.13  
    1.14                      index = 0;
    1.15 +
    1.16                      r = mailmime_encoded_phrase_parse("utf-8", value,
    1.17                              strlen(value), &index, "utf-8", &_value);
    1.18 -                    if (r)
    1.19 -                        goto enomem;
    1.20 +                    
    1.21 +                    
    1.22 +                    // Check result, and if there was no parsing error (or
    1.23 +                    // there was one, but because of an empty string), move
    1.24 +                    // on.
    1.25 +                    bool non_space = false;
    1.26 +                    char* currchar = value;
    1.27 +                            
    1.28 +                    switch (r) {
    1.29 +                        case MAILIMF_NO_ERROR:
    1.30 +                            break;
    1.31 +                        case MAILIMF_ERROR_PARSE:
    1.32 +                            while (*currchar) {
    1.33 +                                if (isspace(*(currchar++)))
    1.34 +                                    continue;
    1.35 +                                non_space = true;
    1.36 +                                break;
    1.37 +                            }
    1.38 +                            if (!non_space)
    1.39 +                                break;
    1.40 +                        default:
    1.41 +                            goto enomem;
    1.42 +
    1.43 +                    }
    1.44  
    1.45                      stringpair_t *pair = new_stringpair(name, _value);
    1.46                      if (pair == NULL)