From 7c11e274646fadf6655cf85e294dae24b04629f2 Mon Sep 17 00:00:00 2001
From: "Rob Swindell (on Windows 11)" <rob@synchro.net>
Date: Sat, 7 Sep 2024 13:13:11 -0700
Subject: [PATCH] Log more/better messages when message fails to post (e.g.
 duplicate detected)

It appears I had the idea to make the CantPost text.dat string a format string
before, but never quite finished that change (e.g. made the change to
email.cpp and text.dat too).
---
 ctrl/text.dat         |  2 +-
 src/sbbs3/email.cpp   |  3 +--
 src/sbbs3/postmsg.cpp | 16 ++++++++++------
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/ctrl/text.dat b/ctrl/text.dat
index 0d22e8305f..2aadbc5ebb 100644
--- a/ctrl/text.dat
+++ b/ctrl/text.dat
@@ -915,7 +915,7 @@
 "\1n\r\nSorry, you can't edit this message.\r\n"	757 CantEditMsg
 "\1n\r\nSorry, you can't delete message #%u.\r\n"	758 CantDeleteMsg
 "\1n\r\nSorry, you can't read messages on %s %s\r\n"	759 CantReadSub
-"\1n\r\nSorry, you can't post that message.\r\n"	760 CantPostMsg
+"\rSorry, you can't post that message. Reason: %s\r\n"	760 CantPostMsg
 "\r\n\1y\1hOperator: \1w"				761 OperatorPrompt
 "Add this sub-board to your new-scan list"         762 AddSubToNewScanQ
 "\1n\1r\1iWARNING: You are reading messages past the last unvalidated message (%u)" 763 UnvalidatedWarning
diff --git a/src/sbbs3/email.cpp b/src/sbbs3/email.cpp
index c5e01c1caa..7b77e7be08 100644
--- a/src/sbbs3/email.cpp
+++ b/src/sbbs3/email.cpp
@@ -258,8 +258,7 @@ bool sbbs_t::email(int usernumber, const char *top, const char *subj, int mode,
 			smb_unlocksmbhdr(&smb);
 			smb_close(&smb);
 			smb_stack(&smb,SMB_STACK_POP);
-			attr(cfg.color[clr_err]);
-			bputs(text[CantPostMsg]);
+			bprintf(text[CantPostMsg], i == SMB_DUPE_MSG ? "duplicate" : "other");
 			return(false); 
 		} 
 	}
diff --git a/src/sbbs3/postmsg.cpp b/src/sbbs3/postmsg.cpp
index f7630d7449..90de3d611e 100644
--- a/src/sbbs3/postmsg.cpp
+++ b/src/sbbs3/postmsg.cpp
@@ -312,17 +312,21 @@ bool sbbs_t::postmsg(int subnum, int wm_mode, smb_t* resmb, smbmsg_t* remsg)
 	i=smb_addmsg(&smb,&msg,storage,dupechk_hashes,xlat,(uchar*)msgbuf, findsig(msgbuf));
 	free(msgbuf);
 
-	if(i==SMB_DUPE_MSG) {
-		attr(cfg.color[clr_err]);
-		bprintf(text[CantPostMsg], smb.last_error);
-	} else if(i!=SMB_SUCCESS)
+	if(i==SMB_DUPE_MSG)
+		bprintf(text[CantPostMsg], "duplicate");
+	else if(i!=SMB_SUCCESS)
 		errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error);
 
 	smb_close(&smb);
 	smb_stack(&smb,SMB_STACK_POP);
 	smb_freemsgmem(&msg);
-	if(i!=SMB_SUCCESS)
-		return(false); 
+	if(i!=SMB_SUCCESS) {
+		if(i == SMB_DUPE_MSG)
+			llprintf(LOG_NOTICE, "P!", "duplicate message post attempt in %s", cfg.sub[subnum]->code);
+		else
+			llprintf(LOG_NOTICE, "P!", "message posting failure (SMB error %d) in %s", i, cfg.sub[subnum]->code);
+		return false;
+	}
 
 	logon_posts++;
 	user_posted_msg(&cfg, &useron, 1);
-- 
GitLab