linux 上http email 协议分析程序 主要能够处理大数据量的主干网的应用

源代码在线查看: emailapp.cpp

软件大小: 599 K
上传用户: red2years
关键词: linux email http 协议分析
下载地址: 免注册下载 普通下载 VIP

相关代码

				#include 				#include 				#include 				#include "Emailapp.h"								void CemailApp::run()				{					//printf("to getstream \n");					if(m_theStream->getStream())					{						printf("to getProtocol\n");						switch(m_theStream->getProtocol())						{						//case SMTP_PORT:						case DST_SMTP:							printf("smtp ------------------\n");							m_theStream->saveFile();							smtpProcess();							break;						case SRC_SMTP:							printf("smtp resp------------------\n");							m_theStream->saveFile();							break;												case DST_POP3:							printf("pop3 auth------------------\n");							m_theStream->saveFile();							break;										case SRC_POP3:							printf("pop3 ------------------\n");							m_theStream->saveFile();							pop3Process();							break;												case DST_HTTP:														break;													case SRC_HTTP:							printf("http ------------------\n");							//m_theStream->saveFile();							//httpProcess();							break;						default:							printf("unkown ------------------\n");							break;						}						printf("end of processing protocol\n");					}										}								//可以根据报文大小来判断是不是邮件				//与服务器间的命令不用解释								void CemailApp::smtpProcess()				{					//如果一个连接中发多个邮件,要加一个循环									while(1)					{						char szbuf[1024];						if(m_theStream->getLine(szbuf)>0)						{							if(!strcmp(szbuf,"DATA"))								break;						}						else							return;					}									//下面是邮件部分,										if(!m_theEmail->setHeader(m_theStream))						return;					#ifdef DEBUG					m_theEmail->showHeader();					#endif										switch(m_theEmail->getMsgType(m_theEmail->m_EmailField))					{					case type_text:						printf("this is onepart email\n");						m_theEmail->deOnePart(m_theStream,m_theInfo);						break;										case type_multipart:						char szbd[128];						printf("this is multipart email\n");						if(m_theEmail->getBoudary(szbd))						{							printf("bound=[%s]\n",szbd);							m_theStream->posBoudary(szbd);							while(m_theEmail->posSingleHead(m_theStream))								{								if(m_theEmail->deBodyPart(m_theStream,m_theInfo))									break;							}						}										break;												case type_image:					case type_audio:					case type_video:					case type_application:					case type_message:					case type_err:					case type_unknown:						break;					}				}								//				//POP3判断邮件需要识别邮件头部信息				void CemailApp::pop3Process()				{					#ifdef DEBUG						int imailid=0;					#endif					while(1)					{						#ifdef DEBUG							printf("--------------------------------------------------------------------\n");							printf("to prcess no(%d) mail\n",imailid++);							printf("--------------------------------------------------------------------\n");							//getchar();						#endif						while(1)						{							char szline[1024];							int len=m_theStream->getLine(szline);							if(len								return;													int i=m_theEmail->isofEmailHead(szline);							if(i								return;							if(i>0)								break;						}											//下面是邮件部分,											if(!m_theEmail->setHeader(m_theStream))							return;						#ifdef DEBUG							m_theEmail->showHeader();						#endif						switch(m_theEmail->getMsgType(m_theEmail->m_EmailField))						{						case type_text:							printf("this is onepart email(pop3)\n");							m_theEmail->deOnePart(m_theStream,m_theInfo);							break;											case type_multipart:							char szbd[128];							printf("this is multipart email(pop3)\n");							if(m_theEmail->getBoudary(szbd))							{								m_theStream->posBoudary(szbd);								//								while(m_theEmail->posSingleHead(m_theStream))								{									//分析到达第一个非multipart 邮件体									if(m_theEmail->deBodyPart(m_theStream,m_theInfo))										break;								}							}							break;													case type_image:						case type_audio:						case type_video:						case type_application:						case type_message:						case type_err:						case type_unknown:							break;						}					}								}								void CemailApp::httpProcess()				{					//查找空行,空行后面是html文本					while(1)					{						char szbuf[1024];						int len;						len=m_theStream->getLine(szbuf);										if(len==0)						{							break;						}						if(len							return;					}										//html 文本部分												}								CemailApp::CemailApp()				{					int isizebuf=10*1024*1024;									m_theInfo=new Cinfo(isizebuf);					m_theStream=new Cmimestream(isizebuf);					m_theEmail=new Cemail();				}								CemailApp::~CemailApp()				{					delete m_theInfo ;					delete m_theStream;					delete m_theEmail;				}							

相关资源