From 11ec032636eaa84122a36329531755ec706612ed Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Sun, 18 May 2003 03:51:01 +0000
Subject: [PATCH] Moved C-exported functions in mail.cpp to new file,
 getmail.c.

---
 src/sbbs3/mail.cpp | 135 +--------------------------------------------
 src/sbbs3/sbbs.h   |   3 +-
 2 files changed, 3 insertions(+), 135 deletions(-)

diff --git a/src/sbbs3/mail.cpp b/src/sbbs3/mail.cpp
index 7ccac4cff7..ad962041e5 100644
--- a/src/sbbs3/mail.cpp
+++ b/src/sbbs3/mail.cpp
@@ -8,7 +8,7 @@
  * @format.tab-size 4		(Plain Text/Source Code File Header)			*
  * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
  *																			*
- * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html		*
+ * Copyright 2003 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				*
@@ -37,84 +37,6 @@
 
 #include "sbbs.h"
 
-/****************************************************************************/
-/* Returns the number of pieces of mail waiting for usernumber              */
-/* If sent is non-zero, it returns the number of mail sent by usernumber    */
-/* If usernumber is 0, it returns all mail on the system                    */
-/****************************************************************************/
-int DLLCALL getmail(scfg_t* cfg, int usernumber, BOOL sent)
-{
-    char    str[128];
-    int     i=0;
-    long    l;
-    idxrec_t idx;
-	smb_t	smb;
-
-	sprintf(smb.file,"%smail",cfg->data_dir);
-	smb.retry_time=cfg->smb_retry_time;
-	sprintf(str,"%s.sid",smb.file);
-	l=flength(str);
-	if(l<(long)sizeof(idxrec_t))
-		return(0);
-	if(!usernumber) 
-		return(l/sizeof(idxrec_t)); 	/* Total system e-mail */
-	smb.subnum=INVALID_SUB;
-	if(smb_open(&smb)!=0) 
-		return(0); 
-	while(!smb_feof(smb.sid_fp)) {
-		if(smb_fread(&idx,sizeof(idx),smb.sid_fp) != sizeof(idx))
-			break;
-		if(idx.number==0)	/* invalid message number, ignore */
-			continue;
-		if(idx.attr&MSG_DELETE)
-			continue;
-		if((!sent && idx.to==usernumber)
-		 || (sent && idx.from==usernumber))
-			i++; 
-	}
-	smb_close(&smb);
-	return(i);
-}
-
-
-/***************************/
-/* Delete file attachments */
-/***************************/
-extern "C" void DLLCALL delfattach(scfg_t* cfg, smbmsg_t* msg)
-{
-    char str[MAX_PATH+1];
-	char str2[MAX_PATH+1];
-	char *tp,*sp,*p;
-
-	if(msg->idx.to==0) {	/* netmail */
-		sprintf(str,"%sfile/%04u.out/%s"
-			,cfg->data_dir,msg->idx.from,getfname(msg->subj));
-		remove(str);
-		sprintf(str,"%sfile/%04u.out"
-			,cfg->data_dir,msg->idx.from);
-		rmdir(str);
-		return;
-	}
-		
-	strcpy(str,msg->subj);
-	tp=str;
-	while(1) {
-		p=strchr(tp,SP);
-		if(p) *p=0;
-		sp=strrchr(tp,'/');              /* sp is slash pointer */
-		if(!sp) sp=strrchr(tp,'\\');
-		if(sp) tp=sp+1;
-		sprintf(str2,"%sfile/%04u.in/%s"  /* str2 is path/fname */
-			,cfg->data_dir,msg->idx.to,tp);
-		remove(str2);
-		if(!p)
-			break;
-		tp=p+1; }
-	sprintf(str,"%sfile/%04u.in",cfg->data_dir,msg->idx.to);
-	rmdir(str);                     /* remove the dir if it's empty */
-}
-
-
 /****************************************************************************/
 /* Deletes all mail messages for usernumber that have been marked 'deleted' */
 /* smb_locksmbhdr() should be called prior to this function 				*/
@@ -223,61 +145,6 @@ void sbbs_t::telluser(smbmsg_t* msg)
 		putsmsg(&cfg,usernumber,str); }
 }
 
-/****************************************************************************/
-/* Loads mail waiting for user number 'usernumber' into the mail array of   */
-/* of pointers to mail_t (message numbers and attributes)                   */
-/* smb_open(&smb) must be called prior										*/
-/****************************************************************************/
-mail_t* DLLCALL loadmail(smb_t* smb, ulong* msgs, uint usernumber
-			   ,int which, long mode)
-{
-	ulong		l=0;
-    idxrec_t    idx;
-	mail_t*		mail=NULL;
-
-	if(msgs==NULL)
-		return(NULL);
-
-	*msgs=0;
-
-	if(smb==NULL)
-		return(NULL);
-
-	if(smb_locksmbhdr(smb)!=0)  				/* Be sure noone deletes or */
-		return(NULL);							/* adds while we're reading */
-
-	smb_rewind(smb->sid_fp);
-	while(!smb_feof(smb->sid_fp)) {
-		if(smb_fread(&idx,sizeof(idx),smb->sid_fp) != sizeof(idx))
-			break;
-		if(idx.number==0)	/* invalid message number, ignore */
-			continue;
-		if((which==MAIL_SENT && idx.from!=usernumber)
-			|| (which==MAIL_YOUR && idx.to!=usernumber)
-			|| (which==MAIL_ANY && idx.from!=usernumber && idx.to!=usernumber))
-			continue;
-		if(idx.attr&MSG_DELETE && !(mode&LM_INCDEL))	/* Don't included deleted msgs */
-			continue;					
-		if(mode&LM_UNREAD && idx.attr&MSG_READ)
-			continue;
-		if((mail=(mail_t *)REALLOC(mail,sizeof(mail_t)*(l+1)))
-			==NULL) {
-			smb_unlocksmbhdr(smb);
-			return(NULL); 
-		}
-		mail[l]=idx;
-		l++; 
-	}
-	smb_unlocksmbhdr(smb);
-	*msgs=l;
-	return(mail);
-}
-
-extern "C" void DLLCALL freemail(mail_t* mail)
-{
-	FREE(mail);
-}
-
 /************************************************************************/
 /* Deletes all mail waiting for user number 'usernumber'                */
 /************************************************************************/
diff --git a/src/sbbs3/sbbs.h b/src/sbbs3/sbbs.h
index 997e0bd707..511a8997d6 100644
--- a/src/sbbs3/sbbs.h
+++ b/src/sbbs3/sbbs.h
@@ -750,12 +750,13 @@ extern "C" {
 	/* main.cpp */
 	DLLEXPORT BOOL		DLLCALL getstats(scfg_t* cfg, char node, stats_t* stats);
 
-	/* mail.cpp */
+	/* getmail.c */
 	DLLEXPORT int		DLLCALL getmail(scfg_t* cfg, int usernumber, BOOL sent);
 	DLLEXPORT mail_t *	DLLCALL loadmail(smb_t* smb, ulong* msgs, uint usernumber
 										,int which, long mode);
 	DLLEXPORT void		DLLCALL freemail(mail_t* mail);
 	DLLEXPORT void		DLLCALL delfattach(scfg_t*, smbmsg_t*);
+
 	/* postmsg.cpp */
 	DLLEXPORT int		DLLCALL savemsg(scfg_t* cfg, smb_t* smb, smbmsg_t* msg, char* msgbuf);
 	DLLEXPORT void		DLLCALL signal_sub_sem(scfg_t* cfg, uint subnum);
-- 
GitLab