From f4f043c71df74e3edeff573d7e5b7b37d504e92d Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Mon, 27 Nov 2017 06:30:33 +0000
Subject: [PATCH] Support the decoding/downloading of multiple MIME
 attachments.

---
 src/sbbs3/readmail.cpp | 11 +++++++----
 src/smblib/smblib.h    |  2 +-
 src/smblib/smbtxt.c    |  2 +-
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/sbbs3/readmail.cpp b/src/sbbs3/readmail.cpp
index 0235fcd7fc..9a5877acb6 100644
--- a/src/sbbs3/readmail.cpp
+++ b/src/sbbs3/readmail.cpp
@@ -269,15 +269,17 @@ void sbbs_t::readmail(uint usernumber, int which)
 					? 0:P_NOATCODES);
 
 			char* txt;
-			if((txt=smb_getmsgtxt(&smb,&msg, 0)) != NULL) {
+			int attachment_index = 0;
+			bool found = true;
+			while((txt=smb_getmsgtxt(&smb,&msg, 0)) != NULL && found) {
 				char filename[MAX_PATH+1] = {0};
 				uint32_t filelen = 0;
 				uint8_t* filedata;
-				if((filedata = smb_getattachment(&msg, txt, filename, &filelen)) != NULL 
+				if((filedata = smb_getattachment(&msg, txt, filename, &filelen, attachment_index++)) != NULL 
 					&& filename[0] != 0 && filelen > 0) {
 					char tmp[32];
 					sprintf(str3, text[DownloadAttachedFileQ], filename, ultoac(filelen,tmp));
-					if(yesno(str3)) {
+					if(!noyes(str3)) {
 						char fpath[MAX_PATH+1];
 						SAFEPRINTF2(fpath, "%s%s", cfg.temp_dir, filename);
 						FILE* fp = fopen(fpath, "wb");
@@ -292,7 +294,8 @@ void sbbs_t::readmail(uint usernumber, int which)
 								sendfile(fpath, useron.prot, "attachment");
 						}
 					}
-				}
+				} else
+					found = false;
 				smb_freemsgtxt(txt);
 			}
 
diff --git a/src/smblib/smblib.h b/src/smblib/smblib.h
index 007fe40fa5..bd43442317 100644
--- a/src/smblib/smblib.h
+++ b/src/smblib/smblib.h
@@ -273,7 +273,7 @@ SMBEXPORT void		SMBCALL smb_dump_msghdr(FILE* fp, smbmsg_t* msg);
 /* smbtxt.c */
 SMBEXPORT char*		SMBCALL smb_getmsgtxt(smb_t* smb, smbmsg_t* msg, ulong mode);
 SMBEXPORT char*		SMBCALL smb_getplaintext(smbmsg_t* msg, char* buf);
-SMBEXPORT uint8_t*	SMBCALL smb_getattachment(smbmsg_t* msg, char* buf, char* filename, uint32_t* filelen);
+SMBEXPORT uint8_t*	SMBCALL smb_getattachment(smbmsg_t* msg, char* buf, char* filename, uint32_t* filelen, int index);
 
 /* smbfile.c */
 SMBEXPORT int 		SMBCALL smb_feof(FILE* fp);
diff --git a/src/smblib/smbtxt.c b/src/smblib/smbtxt.c
index 225d316635..d0d1257450 100644
--- a/src/smblib/smbtxt.c
+++ b/src/smblib/smbtxt.c
@@ -440,7 +440,7 @@ uint8_t* SMBCALL smb_getattachment(smbmsg_t* msg, char* buf, char* filename, uin
 		if(result < 1)
 			return NULL;
 		*filelen = result;
-		return buf;
+		return (uint8_t*)buf;
 	}
 
 	return NULL;	/* No attachment */
-- 
GitLab