ref: e3166b4fe83d12a29c265fe9a8f333369b35c663
parent: 77b819d5853132be43639d1b2149caf5edacbba2
author: Ori Bernstein <[email protected]>
date: Thu Sep 17 12:11:10 EDT 2020
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.
--- a/sys/src/cmd/upas/fs/mbox.c
+++ b/sys/src/cmd/upas/fs/mbox.c
@@ -733,6 +733,19 @@
}
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 @@
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 @@
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*