diff options
author | Ori Bernstein <ori@eigenstate.org> | 2020-09-17 16:11:10 -0700 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2020-09-17 16:11:10 -0700 |
commit | e3166b4fe83d12a29c265fe9a8f333369b35c663 (patch) | |
tree | cef492a6def1a437b4a88d4b63c72fcd0f41682d /sys/src/cmd/upas/fs | |
parent | 77b819d5853132be43639d1b2149caf5edacbba2 (diff) |
upas/fs: fix handing of multi-line header fields (thanks theinicke)
Right now, upasfs exposes header lines as is, without stripping
out new lines. It also documents that it provides one header per
line in the info file.
As a result, when we get a mail with headers that span lines,
our tools get confused.
These split lines are not semantically meaningful. From RFC5322:
2.2.3. Long Header Fields
Each header field is logically a single line of characters comprising
the field name, the colon, and the field body. For convenience
however, and to deal with the 998/78 character limitations per line,
the field body portion of a header field can be split into a
multiple-line representation; this is called "folding". The general
rule is that wherever this specification allows for folding white
space (not simply WSP characters), a CRLF may be inserted before any
WSP.
As a result, to simplify processing, we should just strip out the
line separators when exposing the headers from upasfs.
Diffstat (limited to 'sys/src/cmd/upas/fs')
-rw-r--r-- | sys/src/cmd/upas/fs/mbox.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/sys/src/cmd/upas/fs/mbox.c b/sys/src/cmd/upas/fs/mbox.c index 5b57dba41..84d892b49 100644 --- a/sys/src/cmd/upas/fs/mbox.c +++ b/sys/src/cmd/upas/fs/mbox.c @@ -733,6 +733,19 @@ rtrim(char *p) } static char* +unfold(char *s) +{ + char *p, *q; + + q = s; + for(p = q; *p != '\0'; p++) + if(*p != '\r' && *p != '\n') + *q++ = *p; + *q = '\0'; + return s; +} + +static char* addr822(char *p, char **ac) { int n, c, space, incomment, addrdone, inanticomment, quoted; @@ -760,7 +773,7 @@ addr822(char *p, char **ac) for(p++; c = *p; p++){ if(ac && c == '"') break; - if(!addrdone && !incomment) + if(!addrdone && !incomment && c != '\r' && c != '\n') ps = sputc(ps, e, c); if(!quoted && *p == '"') break; @@ -883,7 +896,7 @@ replace822(Message *, Header *h, char*, char *p) static char* copy822(Message*, Header *h, char*, char *p) { - return rtrim(strdup(skipwhite(p + h->len))); + return rtrim(unfold(strdup(skipwhite(p + h->len)))); } static char* |