diff --git a/src/sbbs3/writemsg.cpp b/src/sbbs3/writemsg.cpp
index f06d8fc76de1c806966492946aafd9319756c48b..e740547bf992eefbc5527423e96aba0cd9c5d72d 100644
--- a/src/sbbs3/writemsg.cpp
+++ b/src/sbbs3/writemsg.cpp
@@ -516,7 +516,6 @@ bool sbbs_t::writemsg(const char *fname, const char *top, char *subj, long mode,
 	}
 
 	editor_details[0] = 0;
-	smb.subnum = subnum;	/* Allow JS msgeditors to use bbs.smb_sub* */
 
 	if(console&CON_RAW_IN) {
 
@@ -596,8 +595,11 @@ bool sbbs_t::writemsg(const char *fname, const char *top, char *subj, long mode,
 
 		CLS;
 		rioctl(IOCM|PAUSE|ABORT);
+		auto savsubnum = smb.subnum;
+		smb.subnum = subnum;	/* Allow JS msgeditors to use bbs.smb_sub* */
 		const char* cmd = cmdstr(cfg.xedit[useron_xedit-1]->rcmd, msgtmp, nulstr, NULL, ex_mode);
 		int result = external(cmd, ex_mode, cfg.node_dir);
+		smb.subnum = savsubnum;
 		lprintf(LOG_DEBUG, "'%s' returned %d", cmd, result);
 		rioctl(IOSM|PAUSE|ABORT);