Commit 4d767fac 4d767fac3cec78beb790fa6336c9f1d69e3aa91c by Alain Magloire

Patch from Sam Roberts.

1 parent f2160616
1 2001-05-27 Sam Roberts
2 * mailbox/address.c: removed unfolding of lines at a NL before parsing.
3 * mailbox/parse822.c: consider LF and CRLF equivalent for purposes
4 of unfolding lines.
5
1 2001-05-23 Alain Magloire 6 2001-05-23 Alain Magloire
2 7
3 * mailbox/mbx_default.c (mailbox_create_default): Check 8 * mailbox/mbx_default.c (mailbox_create_default): Check
......
...@@ -38,55 +38,12 @@ address_create (address_t *a, const char *s) ...@@ -38,55 +38,12 @@ address_create (address_t *a, const char *s)
38 /* 'paddress' must exist, and can't already have been initialized 38 /* 'paddress' must exist, and can't already have been initialized
39 */ 39 */
40 int status; 40 int status;
41 const char *e;
42 const char *save;
43 char *fb;
44 41
45 if (!a) 42 if (!a)
46 return EINVAL; 43 return EINVAL;
47 44
48 *a = NULL; 45 *a = NULL;
49 save = s; 46 status = parse822_address_list (a, (char*) s);
50 e = &s[strlen (s)];
51 fb = calloc (1, 1);
52 if (!fb)
53 return ENOMEM;
54
55 /* We need to unfold the string. Do the same thing as parse822_field_body()
56 but we have to be more flexible in allowing bare '\n' as CRLF for
57 unix-mbox. This is may not be the right approach still. */
58 for (;;)
59 {
60 const char *eol = s;
61 size_t len = strlen (fb);
62 while (eol != e)
63 {
64 /* if (eol[0] == '\r' && (eol+1) != e && eol[1] == '\n') */
65 if (*eol == '\n')
66 break;
67 ++eol;
68 }
69
70 fb = realloc (fb, len + (eol - s) + 1);
71 memcpy (fb + len , s, eol - s);
72 fb[len + (eol - s)] = '\0';
73
74 s = eol;
75 if (eol == e)
76 break; /* no more, so we're done */
77
78 s++;
79
80 if (s == e)
81 break; /* no more, so we're done */
82
83 /* check if next line is a continuation line */
84 if (*s != ' ' && *s != '\t')
85 break;
86 }
87
88 status = parse822_address_list (a, (char*) fb);
89 free (fb);
90 if (status == 0) 47 if (status == 0)
91 { 48 {
92 /* And address-list may contain 0 addresses but parse correctly. 49 /* And address-list may contain 0 addresses but parse correctly.
...@@ -94,7 +51,7 @@ address_create (address_t *a, const char *s) ...@@ -94,7 +51,7 @@ address_create (address_t *a, const char *s)
94 if (!*a) 51 if (!*a)
95 return ENOENT; 52 return ENOENT;
96 53
97 (*a)->addr = strdup (save); 54 (*a)->addr = strdup (s);
98 if (!(*a)->addr) 55 if (!(*a)->addr)
99 { 56 {
100 address_destroy (a); 57 address_destroy (a);
......
...@@ -211,9 +211,13 @@ int parse822_is_smtp_q(char c) ...@@ -211,9 +211,13 @@ int parse822_is_smtp_q(char c)
211 211
212 /***** From RFC 822, 3.3 Lexical Tokens *****/ 212 /***** From RFC 822, 3.3 Lexical Tokens *****/
213 213
214 int parse822_skip_crlf(const char** p, const char* e) 214 int parse822_skip_nl(const char** p, const char* e)
215 { 215 {
216 /* Here we consider a new-line (NL) to be either a bare LF, or
217 * a CRLF pair as required by the RFC.
218 */
216 const char* s = *p; 219 const char* s = *p;
220
217 if( 221 if(
218 (&s[1] < e) && 222 (&s[1] < e) &&
219 s[0] == '\r' && 223 s[0] == '\r' &&
...@@ -224,6 +228,17 @@ int parse822_skip_crlf(const char** p, const char* e) ...@@ -224,6 +228,17 @@ int parse822_skip_crlf(const char** p, const char* e)
224 228
225 return EOK; 229 return EOK;
226 } 230 }
231
232 if(
233 (&s[0] < e) &&
234 s[0] == '\n'
235 )
236 {
237 *p += 1;
238
239 return EOK;
240 }
241
227 return EPARSE; 242 return EPARSE;
228 } 243 }
229 int parse822_skip_lwsp_char(const char** p, const char* e) 244 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) ...@@ -237,7 +252,12 @@ int parse822_skip_lwsp_char(const char** p, const char* e)
237 int parse822_skip_lwsp(const char** p, const char* e) 252 int parse822_skip_lwsp(const char** p, const char* e)
238 { 253 {
239 /* 254 /*
240 * linear-white-space = 1*([CRLF] LWSP-char) 255 * linear-white-space = 1*([[CR]LF] LWSP-char)
256 *
257 * We interpret a bare LF as identical to the canonical CRLF
258 * line ending, I don't know another way since on a Unix system
259 * all CRLF will be translated to the local convention, a bare
260 * LF, and thus we can not deal with bare NLs in the message.
241 */ 261 */
242 int space = 0; 262 int space = 0;
243 263
...@@ -248,7 +268,7 @@ int parse822_skip_lwsp(const char** p, const char* e) ...@@ -248,7 +268,7 @@ int parse822_skip_lwsp(const char** p, const char* e)
248 space = 1; 268 space = 1;
249 continue; 269 continue;
250 } 270 }
251 if(parse822_skip_crlf(p, e) == EOK) { 271 if(parse822_skip_nl(p, e) == EOK) {
252 if(parse822_skip_lwsp_char(p, e) == EOK) { 272 if(parse822_skip_lwsp_char(p, e) == EOK) {
253 continue; 273 continue;
254 } 274 }
......