From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from outgoing.selfhost.de ([82.98.87.70]) by ewsd; Fri Sep 11 17:08:27 EDT 2020 Received: (qmail 32112 invoked from network); 11 Sep 2020 21:08:09 -0000 Received: from unknown (HELO mx03.bss-wf.de) (postmaster@emdtgvmf.mail.selfhost.de@84.150.42.130) by mailout.selfhost.de with ESMTPA; 11 Sep 2020 21:08:09 -0000 Received: by mx03.bss-wf.de (Postfix, from userid 1000) id 2206A3DD7C; Fri, 11 Sep 2020 23:08:09 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mx03 X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED autolearn=ham autolearn_force=no version=3.4.2 Received: from 9nb.pala (p5b3bc91e.dip0.t-ipconnect.de [91.59.201.30]) by mx03.bss-wf.de (Postfix) with ESMTPSA id 299213DD7A for <9front@9front.org>; Fri, 11 Sep 2020 23:08:07 +0200 (CEST) Message-ID: To: 9front@9front.org Subject: Re: [9front] [Bug] [PATCH] Mail cannot cope with multi-line header fields Date: Fri, 11 Sep 2020 23:08:06 +0200 From: theinicke@bss-wf.de In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: virtual virtual method-oriented locator Then the simplest way to do that might be something like the following (remove all line breaks from info fields, preserving it everywhere else). But maybe we would like to take into account the fact that some info fields never contain line breaks or remove them not just in info file but earlier by stripping them in copy822,.. diff -r d8b6a8706f51 sys/src/cmd/upas/fs/fs.c --- a/sys/src/cmd/upas/fs/fs.c Mon Sep 07 19:32:50 2020 -0700 +++ b/sys/src/cmd/upas/fs/fs.c Fri Sep 11 23:03:08 2020 +0200 @@ -387,6 +387,33 @@ return s; } +int +unfold(char *s, int len, char **pp) +{ + int i, u; + char c; + char *p; + + if(s == nil) { + return 0; + } + + p = malloc(len); + *pp = p; + u = 0; + for(i = 0; i < len; i++) { + c = s[i]; + if(c != '\n') { + p[u++] = c; + } + } + if(u < len) { + p[u] = '\0'; + } + + return u; +} + static int fileinfo(Mailbox *mb, Message *m, int t, char **pp) { @@ -568,7 +595,7 @@ int readinfo(Mailbox *mb, Message *m, char *buf, long off, int count) { - char *s, *p, *e; + char *s, *p, *e, *q; int i, n; long off0; @@ -584,18 +611,22 @@ } if((n = fileinfo(mb, m, infofields[i], &p)) < 0) return -1; + /* remove line breaks in fields s.t. consumers of info + can rely on finding particular field at certain line */ + n = unfold(p, n, &q); if(off > n){ off -= n + 1; continue; } if(off){ n -= off; - p += off; + q += off; off = 0; } if(s + n > e) n = e - s; - memcpy(s, p, n); + memcpy(s, q, n); + free(q); s += n; if(s < e) *s++ = '\n';