From 26d0b46e87d2bcc640289d1a90baa8de71dc7378 Mon Sep 17 00:00:00 2001
From: "Rob Swindell (on Debian Linux)" <rob@synchro.net>
Date: Wed, 26 Feb 2025 19:00:10 -0800
Subject: [PATCH] Support per-sub-board user signature (.sig files)

This feature was long overdue.

And "SIG" command to view, create or edit default signature (same function as
available from user_settings.js, in fact a copy/pasted the code).
Add "SUBSIG" command to view, create, or edit sub-board signture (no other
method is available to this other than direct file system access, e.g. by the
sysop).
---
 exec/str_cmds.js       | 23 +++++++++++++++++++++++
 src/sbbs3/writemsg.cpp |  8 +++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/exec/str_cmds.js b/exec/str_cmds.js
index 7f84793548..315a78555a 100644
--- a/exec/str_cmds.js
+++ b/exec/str_cmds.js
@@ -820,6 +820,29 @@ function str_cmds(str)
 					console.printfile(plan);
 			}
 		}
+
+		if(str=="HELP") {
+			writeln("SIG\tEdit or delete your default message signature.");
+			writeln("SUBSIG\tEdit or delete your signature for this sub-board (over-rides default).");
+		}
+		if(str=="SIG" || str=="SUBSIG") {
+			var userSigFilename = system.data_dir + "user/" + format("%04u", user.number);
+			if(str == "SUBSIG")
+				userSigFilename += "." + bbs.cursub_code;
+			userSigFilename += ".sig";
+			if (file_exists(userSigFilename)) {
+				if (console.yesno(bbs.text(bbs.text.ViewSignatureQ)))
+					console.printfile(userSigFilename);
+			}
+			if (console.yesno(bbs.text(bbs.text.CreateEditSignatureQ)))
+				console.editfile(userSigFilename);
+			else if (!console.aborted) {
+				if (file_exists(userSigFilename)) {
+					if (console.yesno(bbs.text(bbs.text.DeleteSignatureQ)))
+						file_remove(userSigFilename);
+				}
+			}
+		}
 	}
 
 	if(str=="HELP") {
diff --git a/src/sbbs3/writemsg.cpp b/src/sbbs3/writemsg.cpp
index ef42e8d68a..2b4d95cafc 100644
--- a/src/sbbs3/writemsg.cpp
+++ b/src/sbbs3/writemsg.cpp
@@ -750,7 +750,13 @@ bool sbbs_t::writemsg(const char *fname, const char *top, char *subj, int mode,
 		/* Signature file */
 		if ((subnum == INVALID_SUB && cfg.msg_misc & MM_EMAILSIG)
 		    || (subnum != INVALID_SUB && !(cfg.sub[subnum]->misc & SUB_NOUSERSIG))) {
-			SAFEPRINTF2(str, "%suser/%04u.sig", cfg.data_dir, useron.number);
+			bool got_sig = false;
+			if (subnum_is_valid(subnum)) {
+				snprintf(str, sizeof str, "%suser/%04u.%s.sig", cfg.data_dir, useron.number, cfg.sub[subnum]->code);
+				got_sig = fexistcase(str);
+			}
+			if (!got_sig)
+				SAFEPRINTF2(str, "%suser/%04u.sig", cfg.data_dir, useron.number);
 			FILE* sig;
 			if (fexistcase(str) && (sig = fopen(str, "r")) != NULL) {
 				while (!feof(sig)) {
-- 
GitLab