From 18bba2e722136fdb582ce4d02ecec4df0af39847 Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Fri, 6 Apr 2018 00:14:06 +0000
Subject: [PATCH] Fix a couple of issues with external mail processors: - Since
 rev 1.556, mailproc_to_match[] would only ever contain one mail   processor
 (index) value, even if the RCPT TO address matched multiple   mail processor
 "To" keys in mailproc.ini, so only the first-matching   mail processor (with
 a "To" key) would be executed for the msg. - mailproc_match, meaning the
 destination was a non-passthrough   external mail processor, in which case
 the destination (RCPT TO) address   may *not* match a valid local user
 account, would be set for *passthru*   mail processors potentially resulting
 in the following error (and an   undelivered mail message): !SMTP can't
 deliver mail to user #0   only set mailproc_match to a valid mail proc index
 if the recipient matches a   non-passthru mail processor.

---
 src/sbbs3/mailsrvr.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/sbbs3/mailsrvr.c b/src/sbbs3/mailsrvr.c
index 89ddaeec62..c7054e55b1 100644
--- a/src/sbbs3/mailsrvr.c
+++ b/src/sbbs3/mailsrvr.c
@@ -4445,7 +4445,8 @@ static void smtp_thread(void* arg)
 				lprintf(LOG_DEBUG,"%04d SMTP NAME ALIAS: %s (for %s)"
 					,socket,p,rcpt_addr);
 		
-			/* Check if message is to be processed by an external mail processor */
+			/* Check if message is to be processed by one or more external mail processors */
+			mailproc_match = INT_MAX;	// no match, by default
 			for(i=0;i<mailproc_count;i++) {
 
 				if(!mailproc_list[i].process_dnsbl && dnsbl_result.s_addr)
@@ -4459,10 +4460,10 @@ static void smtp_thread(void* arg)
 
 				if(findstr_in_list(p, mailproc_list[i].to) || findstr_in_list(rcpt_addr, mailproc_list[i].to)) {
 					mailproc_to_match[i]=TRUE;
-					break;
+					if(!mailproc_list[i].passthru)
+						mailproc_match = i;
 				}
 			}
-			mailproc_match=i;
 
 			if(!strnicmp(p,"sub:",4)) {		/* Post on a sub-board */
 				p+=4;
-- 
GitLab