From bce719a8a77b485111cbc0486715d75c92820308 Mon Sep 17 00:00:00 2001
From: Rob Swindell <rob@synchro.net>
Date: Thu, 24 Dec 2020 16:15:28 -0800
Subject: [PATCH] Add/use new FTN "BBSID" control paragraph (kludge line)

Advertise the system's QWK-ID (a.k.a. BBS ID) in exported echomail messages. This will allow correlation of avatars that were imported via SYNCDATA carried via QWKnet (e.g. DOVE-Net) with messages imported from those same BBSes via FTN.

The alternative was to have SYNCDATA Avatar messages include all the AKAs of each BBS (in the body text), but that was looking like a rather complicated solution. This approach (the BBSID kludge) seems a much simpler solution.

I still need to implement the JS side of this solution however (for avatar lookups using the FTN BBSID), but this was the first important step.
---
 src/sbbs3/js_msgbase.c | 29 ++++++++++++++---------------
 src/sbbs3/sbbsecho.c   | 16 ++++++++++++++++
 src/smblib/smbdefs.h   | 25 ++++++-------------------
 src/smblib/smblib.c    |  3 +++
 src/smblib/smbstr.c    |  1 +
 5 files changed, 40 insertions(+), 34 deletions(-)

diff --git a/src/sbbs3/js_msgbase.c b/src/sbbs3/js_msgbase.c
index 9dd49638f9..fdde31ba8c 100644
--- a/src/sbbs3/js_msgbase.c
+++ b/src/sbbs3/js_msgbase.c
@@ -1,8 +1,5 @@
 /* Synchronet JavaScript "MsgBase" Object */
 
-/* $Id: js_msgbase.c,v 1.262 2020/05/07 21:58:37 rswindell Exp $ */
-// vi: tabstop=4
-
 /****************************************************************************
  * @format.tab-size 4		(Plain Text/Source Code File Header)			*
  * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
@@ -16,21 +13,9 @@
  * See the GNU General Public License for more details: gpl.txt or			*
  * http://www.fsf.org/copyleft/gpl.html										*
  *																			*
- * Anonymous FTP access to the most recent released source is available at	*
- * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net	*
- *																			*
- * Anonymous CVS access to the development source and modification history	*
- * is available at cvs.synchro.net:/cvsroot/sbbs, example:					*
- * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login			*
- *     (just hit return, no password is necessary)							*
- * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src		*
- *																			*
  * For Synchronet coding style and modification guidelines, see				*
  * http://www.synchro.net/source.html										*
  *																			*
- * You are encouraged to submit any modifications (preferably in Unix diff	*
- * format) via e-mail to mods@synchro.net									*
- *																			*
  * Note: If this box doesn't appear square, then you need to fix your tabs.	*
  ****************************************************************************/
 
@@ -795,6 +780,19 @@ static BOOL parse_header_object(JSContext* cx, private_t* p, JSObject* hdr, smbm
 		}
 	}
 
