shithub: Nail

Download patch

ref: eb491d33f6608b948b3615e9ac2b93c8824a30bb
parent: c96f87d66f550ddcc92a6bf184088d4167937c0a
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Dec 20 13:21:30 EST 2020

message id matching: make id matching stricter

We used to try matching '123foo' as a message id,
due to the numeric prefix. Now, we require that
the numeric portion match fully, or be terminated
with a /.

This leads to strings with numeric prefixes being
plumbable.

--- a/mail.h
+++ b/mail.h
@@ -148,7 +148,6 @@
 };
 
 extern Mbox	mbox;
-extern Reprog	*addrpat;
 extern Reprog	*mesgpat;
 extern char	*savebox;
 
--- a/mbox.c
+++ b/mbox.c
@@ -1028,7 +1028,7 @@
 		mailbox = argv[0];
 
 	addrpat = regcomp("[^ \t]*@[^ \t]*\\.[^ \t]*");
-	mesgpat = regcomp("[0-9]+(/.*)?");
+	mesgpat = regcomp("([0-9]+)(/.*)?");
 	cwait = threadwaitchan();
 
 	/* open these early so we won't miss messages while loading */
--- a/win.c
+++ b/win.c
@@ -266,14 +266,16 @@
 int
 matchmesg(Win *, char *text)
 {
-	char *p;
+	Resub m[3];
 
+	memset(m, 0, sizeof(m));
 	if(strncmp(text, mbox.path, strlen(mbox.path)) == 0)
 		return 1;
-	else if(regexec(mesgpat, text, nil, 0)){
-		if((p = strchr(text, '/')) != nil)
-			p[1] = 0;
-		return 1;
+	else if(regexec(mesgpat, text, m, nelem(m))){
+		if(*m[1].ep == 0 || *m[1].ep == '/'){
+			*m[1].ep = 0;
+			return 1;
+		}
 	}
 	return 0;
 }