From 41ed7a56224ff0b22d81999ad418168f00367c90 Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Sun, 26 Apr 2020 20:43:06 +0000
Subject: [PATCH] Fix bug reported by Mark Lewis (Rampage@SESTAR), when packing
 NetMail messages (from stored messages in .msg files into packets), the
 origin net/node within the  *packed message* header would be set to the local
 system's address net/node (for the destination zone), always. This is the
 appropriate action when packing EchoMail, but not for NetMail.

Now, there are lot of other header fields in the packed message that contain
the source/origin address (e.g. @FMPT, @INTL kludges) and those would reflect
the original origin address still. And these fields take precedence over the
orign net/node fields of the packed message header. So I'm not sure this bug
would actually cause any problems anywhere, but it was a bug all the same.
---
 src/sbbs3/sbbsecho.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/sbbs3/sbbsecho.c b/src/sbbs3/sbbsecho.c
index 8d37050821..3f77df5ddd 100644
--- a/src/sbbs3/sbbsecho.c
+++ b/src/sbbs3/sbbsecho.c
@@ -3707,8 +3707,13 @@ void putfmsg(FILE* stream, const char* fbuf, fmsghdr_t* hdr, area_t area
 	/* Write fixed-length header fields */
 	memset(&pkdmsg,0,sizeof(pkdmsg));
 	pkdmsg.type		= 2;
-	pkdmsg.orignet	= addr.net;
-	pkdmsg.orignode	= addr.node;
+	if(area.tag == NULL)	{ /* NetMail, so use original origin address */
+		pkdmsg.orignet	= hdr->orignet;
+		pkdmsg.orignode = hdr->orignode;
+	} else {
+		pkdmsg.orignet	= addr.net;
+		pkdmsg.orignode	= addr.node;
+	}
 	pkdmsg.destnet	= hdr->destnet;
 	pkdmsg.destnode	= hdr->destnode;
 	pkdmsg.attr		= hdr->attr;
@@ -4676,14 +4681,12 @@ void export_echomail(const char* sub_code, const nodecfg_t* nodecfg, bool rescan
 	fmsghdr_t hdr;
 	struct	tm *tm;
 	post_t *post;
-	area_t fakearea;
 	addrlist_t msg_seen,msg_path;
 	time_t	tt;
 	time_t now = time(NULL);
 
 	memset(&msg_seen,0,sizeof(addrlist_t));
 	memset(&msg_path,0,sizeof(addrlist_t));
-	memset(&fakearea,0,sizeof(area_t));
 	memset(&hdr,0,sizeof(hdr));
 
 	printf("\nScanning for Outbound EchoMail...");
-- 
GitLab