diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-04-26 22:48:29 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-04-26 23:10:33 +0300 |
commit | 1a771a60bf194a84f8e2df404a768ea71623fbf9 (patch) | |
tree | 20b4bdd9a84a1456cf3ca3acb185c85fef646be4 | |
parent | 5157bbc99fc7cd3c0ea904f70ab2ee1f595ac8fe (diff) | |
download | mailutils-1a771a60bf194a84f8e2df404a768ea71623fbf9.tar.gz mailutils-1a771a60bf194a84f8e2df404a768ea71623fbf9.tar.bz2 |
Accept additional whitespace and quotes in the disposition part of MIME headers.
* mailbox/mimehdr.c (disp_segment_len): New function.
(mu_mimehdr_get_disp, mu_mimehdr_aget_disp): Use disp_segment_len.
Unquote the returned string.
(_header_get_param): Allow for whitespace before '"'. Unquote the
string before comparison.
-rw-r--r-- | mailbox/mimehdr.c | 57 |
1 files changed, 45 insertions, 12 deletions
diff --git a/mailbox/mimehdr.c b/mailbox/mimehdr.c index 4c273587d..3391868d1 100644 --- a/mailbox/mimehdr.c +++ b/mailbox/mimehdr.c @@ -100,6 +100,7 @@ _header_get_param (const char *field_body, int res = MU_ERR_NOENT; /* Return value, pessimistic default */ size_t param_len = strlen (param); char *p; + size_t size; char *mem = NULL; /* Allocated memory storage */ size_t retlen = 0; /* Total number of bytes copied */ unsigned long cind = 0; /* Expected continued parameter index. @@ -116,7 +117,18 @@ _header_get_param (const char *field_body, p = strchr (field_body, ';'); if (!p) return MU_ERR_NOENT; - if (disp && mu_c_strncasecmp (field_body, disp, p - field_body)) + /* Allow for possible whitespace before the semicolon */ + for (size = p - field_body; + size > 0 && mu_isblank (field_body[size-1]); size--) + ; + /* Remove surrounding quotes. + FIXME: unescape the quoted contents. */ + if (field_body[0] == '"' && field_body[size-1] == '"') + { + field_body++; + size -= 2; + } + if (disp && mu_c_strncasecmp (field_body, disp, size)) return MU_ERR_NOENT; while (p && *p) @@ -326,6 +338,21 @@ _header_get_param (const char *field_body, return res; } +static size_t +disp_segment_len (const char *str) +{ + char *p = strchr (str, ';'); + size_t size; + + if (!p) + size = strlen (str); + else + size = p - str; + while (size > 0 && mu_isblank (str[size-1])) + size--; + return size; +} + /* STR is a value of a structured MIME header, e.g. Content-Type. This function returns the `disposition part' of it. In other words, it returns disposition, if STR is a Content-Disposition @@ -334,13 +361,15 @@ _header_get_param (const char *field_body, int mu_mimehdr_get_disp (const char *str, char *buf, size_t bufsz, size_t *retsz) { - char *p = strchr (str, ';'); size_t size; - - if (!p) - size = strlen (str); - else - size = p - str; + + str = mu_str_skip_class (str, MU_CTYPE_BLANK); + size = disp_segment_len (str); + if (size > 2 && str[0] == '"' && str[size-1] == '"') + { + str++; + size -= 2; + } if (buf) size = mu_cpystr (buf, str, size); if (retsz) @@ -352,13 +381,17 @@ mu_mimehdr_get_disp (const char *str, char *buf, size_t bufsz, size_t *retsz) int mu_mimehdr_aget_disp (const char *str, char **pvalue) { - char *p = strchr (str, ';'); + char *p; size_t size; - if (!p) - size = strlen (str); - else - size = p - str; + str = mu_str_skip_class (str, MU_CTYPE_BLANK); + size = disp_segment_len (str); + if (size > 2 && str[0] == '"' && str[size-1] == '"') + { + str++; + size -= 2; + } + p = malloc (size + 1); if (!p) return ENOMEM; |