Commit 1a771a60 1a771a60bf194a84f8e2df404a768ea71623fbf9 by Sergey Poznyakoff

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.
1 parent 5157bbc9
......@@ -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;
......