From cdaba0e62d5d0ab93e368cb44b1a407bd1a4af02 Mon Sep 17 00:00:00 2001
From: "Rob Swindell (on Windows)" <rob@synchro.net>
Date: Wed, 29 Mar 2023 12:47:47 -0700
Subject: [PATCH] MsgBase.save_msg() throw an exception when an empty recipient
 list is provided

... rather than just return false.

This will make debugging this type of issue much easier in the future.
sendmail.js was allowing empty recipient_list array arguments and the MsgBase
.status was 0 and .error just an emtpy string - unhelpful.
---
 src/sbbs3/js_msgbase.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/sbbs3/js_msgbase.c b/src/sbbs3/js_msgbase.c
index 179dbbf4f5..815906374d 100644
--- a/src/sbbs3/js_msgbase.c
+++ b/src/sbbs3/js_msgbase.c
@@ -2628,7 +2628,12 @@ js_save_msg(JSContext *cx, uintN argc, jsval *arglist)
 		body=strdup("");
 
 	if(rcpt_list!=NULL) {
-		if(!JS_GetArrayLength(cx, rcpt_list, &rcpt_list_length) || !rcpt_list_length) {
+		if(!JS_GetArrayLength(cx, rcpt_list, &rcpt_list_length)) {
+			free(body);
+			return JS_TRUE;
+		}
+		if(rcpt_list_length < 1) {
+			JS_ReportError(cx, "Empty recipient list");
 			free(body);
 			return JS_TRUE;
 		}
-- 
GitLab