From 981fd18a49e8f22e2fb4648c6f56e5ba13c873a9 Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Sun, 18 Aug 2019 20:24:30 +0000
Subject: [PATCH] Added "name <user@addr>" address parsing for Internet email.

---
 src/sbbs3/netmail.cpp | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/src/sbbs3/netmail.cpp b/src/sbbs3/netmail.cpp
index 8af7213f34..3155ece9e1 100644
--- a/src/sbbs3/netmail.cpp
+++ b/src/sbbs3/netmail.cpp
@@ -65,7 +65,17 @@ bool sbbs_t::inetmail(const char *into, const char *subj, long mode, smb_t* resm
 
 	if(into != NULL) {
 		SAFECOPY(name,into);
-		SAFECOPY(addr,into);
+		if((p = strrchr((char*)into, '<')) != NULL) {
+			SAFECOPY(addr, p + 1);
+			p = strrchr(addr, '>');
+			if(p == NULL) {
+				bputs(text[InvalidNetMailAddr]);
+				return false;
+			}
+			*p = 0;
+		} else {
+			SAFECOPY(addr, into);
+		}
 	}
 	if(subj != NULL)
 		SAFECOPY(title,subj);
@@ -83,6 +93,11 @@ bool sbbs_t::inetmail(const char *into, const char *subj, long mode, smb_t* resm
 		return(false); 
 	}
 
+	if(strchr(addr, ' ') != NULL || strchr(addr, '@') <= addr) {
+		bputs(text[InvalidNetMailAddr]);
+		return false;
+	}
+
 	if(cfg.inetmail_cost && !(useron.exempt&FLAG('S'))) {
 		if(useron.cdt+useron.freecdt<cfg.inetmail_cost) {
 			bputs(text[NotEnoughCredits]);
@@ -94,12 +109,16 @@ bool sbbs_t::inetmail(const char *into, const char *subj, long mode, smb_t* resm
 	}
 
 	/* Get destination user name */
-	p=strrchr(name,'@');
+	p=strrchr(name,'<');
+	if(!p)
+		p=strrchr(name,'@');
 	if(!p)
 		p=strrchr(name,'!');
 	if(p) {
 		*p=0;
-		truncsp(name); 
+		truncsp(name);
+		if(name[0] == 0)
+			SAFECOPY(name, addr);
 	}
 
 	/* Get this user's internet mailing address */
-- 
GitLab