www.pudn.com > antispam-addin.rar > databasemgr.cxx


#include "unihead.hxx" 
 
#include "databasemgr.hxx" 
 
#define AUTHENTIC_DB_LEN	2048 
 
DatabaseMgr::DatabaseMgr(Configure *pConfigure) 
{ 
	fpAuthentic = fopen(pConfigure->getAuthenticDir(),"a+"); 
	SpoolDir = pConfigure->getSpoolDir(); 
} 
 
DatabaseMgr::~DatabaseMgr() 
{ 
	if(fpAuthentic) 
		fclose(fpAuthentic); 
} 
 
bool DatabaseMgr::GetSpoolMail(char *pszAuthCode,char *originalMail,int &Len) 
{ 
	char szFile[128]; 
	sprintf(szFile,"%s/%s",SpoolDir,pszAuthCode); 
 
	FILE *fp = fopen(szFile,"r"); 
	Len = fread(originalMail,1,Len,fp); 
	fclose(fp); 
 
	return true; 
} 
 
bool DatabaseMgr::InsertIntoAuthenticDB(AuthenticItem* pAuthenticItem) 
{ 
	char szTemp[] = "\r\n"; 
	fwrite(pAuthenticItem->getAddress(),1,strlen(pAuthenticItem->getAddress()),fpAuthentic); 
	fwrite(szTemp,1,strlen(szTemp),fpAuthentic); 
 
	fflush(fpAuthentic); 
 
	return true; 
} 
 
bool DatabaseMgr::IsAuthenticSender(char *pszAddress) 
{ 
	char TempDB[AUTHENTIC_DB_LEN]; 
	memset(TempDB,0,AUTHENTIC_DB_LEN); 
 
	fread(TempDB,1,AUTHENTIC_DB_LEN,fpAuthentic); 
 
	if(!strstr(TempDB,pszAddress)) 
	{ 
		return false; 
	} 
 
	return true; 
} 
 
bool DatabaseMgr::IsSpoolSender(char *pszSubject) 
{ 
	char szFile[128]; 
	sprintf(szFile,"%s/%s",SpoolDir,pszSubject); 
 
	FILE *fp = fopen(szFile,"r"); 
	if(!fp) 
	{ 
		return false; 
	} 
 
	fclose(fp); 
 
	return true; 
} 
 
void DatabaseMgr::Spool(char *pszAuthCode,char *pszMail) 
{ 
	char szFile[128]; 
	sprintf(szFile,"%s/%s",SpoolDir,pszAuthCode); 
	FILE *fp = fopen(szFile,"w"); 
	fwrite(pszMail,1,strlen(pszMail),fp); 
	fclose(fp); 
} 
 
AuthenticItem* DatabaseMgr::Search(char *pszAddress) 
{ 
	AuthenticItem* pTemp = NULL; 
 
	return pTemp; 
}