Fixed #198, #173: parse missing closing quote if it's not parsed as part of a word with an opening quote in a phrase

merge-experiment
Hoa V. Dinh 8 years ago
parent 2dd94c732b
commit 959f87c709

@ -1170,8 +1170,8 @@ int mailimf_atom_parse(const char * message, size_t length,
}
LIBETPAN_EXPORT
int mailimf_fws_atom_for_word_parse(const char * message, size_t length,
size_t * indx, char ** result)
static int mailimf_fws_atom_for_word_parse(const char * message, size_t length,
size_t * indx, char ** result, int * p_missing_closing_quote)
{
size_t end;
size_t cur_token;
@ -1179,9 +1179,11 @@ int mailimf_fws_atom_for_word_parse(const char * message, size_t length,
int res;
struct mailmime_encoded_word * word;
int has_fwd;
int missing_closing_quote;
char * atom;
cur_token = * indx;
missing_closing_quote = 0;
r = mailimf_fws_parse(message, length, &cur_token);
if ((r != MAILIMF_NO_ERROR) && (r != MAILIMF_ERROR_PARSE)) {
@ -1191,7 +1193,7 @@ int mailimf_fws_atom_for_word_parse(const char * message, size_t length,
end = cur_token;
r = mailmime_encoded_word_parse(message, length, &cur_token, &word, &has_fwd);
r = mailmime_encoded_word_parse(message, length, &cur_token, &word, &has_fwd, &missing_closing_quote);
if ((r != MAILIMF_NO_ERROR) && (r != MAILIMF_ERROR_PARSE)) {
res = r;
goto err;
@ -1213,6 +1215,7 @@ int mailimf_fws_atom_for_word_parse(const char * message, size_t length,
* result = atom;
* indx = cur_token;
* p_missing_closing_quote = missing_closing_quote;
return MAILIMF_NO_ERROR;
@ -1591,15 +1594,17 @@ int mailimf_word_parse(const char * message, size_t length,
LIBETPAN_EXPORT
int mailimf_fws_word_parse(const char * message, size_t length,
size_t * indx, char ** result)
size_t * indx, char ** result, int * p_missing_closing_quote)
{
size_t cur_token;
char * word;
int r;
int missing_closing_quote;
cur_token = * indx;
missing_closing_quote = 0;
r = mailimf_fws_atom_for_word_parse(message, length, &cur_token, &word);
r = mailimf_fws_atom_for_word_parse(message, length, &cur_token, &word, &missing_closing_quote);
if (r == MAILIMF_ERROR_PARSE)
r = mailimf_fws_quoted_string_parse(message, length, &cur_token, &word);
@ -1609,6 +1614,7 @@ int mailimf_fws_word_parse(const char * message, size_t length,
* result = word;
* indx = cur_token;
* p_missing_closing_quote = missing_closing_quote;
return MAILIMF_NO_ERROR;
}
@ -1627,8 +1633,10 @@ static int mailimf_phrase_parse(const char * message, size_t length,
int r;
int res;
char * str;
int has_missing_closing_quote;
cur_token = * indx;
has_missing_closing_quote = 0;
gphrase = mmap_string_new("");
if (gphrase == NULL) {
@ -1639,7 +1647,11 @@ static int mailimf_phrase_parse(const char * message, size_t length,
first = TRUE;
while (1) {
r = mailimf_fws_word_parse(message, length, &cur_token, &word);
int missing_quote = 0;
r = mailimf_fws_word_parse(message, length, &cur_token, &word, &missing_quote);
if (missing_quote) {
has_missing_closing_quote = 1;
}
if (r == MAILIMF_NO_ERROR) {
if (!first) {
if (mmap_string_append_c(gphrase, ' ') == NULL) {
@ -1669,6 +1681,10 @@ static int mailimf_phrase_parse(const char * message, size_t length,
goto free;
}
if (has_missing_closing_quote) {
r = mailimf_char_parse(message, length, &cur_token, '\"');
}
str = strdup(gphrase->str);
if (str == NULL) {
res = MAILIMF_ERROR_MEMORY;

@ -348,7 +348,7 @@ int mailimf_fws_atom_parse(const char * message, size_t length,
LIBETPAN_EXPORT
int mailimf_fws_word_parse(const char * message, size_t length,
size_t * indx, char ** result);
size_t * indx, char ** result, int * p_missing_closing_quote);
LIBETPAN_EXPORT
int mailimf_fws_quoted_string_parse(const char * message, size_t length,

@ -110,6 +110,7 @@ int mailmime_encoded_phrase_parse(const char * default_fromcode,
char * str;
char * wordutf8;
int type;
int missing_closing_quote;
cur_token = * indx;
@ -127,7 +128,7 @@ int mailmime_encoded_phrase_parse(const char * default_fromcode,
int has_fwd;
word = NULL;
r = mailmime_encoded_word_parse(message, length, &cur_token, &word, &has_fwd);
r = mailmime_encoded_word_parse(message, length, &cur_token, &word, &has_fwd, &missing_closing_quote);
if (r == MAILIMF_NO_ERROR) {
if ((!first) && has_fwd) {
if (type != TYPE_ENCODED_WORD) {
@ -366,7 +367,7 @@ mailmime_non_encoded_word_parse(const char * message, size_t length,
int mailmime_encoded_word_parse(const char * message, size_t length,
size_t * indx,
struct mailmime_encoded_word ** result,
int * p_has_fwd)
int * p_has_fwd, int * p_missing_closing_quote)
{
size_t cur_token;
char * charset;
@ -381,9 +382,11 @@ int mailmime_encoded_word_parse(const char * message, size_t length,
int opening_quote;
int end;
int has_fwd;
int missing_closing_quote;
cur_token = * indx;
missing_closing_quote = 0;
has_fwd = 0;
r = mailimf_fws_parse(message, length, &cur_token);
if (r == MAILIMF_NO_ERROR) {
@ -509,6 +512,9 @@ int mailmime_encoded_word_parse(const char * message, size_t length,
goto free_encoded_text;
}
#endif
if (r == MAILIMF_ERROR_PARSE) {
missing_closing_quote = 1;
}
}
/* fix charset */
@ -525,6 +531,7 @@ int mailmime_encoded_word_parse(const char * message, size_t length,
* result = ew;
* indx = cur_token;
* p_has_fwd = has_fwd;
* p_missing_closing_quote = missing_closing_quote;
return MAILIMF_NO_ERROR;

@ -53,7 +53,7 @@ int
mailmime_encoded_word_parse(const char * message, size_t length,
size_t * indx,
struct mailmime_encoded_word ** result,
int * p_has_fwd);
int * p_has_fwd, int * p_missing_closing_quote);
#ifdef __cplusplus
}

Loading…
Cancel
Save