⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 解析email的源代码。 mine协议 解码译码
💻 CPP
字号:
#include "email.h"
#include <iostream>
#include <fstream>
#include <string>
#include "windows.h"
using namespace std;

void get(mail_node* b);
void getcontent(mail a);
vector<string> GetAllNewMail(string mailDir);
ofstream ofile("D:\\result.txt");

void main()
{
	cout<<"输入文件夹路径..."<<endl;
	string mailDir,name;
	cin>>mailDir;
	vector<string> vs;
	vs=GetAllNewMail(mailDir);
	for(int i=0; i<vs.size(); i++)
	{
		string filename;
		mail mail1;	
		filename=vs.at(i).c_str();
		name=mail1.getfile((mailDir+"\\"+filename).c_str());
		mail1.load(name.c_str());
		ofile<<"-----------------------------------"<<endl;
		ofile<<"主题:"<<mail1.getSubject()<<endl;
		ofile<<"发件人:"<<mail1.getFrom()<<endl;
		ofile<<"收件人:"<<mail1.getTo()<<endl;
		getcontent(mail1);
		ofile<<"-----------------------------------";
		ofile<<endl<<endl;
	}
	ofile.close();

	/*
	while(1)
	{
	string filename;
	cout<<"输入文件名:";
	cin>>filename;
	if(filename=="exit")
		return;
	cout<<endl;
	mail mail1;	
	mail1.load(mail1.getfile(filename.c_str()).c_str());
	cout<<"主题:"<<mail1.getSubject()<<endl;
	cout<<"发件人:"<<mail1.getFrom()<<endl;
	cout<<"收件人:"<<mail1.getTo()<<endl;
	getcontent(mail1);
	cout<<endl<<endl<<endl<<endl;
	}
	*/
}
//	cout<<"输入文件夹路径..."<<endl;
/*	string mailDir,name;
	cin>>mailDir;
	vector<string> vs;
	vs=GetAllNewMail(mailDir);
	for(int i=0; i<vs.size(); i++)
	{
		string filename;
		mail mail1;	
		filename=vs.at(i).c_str();
		name=mail1.getfile((mailDir+"\\"+filename).c_str());
		mail1.load(name.c_str());
		getcontent(mail1);
	}
	ofile.close();*/


vector<string> GetAllNewMail(string mailDir)
{
	vector<string> MailVec;
	int num=0;
	string tempfile;
	WIN32_FIND_DATA FindFileData;
	HANDLE hFind;
	BOOL result,fFinished = FALSE;
	string strPath = mailDir+"\\";
	string strFileEx;
	strFileEx = strPath+"*.eml";
	hFind = FindFirstFile( strFileEx.c_str(),&FindFileData );
	if( hFind == INVALID_HANDLE_VALUE )
		cerr<<"Error: there is no .txt files in this directory!"<<endl;
	else
	{
		num++;
		tempfile = FindFileData.cFileName;
		MailVec.push_back( tempfile );
	}
	while( !fFinished )
	{
		result = FindNextFile( hFind, &FindFileData );
		if( !result )
		{			
			if (GetLastError() == ERROR_NO_MORE_FILES) 
			{								
				cout<<"There are total "<<num<<" new mail to classify!"<<endl;
				fFinished = TRUE; 
			} 
			else 
			{ 
				cerr<<"Couldn't find next file."<<endl; 
			} 
		}
		else
		{
			num++;
			tempfile = FindFileData.cFileName;
			MailVec.push_back( tempfile );
		}
	}
	return MailVec;
} 

void getcontent(mail a)
{
	for(int i=0; i<a.getMail_nodes().size(); i++)
	{
		get(a.getMail_nodes().at(i));
	}
}

void get(mail_node* b)
{
	if(b)
	{
		for(int i=0; i<b->getMail_nodes().size(); i++)
		{
			get(b->getMail_nodes().at(i));
		}
		if(!b->getUncodeContent().empty())
			ofile<<b->getUncodeContent();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -