From b304564ea059dd0fb3933aa7042698e970f75fc5 Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Wed, 15 Nov 2017 10:16:52 +0000
Subject: [PATCH] When toggling SPAM visibility, go to the first msg, not the
 last.

---
 src/sbbs3/readmail.cpp | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/sbbs3/readmail.cpp b/src/sbbs3/readmail.cpp
index 6e966e9881..5b0f2328ef 100644
--- a/src/sbbs3/readmail.cpp
+++ b/src/sbbs3/readmail.cpp
@@ -229,12 +229,16 @@ void sbbs_t::readmail(uint usernumber, int which)
 			mail=loadmail(&smb,&smb.msgs,usernumber,which,lm_mode);   /* So re-load */
 			if(!smb.msgs)
 				break;
+			if(lm_mode != last_mode)
+				smb.curmsg = 0;
+			else {
+				for(smb.curmsg=0;smb.curmsg<smb.msgs;smb.curmsg++)
+					if(mail[smb.curmsg].number==msg.idx.number)
+						break;
+				if(smb.curmsg>=smb.msgs)
+					smb.curmsg=(smb.msgs-1);
+			}
 			last_mode = lm_mode;
-			for(smb.curmsg=0;smb.curmsg<smb.msgs;smb.curmsg++)
-				if(mail[smb.curmsg].number==msg.idx.number)
-					break;
-			if(smb.curmsg>=smb.msgs)
-				smb.curmsg=(smb.msgs-1);
 			continue; 
 		}
 
@@ -764,12 +768,12 @@ void sbbs_t::readmail(uint usernumber, int which)
 			case 'V':	/* View SPAM (toggle) */
 			{
 				domsg = false;
-				int spam = getmail(&cfg, usernumber, /* Sent: */FALSE, /* SPAM-ONLY */TRUE);
+				int spam = getmail(&cfg, usernumber, /* Sent: */FALSE, /* attr: */MSG_SPAM);
 				if(!spam) {
 					bprintf(text[NoMailWaiting], "SPAM");
 					break;
 				}
-				if(spam >= getmail(&cfg, usernumber, /* Sent: */FALSE, /* SPAM-ONLY */FALSE)) {
+				if(spam >= getmail(&cfg, usernumber, /* Sent: */FALSE, /* attr: */0)) {
 					bprintf(text[NoMailWaiting], "HAM");
 					break;
 				}
-- 
GitLab