9front - general discussion about 9front
 help / color / mirror / Atom feed
From: theinicke@bss-wf.de
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	[thread overview]
Message-ID: <E5B90C9FB0641679CAAC6A91690E70ED@bss-wf.de> (raw)
In-Reply-To: <F4C02EB6DC83C56813C8B0C8CB2F4793@eigenstate.org>

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';



  reply	other threads:[~2020-09-11 21:08 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-09 19:33 theinicke
2020-09-09 19:50 ` [9front] " ori
2020-09-10  6:27   ` theinicke
2020-09-10 19:58     ` theinicke
2020-09-10 21:12       ` ori
2020-09-11 21:08         ` theinicke [this message]
2020-09-12 21:19           ` theinicke
2020-09-12 22:58           ` ori
2020-09-14 21:49             ` theinicke
2020-09-17 23:01               ` ori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E5B90C9FB0641679CAAC6A91690E70ED@bss-wf.de \
    --to=theinicke@bss-wf.de \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).