9front - general discussion about 9front
 help / color / mirror / Atom feed
* upas/fs: change header filters
@ 2020-10-05  3:13 ori
  2020-10-05 17:03 ` [9front] " Lyndon Nerenberg
  0 siblings, 1 reply; 2+ messages in thread
From: ori @ 2020-10-05  3:13 UTC (permalink / raw)
  To: 9front

This change does two things:

1) It puts in some defaults -- for now, the behavior should,
   be unchanged, but I think we can put some more thought into
   the default set of headers to show. This lets us get rid
   of /mail/lib/ignore.

2) It flips the default action to accept a header, and
   adds a '!' operator to reject. First match wins.

   Note that the default
   action if there are no matches is to accept, so for
   a file that rejects all but a few headers, the last
   line should be a '!' on its own:


	# Show a few headers
	From:
	To:
	# Drop X-original-to
	!X-Original-To:
	# Keep all other x-headers
	X-
	# Drop everything else
	!

diff -r bd503458654d sys/src/cmd/upas/fs/fs.c
--- a/sys/src/cmd/upas/fs/fs.c	Sun Oct 04 22:45:22 2020 +0200
+++ b/sys/src/cmd/upas/fs/fs.c	Sun Oct 04 20:12:47 2020 -0700
@@ -1500,11 +1500,32 @@
 typedef struct Ignorance Ignorance;
 struct Ignorance
 {
-	Ignorance *next;
+	int	drop;
+	int	len;
 	char	*str;
-	int	len;
 };
 static Ignorance *ignorance;
+static int nignorance;
+static Ignorance defaultignorance[] = {
+	{.drop=1, .len=13,	.str="Mime-Version:"},
+	{.drop=1, .len=8,	.str="Content-"},
+	{.drop=1, .len=11,	.str="Message-Id:"},
+	{.drop=1, .len=9,	.str="Received:"},
+	{.drop=1, .len=7,	.str="Mailer:"},
+	{.drop=1, .len=11,	.str="References:"},
+	{.drop=1, .len=11,	.str="Precedence:"},
+	{.drop=1, .len=2,	.str="X-"},
+	{.drop=1, .len=5,	.str="X400-"},
+	{.drop=1, .len=2,	.str="O-"},
+	{.drop=1, .len=5,	.str="List-"},
+	{.drop=1, .len=13,	.str="Organization:"},
+	{.drop=1, .len=11,	.str="User-Agent:"},
+	{.drop=1, .len=12,	.str="In-Reply-To:"},
+	{.drop=1, .len=13,	.str="Delivered-To:"},
+	{.drop=1, .len=20,	.str="DomainKey-Signature:"},
+	{.drop=1, .len=15,	.str="DKIM-Signature:"},
+	{.drop=0, .len=0,	.str=""},
+};
 
 /*
  *  read the file of headers to ignore
@@ -1515,28 +1536,32 @@
 	char *p;
 	Ignorance *i;
 	Biobuf *b;
+	int drop;
 
 	if(ignorance != nil)
 		return;
 
-	b = Bopen("/mail/lib/ignore", OREAD);
-	if(b == 0)
+	b = Bopen("/mail/lib/filterheaders", OREAD);
+	if(b == nil){
+		ignorance = defaultignorance;
+		nignorance = nelem(defaultignorance);
 		return;
+	}
 	while(p = Brdline(b, '\n')){
 		p[Blinelen(b) - 1] = 0;
 		while(*p && (*p == ' ' || *p == '\t'))
 			p++;
-		if(*p == '#')
+		if(*p == '#' || *p == '\0')
 			continue;
-		i = emalloc(sizeof *i);
+		if(drop = (*p == '!'))
+			p++;
+		ignorance = erealloc(ignorance, ++nignorance*sizeof(*i));
+		i = &ignorance[nignorance - 1];
+		i->drop = drop;
 		i->len = strlen(p);
 		i->str = strdup(p);
-		if(i->str == 0){
-			free(i);
-			break;
-		}
-		i->next = ignorance;
-		ignorance = i;
+		if(i->str == nil)
+			sysfatal("strdup: %r");
 	}
 	Bterm(b);
 }
@@ -1547,9 +1572,9 @@
 	Ignorance *i;
 
 	readignore();
-	for(i = ignorance; i != nil; i = i->next)
+	for(i = ignorance; i != &ignorance[nignorance]; i++)
 		if(i->len <= n && cistrncmp(i->str, p, i->len) == 0)
-			return 1;
+			return i->drop;
 	return 0;
 }
 



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [9front] upas/fs: change header filters
  2020-10-05  3:13 upas/fs: change header filters ori
@ 2020-10-05 17:03 ` Lyndon Nerenberg
  0 siblings, 0 replies; 2+ messages in thread
From: Lyndon Nerenberg @ 2020-10-05 17:03 UTC (permalink / raw)
  To: 9front

This last set of changes seems reasonable, but we really do need
to pay attention to when and where this sort of header munging
takes place.

The underlying issue is that there are three distinct email services
in play:

  1) SMTP relay, and
  2) Submission (initial message injection)
  3) Final delivery

upas predates (2) being carved out as a distinct service.

In almost all cases, SMTP relay should *never* touch the headers,
other than to add a Received trace header.

The submission service (2) should *add* any missing required or
defacto-required headers (primarily Message-ID, Date, From), but
otherwise leave existing headers intact.

By the time you hand off to the local delivery agent (3), the message
is in the recipient's hands and all bets are off.

To do all of this properly requires significant restructuring of
how upas works.  Since I personally consider upas a botch from start
to finish I'm not willing to put any time into "fixing" it, although
others might.  I'd rather put the effort into replacing upas outright
with something that properly breaks up this functionality, and is
more in tune with the current set of email RFCs.

--lyndon


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-10-05 17:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-05  3:13 upas/fs: change header filters ori
2020-10-05 17:03 ` [9front] " Lyndon Nerenberg

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).