From 459893f5f0ffe3b110628653944a38a2cfbcb51a Mon Sep 17 00:00:00 2001
From: Rob Swindell <rob@synchro.net>
Date: Fri, 22 Jan 2021 18:22:30 -0800
Subject: [PATCH] Fix bug introduced in e9f56e5d - line endings stripped from
 rx'd mail

An unrelated optimization (elimination of an unnecessary use of fprintf) resulted in a new bug that combined all lines from SMTP-received mail messages into a single long line, thus breaking all decoding ability of multi-part MIME messages (where blank lines are significant).

Went ahead and replaced some other unnecessary uses of fprintf(), replaces with fputs() while at it.
---
 src/sbbs3/mailsrvr.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/sbbs3/mailsrvr.c b/src/sbbs3/mailsrvr.c
index 5bde6041fd..52ec93bee6 100644
--- a/src/sbbs3/mailsrvr.c
+++ b/src/sbbs3/mailsrvr.c
@@ -4006,7 +4006,7 @@ static void smtp_thread(void* arg)
 				state=SMTP_STATE_DATA_BODY;	/* Null line separates header and body */
 				lines=0;
 				if(msgtxt!=NULL) {
-					fprintf(msgtxt, "\r\n");
+					fputs("\r\n", msgtxt);
 					hdr_len=ftell(msgtxt);
 				}
 				continue;
@@ -4016,6 +4016,7 @@ static void smtp_thread(void* arg)
 				if(*p=='.') p++;	/* Transparency (RFC821 4.5.2) */
 				if(msgtxt!=NULL) {
 					fputs(p, msgtxt);
+					fputs("\r\n", msgtxt);
 				}
 				lines++;
 				/* release time-slices every x lines */
@@ -4044,8 +4045,10 @@ static void smtp_thread(void* arg)
 				}
 			}
 
-			if(msgtxt!=NULL) 
-				fprintf(msgtxt, "%s\r\n", buf);
+			if(msgtxt!=NULL) {
+				fputs(buf, msgtxt);
+				fputs("\r\n", msgtxt);
+			}
 			hdr_lines++;
 			continue;
 		}
-- 
GitLab