+	if(JS_GetProperty(cx, hdr, "ftn_bbsid", &val) && !JSVAL_NULL_OR_VOID(val)) {
+		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
+		HANDLE_PENDING(cx, cp);
+		if(cp==NULL) {
+			JS_ReportError(cx, "Invalid \"ftn_bbsid\" string in header object");
+			goto err;
+		}
+		if((smb_result = smb_hfield_str(msg, FIDOBBSID, cp))!=SMB_SUCCESS) {
+			JS_ReportError(cx, "Error %d adding FIDOBBSID field to message header", smb_result);
+			goto err;
+		}
+	}
+
 	if(JS_GetProperty(cx, hdr, "date", &val) && !JSVAL_NULL_OR_VOID(val)) {
 		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
 		HANDLE_PENDING(cx, cp);
@@ -1522,6 +1520,7 @@ static JSBool js_get_msg_header_resolve(JSContext *cx, JSObject *obj, jsid id)
 	LAZY_STRING_TRUNCSP_NULL("ftn_area", p->msg.ftn_area, JSPROP_ENUMERATE);
 	LAZY_STRING_TRUNCSP_NULL("ftn_flags", p->msg.ftn_flags, JSPROP_ENUMERATE);
 	LAZY_STRING_TRUNCSP_NULL("ftn_charset", p->msg.ftn_charset, JSPROP_ENUMERATE);
+	LAZY_STRING_TRUNCSP_NULL("ftn_bbsid", p->msg.ftn_bbsid, JSPROP_ENUMERATE);
 
 	if(name==NULL || strcmp(name,"field_list")==0) {
 		if(name) free(name);
diff --git a/src/sbbs3/sbbsecho.c b/src/sbbs3/sbbsecho.c
index ef34fff721..b0431a0a71 100644
--- a/src/sbbs3/sbbsecho.c
+++ b/src/sbbs3/sbbsecho.c
@@ -1232,6 +1232,8 @@ int create_netmail(const char *to, const smbmsg_t* msg, const char *subject, con
 			fprintf(fp, "\1MSGID: %.256s\r", msg->ftn_msgid);
 		if(msg->ftn_reply != NULL)
 			fprintf(fp, "\1REPLY: %.256s\r", msg->ftn_reply);
+		if(msg->ftn_bbsid != NULL)
+			fprintf(fp, "\1BBSID: %.256s\r", msg->ftn_bbsid);
 		if(msg->ftn_flags != NULL)
 			fprintf(fp, "\1FLAGS %s\r", msg->ftn_flags);
 		else if(msg->hdr.auxattr&MSG_KILLFILE)
@@ -3493,6 +3495,15 @@ int fmsgtosmsg(char* fbuf, fmsghdr_t* hdr, uint usernumber, uint subnum)
 					smb_hfield_bin(&msg, SMB_COLUMNS, columns);
 			}
 
+			else if(!strncmp(fbuf+l+1,"BBSID:",6)) {
+				l+=7;
+				while(l<length && fbuf[l]<=' ' && fbuf[l]>=0) l++;
+				m=l;
+				while(m<length && fbuf[m]!='\r') m++;
+				if(m>l)
+					smb_hfield(&msg,FIDOBBSID,(ushort)(m-l),fbuf+l);
+			}
+
 			else {		/* Unknown kludge line */
 				while(l<length && fbuf[l]<=' ' && fbuf[l]>=0) l++;
 				m=l;
@@ -4912,6 +4923,11 @@ void export_echomail(const char* sub_code, const nodecfg_t* nodecfg, bool rescan
 			if(msg.columns)
 				f += sprintf(fmsgbuf+f, "\1COLS: %u\r", (unsigned int)msg.columns);
 
+			if(msg.ftn_bbsid != NULL)	/* use original BBSID */
+				f += sprintf(fmsgbuf + f, "\1BBSID: %.256s\r", msg.ftn_bbsid);
+			else if(msg.from_net.type != NET_FIDO)
+				f += sprintf(fmsgbuf + f, "\1BBSID: %.256s\r", scfg.sys_id);
+
 			if(rescan)
 				f+=sprintf(fmsgbuf+f,"\1RESCANNED %s\r", smb_faddrtoa(&scfg.sub[subnum]->faddr,NULL));
 
diff --git a/src/smblib/smbdefs.h b/src/smblib/smbdefs.h
index 9210897a6a..89d195f53d 100644
--- a/src/smblib/smbdefs.h
+++ b/src/smblib/smbdefs.h
@@ -1,36 +1,21 @@
 /* Synchronet message base constant and structure definitions */
 
-/* $Id: smbdefs.h,v 1.119 2019/07/30 10:20:20 rswindell Exp $ */
-// vi: tabstop=4
-
 /****************************************************************************
  * @format.tab-size 4		(Plain Text/Source Code File Header)			*
  * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
  *																			*
  * Copyright Rob Swindell - http://www.synchro.net/copyright.html			*
  *																			*
- * This program is free software; you can redistribute it and/or			*
- * modify it under the terms of the GNU General Public License				*
+ * This library is free software; you can redistribute it and/or			*
+ * modify it under the terms of the GNU Lesser General Public License		*
  * as published by the Free Software Foundation; either version 2			*
  * of the License, or (at your option) any later version.					*
- * See the GNU General Public License for more details: gpl.txt or			*
- * http://www.fsf.org/copyleft/gpl.html										*
- *																			*
- * Anonymous FTP access to the most recent released source is available at	*
- * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net	*
- *																			*
- * Anonymous CVS access to the development source and modification history	*
- * is available at cvs.synchro.net:/cvsroot/sbbs, example:					*
- * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login			*
- *     (just hit return, no password is necessary)							*
- * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src		*
+ * See the GNU Lesser General Public License for more details: lgpl.txt or	*
+ * http://www.fsf.org/copyleft/lesser.html									*
  *																			*
  * For Synchronet coding style and modification guidelines, see				*
  * http://www.synchro.net/source.html										*
  *																			*
- * You are encouraged to submit any modifications (preferably in Unix diff	*
- * format) via e-mail to mods@synchro.net									*
- *																			*
  * Note: If this box doesn't appear square, then you need to fix your tabs.	*
  ****************************************************************************/
 
@@ -224,6 +209,7 @@
 #define FIDOFLAGS			0xa7
 #define FIDOTID 			0xa8
 #define FIDOCHARSET			0xa9	// CHRS or CHARSET control line
+#define FIDOBBSID			0xaa
 
 // RFC822* header field values are strings of US-ASCII chars, but potentially MIME-encoded (RFC2047)
 // (i.e. base64 or Q-encoded UTF-8, ISO-8859-1, etc.)
@@ -563,6 +549,7 @@ typedef struct {				/* Message */
 				*ftn_area,		/* FTN AREA */
 				*ftn_flags,		/* FTN FLAGS */
 				*ftn_charset,	/* FTN CHRS */
+				*ftn_bbsid,		/* FTN BBSID */
 				*ftn_msgid,		/* FTN MSGID */
 				*ftn_reply;		/* FTN REPLY */
 	char*		summary;		/* Summary  */
diff --git a/src/smblib/smblib.c b/src/smblib/smblib.c
index 552b02bfdb..a670a1262a 100644
--- a/src/smblib/smblib.c
+++ b/src/smblib/smblib.c
@@ -840,6 +840,9 @@ static void set_convenience_ptr(smbmsg_t* msg, uint16_t hfield_type, void* hfiel
 		case FIDOCHARSET:
 			msg->ftn_charset=(char*)hfield_dat;
 			break;
+		case FIDOBBSID:
+			msg->ftn_bbsid=(char*)hfield_dat;
+			break;
 		case RFC822HEADER:
 		{
 			char* p = (char*)hfield_dat;
diff --git a/src/smblib/smbstr.c b/src/smblib/smbstr.c
index fe99b82645..245f4ef402 100644
--- a/src/smblib/smbstr.c
+++ b/src/smblib/smbstr.c
@@ -81,6 +81,7 @@ char* SMBCALL smb_hfieldtype(uint16_t type)
 		case FIDOFLAGS:			return("X-FTN-Flags");
 		case FIDOTID:			return("X-FTN-TID");
 		case FIDOCHARSET:		return("X-FTN-CHRS");
+		case FIDOBBSID:			return("X-FTN-BBSID");
 
 		case RFC822HEADER:		return("OtherHeader");
 		case RFC822MSGID:		return("Message-ID");			/* RFC-compliant */
-- 
GitLab