#include "mailfilter_def.h"
#ifdef WIN32
HINSTANCE ghIns;
#endif
char gszPathIniFile[LEN_MAX_PATH];
char gszPathLogFile[LEN_MAX_PATH];
char gszPathLogFileDefault[LEN_MAX_PATH];
char gszPathWork[LEN_MAX_PATH];
SERVICE_CFG gService_cfg;
DELIVER_CFG gDeliver_cfg;
DELIVER_OPTION gDeliver_option;
int gISINITED=0;
_MailFilterDeliver MailFilterDeliver=0;
PMAIL_ADDR gpNoFilterMailAddr=0;
const char RC_RPLY_EHLO[]=
"250-mailfilter copyright chendonghai\r\n"
"250 8BITMIME\r\n";
const char RC_RPLY_250OK[]="250 Ok\r\n";
const char RC_RPLY_354DATA[]="354 Start mail input;end with \"<CRLF>.<CRLF>\"\r\n";
const char RC_RPLY_221QUIT[]="221 mailfilter Service closing transmission channel\r\n";
const char RC_RPLY_504COMMANDERROR[]="504 mailfilter command error,Service closing transmission channel\r\n";
const char RC_RPLY_550BLOCK[]="550 %s\r\n";
const char RC_RPLY_421SRVERROR[]="421 %s\r\n";
const char RC_INI_SECTION_SERVER[]="server";
const char RC_INI_VAR_LOG_LEVEL[]="log_level";
const char RC_INI_VAR_WORK_PATH[]="work_path";
const char RC_INI_VAR_TIMEOUT_READ[]="timeout_read";
const char RC_INI_VAR_TIMEOUT_WRITE[]="timeout_write";
const char RC_INI_VAR_BIND_ADDR[]="bind_addr";
const char RC_INI_VAR_BANNER[]="banner";
const char RC_INI_VAR_IS_LOG_CONSOLE[]="is_log_console";
const char RC_INI_VAR_MAX_THREAD[]="max_thread";
const char RC_INI_VAR_LOG_FILE[]="log_file";
const char RC_INI_SECTION_DELIVER[]="deliver";
const char RC_INI_VAR_SOCKS5AGENT[]="socks5agent";
const char RC_INI_VAR_TRANS_ADDR[]="smtp_trans_addr";
const char RC_INI_VAR_EHLO_HOST[]="smtp_ehlo_host";
const char RC_INI_VAR_TIMEOUT_CONNECT[]="timeout_connect";
const char RC_INI_VAR_USE_PLUGIN[]="use_plugin";
const char RC_INI_VAR_DELIVER_MODULE[]="deliver_module";
const char RC_INI_VAR_DELIVER_FUNCTION[]="deliver_function";
const char RC_INI_VAR_NOTREMOVE_EML[]="notremove_tmp_eml";
char *ParseFilterReason(char *szReason)
{
int i=0;
if(!szReason)return 0;
for(i=0;szReason[i]==' '||szReason[i]=='-'||
szReason[i]=='\r'||szReason[i]=='\n'||
('0'<=szReason[i]&&szReason[i]<='9');i++);
if(i>0)
{
strcpyn_stop(szReason,szReason+i,_LEN_FILTER_REASON_,"\r\n");
}
else
{
for(i=0;szReason[i]!=0&&szReason[i]!='\r'&&szReason[i]!='\n';i++);
szReason[i]=0;
}
return szReason;
}
void DeliverInit()
{
char szValue[LEN_MAX_PATH];
DLL_HANDLE hDll;
if(!IniReadBool(RC_INI_SECTION_DELIVER,RC_INI_VAR_USE_PLUGIN,gszPathIniFile,0))
{
goto MY_END;
}
if(IniReadStr(RC_INI_SECTION_DELIVER,RC_INI_VAR_DELIVER_MODULE,szValue,LEN_MAX_PATH,gszPathIniFile)<1)
{
goto MY_END;
}
hDll=DllOpen(szValue,0);
if(!hDll)
{
MailFilterLog(_LOG_LEVEL_INFO,"can't open deliver plugin<%s>,use the default deliver\n",szValue);
goto MY_END;
}
if(IniReadStr(RC_INI_SECTION_DELIVER,RC_INI_VAR_DELIVER_FUNCTION,szValue,LEN_MAX_PATH,gszPathIniFile)<1)
{
MailFilterLog(_LOG_LEVEL_INFO,"var %s is empty.use the default deliver\n",RC_INI_VAR_DELIVER_FUNCTION);
DllClose(hDll);
goto MY_END;
}
MailFilterDeliver=(_MailFilterDeliver)DllSymbol(hDll,szValue);
if(!MailFilterDeliver)
{
MailFilterLog(_LOG_LEVEL_INFO,"not find exported function <%s>,at deliver module.use the default deliver\n",szValue);
DllClose(hDll);
goto MY_END;
}
return ;
MY_END:
MailFilterDeliver=DeliverSmtp;
return ;
}
void UnloadNoFilterMailAddr()
{
MailAddrListFree( gpNoFilterMailAddr);
gpNoFilterMailAddr=0;
}
int LoadNoFilterMailAddr()
{
int i=0;
char szTmpAddr[100];
PMAIL_ADDR pTmpAddr,*ppAddr;
MailAddrListFree( gpNoFilterMailAddr);
gpNoFilterMailAddr=0;
ppAddr=&gpNoFilterMailAddr;
while(IniReadIndex("nofilter",i,szTmpAddr,100,gszPathIniFile)>0)
{
pTmpAddr=MailAddrAlloc(szTmpAddr );
if(!pTmpAddr)break;
*ppAddr=pTmpAddr;
ppAddr=&(pTmpAddr->next);
i++;
}
return i;
}
int IsNoFilterMailAddr(const char *szMailAddr)
{
PMAIL_ADDR pMailAddr=gpNoFilterMailAddr;
if(!szMailAddr)return 1;
while(pMailAddr)
{
if(strcmpix(pMailAddr->szAddr,szMailAddr )==0)
{
MailFilterLog(_LOG_LEVEL_DEBUG,"%s is NoFilter\n",szMailAddr);
return 1;
}
pMailAddr=pMailAddr->next;
}
return 0;
}
void LoadCfg(void)
{
if(FileLength(gszPathIniFile)<0)
{
MailFilterLog(_LOG_LEVEL_INFO,"Mailfilter INI file<%s> is not exist\n",gszPathIniFile);
}
gService_cfg.nMaxThread=
IniReadInt(RC_INI_SECTION_SERVER,RC_INI_VAR_MAX_THREAD,gszPathIniFile,_MAX_WORK_THREADS_);
gService_cfg.IsLogConsole
=IniReadBool(RC_INI_SECTION_SERVER,RC_INI_VAR_IS_LOG_CONSOLE,gszPathIniFile,0);
gService_cfg.nPort=MAILFILTER_PORT;
IniReadStr(RC_INI_SECTION_SERVER,RC_INI_VAR_BIND_ADDR,gService_cfg.szBindIp,100,gszPathIniFile);
IniReadStr(RC_INI_SECTION_SERVER,RC_INI_VAR_BANNER,gService_cfg.szWelcomeTxt,500,gszPathIniFile);
if(gService_cfg.szWelcomeTxt[0]==0)
{
strcpyn(gService_cfg.szWelcomeTxt,"welcome to mailfilter copyrigght ChenDonghai",500);
}
gService_cfg.nLogLevel=IniReadInt(RC_INI_SECTION_SERVER,RC_INI_VAR_LOG_LEVEL,gszPathIniFile,0);
gService_cfg.TimeoutRead=
IniReadInt(RC_INI_SECTION_SERVER,RC_INI_VAR_TIMEOUT_READ,gszPathIniFile,60000);
gService_cfg.TimeoutWrite=
IniReadInt(RC_INI_SECTION_SERVER,RC_INI_VAR_TIMEOUT_WRITE,gszPathIniFile,60000);
if(gService_cfg.TimeoutRead==0)gService_cfg.TimeoutRead=60000;
if(gService_cfg.TimeoutWrite==0)gService_cfg.TimeoutWrite=60000;
IniReadStr(RC_INI_SECTION_SERVER,RC_INI_VAR_WORK_PATH,gszPathWork,LEN_MAX_PATH,gszPathIniFile);
if(gszPathWork[0]==0)
{
#if defined(WIN32)
#ifdef _DEBUG
GetModuleFileNameA(GetModuleHandleA("mailfilterD.dll"),gszPathWork,LEN_MAX_PATH-20);
#else
GetModuleFileNameA(GetModuleHandleA("mailfilter.dll"),gszPathWork,LEN_MAX_PATH-20);
#endif
ChopPathFileName(gszPathWork);
#else
strcpyn(gszPathWork,gszPathIniFile,LEN_MAX_PATH);
ChopPathFileName(gszPathWork );
#endif
}
PathAddSlash(gszPathWork);
MakeDirRecur(gszPathWork);
/**************************load deliver cfg*********************************************************/
IniReadStr(RC_INI_SECTION_DELIVER,RC_INI_VAR_SOCKS5AGENT,gDeliver_cfg.szSocks5Agent,100,gszPathIniFile);
IniReadStr(RC_INI_SECTION_DELIVER,RC_INI_VAR_TRANS_ADDR,gDeliver_cfg.szAddr,100,gszPathIniFile);
IniReadStr(RC_INI_SECTION_DELIVER,RC_INI_VAR_EHLO_HOST,gDeliver_cfg.szEhloHost,100,gszPathIniFile);
if(gDeliver_cfg.szEhloHost[0]==0)
{
RDE_GetHostName(gDeliver_cfg.szEhloHost,100);
if(gDeliver_cfg.szEhloHost[0]==0)
{
strcpyx(gDeliver_cfg.szEhloHost,"mailfilter");
}
}
gDeliver_cfg.nTimeoutConnect=
IniReadInt(RC_INI_SECTION_DELIVER,RC_INI_VAR_TIMEOUT_CONNECT,gszPathIniFile,6000);
gDeliver_cfg.nTimeoutRead=
IniReadInt(RC_INI_SECTION_DELIVER,RC_INI_VAR_TIMEOUT_READ,gszPathIniFile,6000);
gDeliver_cfg.nTimeoutWrite=
IniReadInt(RC_INI_SECTION_DELIVER,RC_INI_VAR_TIMEOUT_WRITE,gszPathIniFile,6000);
if(gDeliver_cfg.nTimeoutWrite==0)gDeliver_cfg.nTimeoutWrite=60000;
if(gDeliver_cfg.nTimeoutRead==0)gDeliver_cfg.nTimeoutRead=60000;
if(gDeliver_cfg.nTimeoutConnect==0)gDeliver_cfg.nTimeoutConnect=6000;
gDeliver_cfg.IsNotRemoveEmlFile=
IniReadBool(RC_INI_SECTION_DELIVER,RC_INI_VAR_NOTREMOVE_EML,gszPathIniFile,0);
}
int MYAPI MailFilterLog(int nLevel,const char *fmt, ...)
{
va_list args;
FILE *pFile;
INT_THREADID threadId;
char szTime[22];
threadId=ThreadGetID();
if(nLevel>gService_cfg.nLogLevel)
{
return 0;
}
DateTimeNowStr(szTime,FALSE,FALSE);
pFile=fopen(gszPathLogFile,"a");
if(!pFile)
{
return 0;
}
va_start(args, fmt);
fprintf(pFile,"%s,%u,%s,",szTime,threadId,LogLevelStr(nLevel));
vfprintf(pFile,fmt,args);
va_end(args);
/////////////////////////
fclose(pFile);
if(gService_cfg.IsLogConsole)
{
va_start(args, fmt);
printf("%s,%u,%s,",szTime,threadId,LogLevelStr(nLevel));
vprintf(fmt,args);
va_end(args);
}
return 1;
}
int ReadMailDataFromClient(PFILTER_SESSION pSession)
{
int nReaded=0,nReadedSum=0,i,nBufLen;
FILE_HANDLE hFile;
char *pBuf=pSession->pBuf;
#define LEN_PRE_BUF 28
#define LEN_PRE_BUF_HALF 12
char szPreBuf[LEN_PRE_BUF]
没有合适的资源?快使用搜索试试~ 我知道了~
邮件过滤器代码c/c++
共8个文件
c:4个
makefiled:1个
def:1个
5星 · 超过95%的资源 需积分: 13 29 下载量 25 浏览量
2010-08-11
12:17:23
上传
评论 1
收藏 11KB ZIP 举报
温馨提示
邮件过滤器代码c/c++ int ReadMailDataFromClient(PFILTER_SESSION pSession) { int nReaded=0,nReadedSum=0,i,nBufLen; FILE_HANDLE hFile; char *pBuf=pSession->pBuf; #define LEN_PRE_BUF 28 #define LEN_PRE_BUF_HALF 12 char szPreBuf[LEN_PRE_BUF]; int nPreLen=0; int nDotPos=0; nBufLen=pSession->nBufMaxLen-1; hFile=FileOpenXX2(pSession->pszMailFile,O_CREAT|O_TRUNC|O_RDWR); if(hFile==FILE_HANDLE_INVALID)return -1;
资源推荐
资源详情
资源评论
收起资源包目录
src.zip (8个子文件)
mailfilter_api.c 3KB
mailfilter_def.h 2KB
mailfilter.def 435B
mailfilter_smtp.c 6KB
mailfilter.c 21KB
MakefileD 886B
Makefile 931B
mailfilter_plugin.c 4KB
共 8 条
- 1
资源评论
- yangxinyu20602014-04-25只是参考了一下。
- ryf85082013-03-04做毕设的时候参考过,感觉挺不错,因为题目就是这类的过滤程序。
OpenNVR
- 粉丝: 11
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功