Commit 4d767fac 4d767fac3cec78beb790fa6336c9f1d69e3aa91c by Alain Magloire

Patch from Sam Roberts.

1 parent f2160616
2001-05-27 Sam Roberts
* mailbox/address.c: removed unfolding of lines at a NL before parsing.
* mailbox/parse822.c: consider LF and CRLF equivalent for purposes
of unfolding lines.
2001-05-23 Alain Magloire
* mailbox/mbx_default.c (mailbox_create_default): Check
......
......@@ -38,55 +38,12 @@ address_create (address_t *a, const char *s)
/* 'paddress' must exist, and can't already have been initialized
*/
int status;
const char *e;
const char *save;
char *fb;
if (!a)
return EINVAL;
*a = NULL;
save = s;
e = &s[strlen (s)];
fb = calloc (1, 1);
if (!fb)
return ENOMEM;
/* We need to unfold the string. Do the same thing as parse822_field_body()
but we have to be more flexible in allowing bare '\n' as CRLF for
unix-mbox. This is may not be the right approach still. */
for (;;)
{
const char *eol = s;
size_t len = strlen (fb);
while (eol != e)
{
/* if (eol[0] == '\r' && (eol+1) != e && eol[1] == '\n') */
if (*eol == '\n')
break;
++eol;
}
fb = realloc (fb, len + (eol - s) + 1);
memcpy (fb + len , s, eol - s);
fb[len + (eol - s)] = '\0';
s = eol;
if (eol == e)
break; /* no more, so we're done */
s++;
if (s == e)
break; /* no more, so we're done */
/* check if next line is a continuation line */
if (*s != ' ' && *s != '\t')
break;
}
status = parse822_address_list (a, (char*) fb);
free (fb);
status = parse822_address_list (a, (char*) s);
if (status == 0)
{
/* And address-list may contain 0 addresses but parse correctly.
......@@ -94,7 +51,7 @@ address_create (address_t *a, const char *s)
if (!*a)
return ENOENT;
(*a)->addr = strdup (save);
(*a)->addr = strdup (s);
if (!(*a)->addr)
{
address_destroy (a);
......
......@@ -211,9 +211,13 @@ int parse822_is_smtp_q(char c)
/***** From RFC 822, 3.3 Lexical Tokens *****/
int parse822_skip_crlf(const char** p, const char* e)
int parse822_skip_nl(const char** p, const char* e)
{
/* Here we consider a new-line (NL) to be either a bare LF, or
* a CRLF pair as required by the RFC.
*/
const char* s = *p;
if(
(&s[1] < e) &&
s[0] == '\r' &&
......@@ -224,6 +228,17 @@ int parse822_skip_crlf(const char** p, const char* e)
return EOK;
}
if(
(&s[0] < e) &&
s[0] == '\n'
)
{
*p += 1;
return EOK;
}
return EPARSE;
}
int parse822_skip_lwsp_char(const char** p, const char* e)
......@@ -237,7 +252,12 @@ int parse822_skip_lwsp_char(const char** p, const char* e)
int parse822_skip_lwsp(const char** p, const char* e)
{
/*
* linear-white-space = 1*([CRLF] LWSP-char)
* linear-white-space = 1*([[CR]LF] LWSP-char)
*
* We interpret a bare LF as identical to the canonical CRLF
* line ending, I don't know another way since on a Unix system
* all CRLF will be translated to the local convention, a bare
* LF, and thus we can not deal with bare NLs in the message.
*/
int space = 0;
......@@ -248,7 +268,7 @@ int parse822_skip_lwsp(const char** p, const char* e)
space = 1;
continue;
}
if(parse822_skip_crlf(p, e) == EOK) {
if(parse822_skip_nl(p, e) == EOK) {
if(parse822_skip_lwsp_char(p, e) == EOK) {
continue;
}
......