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

📄 maildecoder.h

📁 .net 方面的开发说明资料。
💻 H
字号:
// =============================================================
// Multi-Purpose Internet Mail Extensions decoder
//
// Purpose: converts a mime encoded e-mail message from
//          a string and converts to a tree structure.
//
// This file is part of Eplug
//
// Copyright (c) 2002 - 2003 Pylon Software
// =============================================================

#ifndef MAILDECODER_H
#define MAILDECODER_H

#ifndef _STRING_
#include <string>
#endif

#ifndef _VECTOR_
#include <vector>
#endif

// -------------------------------------------------------------

enum MimeEnum {
	MIME_UNKNOWN,
	MIME_RETURNPATH,
	MIME_MESSAGEID,
	MIME_FROM,
	MIME_TO,
	MIME_CC,
	MIME_SUBJECT,
	MIME_DATE,
	MIME_VERSION,
	MIME_CONTENTTYPE,
	MIME_CONTENTTRANSFERENCODING,
	MIME_CONTENTDISPOSITION,
};

struct Mime {
	std::string m_s;
	MimeEnum m_mime;

	Mime(const std::string &s, MimeEnum mime) :
	m_s(s),
	m_mime(mime) {
	}
};

struct BlockHeading {
	std::string m_return_path;
	std::string m_message_id;
	std::string m_from;
	std::string m_to;
	std::string m_cc;
	std::string m_subject;
	std::string m_mime_version;
	std::string m_date;
	std::string m_content_type;
	std::string m_content_encoding;
	std::string m_content_disposition;
	std::string m_boundary;
	std::string m_charset;
	std::string m_filename;
};

struct MailBlock {
	BlockHeading heading;
	std::string content;
};

struct MailSection {
	MailSection *parent;
	std::vector<MailSection *> children;
	std::vector<MailBlock *> content;

	~MailSection() {
		for (unsigned i = 0; i < content.size(); ++i)
			delete content[i];

		for (unsigned j = 0; j < children.size(); ++j)
			delete children[j];
	}
};

// -------------------------------------------------------------

class MailDecoder {
public :
	MailDecoder();
	bool open(std::string mail_content);
	void close();
	~MailDecoder();

private :
	void BeginSection();
	void EndSection();
	void NewBlock();
	void SkipWhite();
	void CopyHeading(BlockHeading &a, BlockHeading &b);

private :
	MimeEnum MatchMimeString(std::string s);
	std::string GetFieldName();
	std::string GatherParameters();
	std::string DeQuoteString(std::string &s);
	std::string ReadLine();
	void DecodeHeadingSection(BlockHeading &heading);
	void DecodeMailSection(BlockHeading &heading);
	void DecodeParameters(MimeEnum mime, std::string &params, BlockHeading &heading, std::string *attribute);

private :
	void LogMailContents();
	void LogMailContents(FILE *f, MailSection *block);

private :
	std::string m_raw_text;
	unsigned m_pos;
	unsigned m_section_pos;
	MailSection *m_decoded;
	MailSection *m_current_section;
	MailBlock *m_current_block;
};

#endif //!MAILDECODER_H

⌨️ 快捷键说明

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