From e35e78866a3ffb815cad7fba33ada606d9eb6158 Mon Sep 17 00:00:00 2001
From: "Rob Swindell (on Windows 11)" <rob@synchro.net>
Date: Sun, 10 Dec 2023 13:37:19 -0800
Subject: [PATCH] Support @-codes in Regarding* text.dat strings

Expected to use the MSG_* @-codes in this context. This allows more freedom
of ordering the message header fields reused in this expanded string. The %s
specifiers can be eliminated altogether when using @-codes.

For Accession to play with.
---
 src/sbbs3/postmsg.cpp  | 4 +++-
 src/sbbs3/readmail.cpp | 8 +++++---
 src/sbbs3/readmsgs.cpp | 4 +++-
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/sbbs3/postmsg.cpp b/src/sbbs3/postmsg.cpp
index 0f621086d0..83eef67016 100644
--- a/src/sbbs3/postmsg.cpp
+++ b/src/sbbs3/postmsg.cpp
@@ -67,6 +67,7 @@ static uchar* findsig(char* msgbuf)
 bool sbbs_t::postmsg(int subnum, int wm_mode, smb_t* resmb, smbmsg_t* remsg)
 {
 	char	str[256];
+	char	fmt[256];
 	char	title[LEN_TITLE+1] = "";
 	char	top[256] = "";
 	char	touser[64] = "";
@@ -107,7 +108,8 @@ bool sbbs_t::postmsg(int subnum, int wm_mode, smb_t* resmb, smbmsg_t* remsg)
 		if(remsg->to != NULL)
 			strListPush(&names, remsg->to);
 		msgattr=(ushort)(remsg->hdr.attr&MSG_PRIVATE);
-		sprintf(top,text[RegardingByToOn]
+		expand_atcodes(text[RegardingByToOn], fmt, sizeof fmt);
+		snprintf(top, sizeof top, fmt
 			,title
 			,from
 			,msghdr_field(remsg, remsg->to, NULL, term_supports(UTF8))
diff --git a/src/sbbs3/readmail.cpp b/src/sbbs3/readmail.cpp
index f148bb6dbb..b45dfe5885 100644
--- a/src/sbbs3/readmail.cpp
+++ b/src/sbbs3/readmail.cpp
@@ -43,6 +43,7 @@ int sbbs_t::readmail(uint usernumber, int which, int lm_mode)
 {
 	char	str[256],str2[256],done=0,domsg=1
 			,*p;
+	char	fmt[256];
 	char 	tmp[512];
 	int		i;
 	uint32_t u,v;
@@ -344,10 +345,11 @@ int sbbs_t::readmail(uint usernumber, int which, int lm_mode)
 				smb_getmsgidx(&smb,&msg);
 
 				if(!stricmp(str2,str))		/* Reply to sender */
-					SAFEPRINTF(str2,text[Regarding], msghdr_field(&msg, msg.subj));
+					expand_atcodes(text[Regarding], fmt, sizeof fmt);
 				else						/* Reply to other */
-					SAFEPRINTF3(str2,text[RegardingByOn], msghdr_field(&msg, msg.subj), msghdr_field(&msg, msg.from, tmp)
-						,timestr(msg.hdr.when_written.time));
+					expand_atcodes(text[RegardingByOn], fmt, sizeof fmt);
+				SAFEPRINTF3(str2, fmt, msghdr_field(&msg, msg.subj), msghdr_field(&msg, msg.from, tmp)
+					,timestr(msg.hdr.when_written.time));
 
 				p=strrchr(str,'@');
 				if(p) { 							/* name @addr */
diff --git a/src/sbbs3/readmsgs.cpp b/src/sbbs3/readmsgs.cpp
index 1067f6f34c..a5753feeef 100644
--- a/src/sbbs3/readmsgs.cpp
+++ b/src/sbbs3/readmsgs.cpp
@@ -396,6 +396,7 @@ int sbbs_t::scanposts(int subnum, int mode, const char *find)
 {
 	char	str[256],str2[256],do_find=true,mismatches=0
 			,done=0,domsg=1,*buf;
+	char	fmt[256];
 	char	find_buf[128];
 	char	tmp[128];
 	int		i;
@@ -1006,7 +1007,8 @@ int sbbs_t::scanposts(int subnum, int mode, const char *find)
 					&& stricmp(msg.to,useron.name)
 					&& stricmp(msg.to,useron.alias))
 					break;
-				SAFEPRINTF2(str2,text[Regarding]
+				expand_atcodes(text[Regarding], fmt, sizeof fmt);
+				SAFEPRINTF2(str2, fmt
 					,msghdr_field(&msg, msg.subj)
 					,timestr(msg.hdr.when_written.time));
 				if(msg.from_net.addr==NULL)
-- 
GitLab