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

📄 imapparser.hpp

📁 MIME解析的代码
💻 HPP
📖 第 1 页 / 共 5 页
字号:
		~continue_req()		{			delete (m_resp_text);		}		void go(IMAPParser& parser, string& line, string::size_type* currentPos)		{			DEBUG_ENTER_COMPONENT("continue_req");			string::size_type pos = *currentPos;			parser.check <one_char <'+'> >(line, &pos);			parser.check <SPACE>(line, &pos);			m_resp_text = parser.get <IMAPParser::resp_text>(line, &pos);			parser.check <CRLF>(line, &pos);			*currentPos = pos;		}	private:		IMAPParser::resp_text* m_resp_text;	public:		const IMAPParser::resp_text* resp_text() const { return (m_resp_text); }	};	//	// auth_type ::= atom	//               ;; Defined by [IMAP-AUTH]	//	class auth_type : public component	{	public:		void go(IMAPParser& parser, string& line, string::size_type* currentPos)		{			DEBUG_ENTER_COMPONENT("auth_type");			atom* at = parser.get <atom>(line, currentPos);			m_name = utility::stringUtils::toLower(at->value());			delete (at);			if (m_name == "kerberos_v4")				m_type = KERBEROS_V4;			else if (m_name == "gssapi")				m_type = GSSAPI;			else if (m_name == "skey")				m_type = SKEY;			else				m_type = UNKNOWN;		}		enum Type		{			UNKNOWN,			// RFC 1731 - IMAP4 Authentication Mechanisms			KERBEROS_V4,			GSSAPI,			SKEY		};	private:		Type m_type;		string m_name;	public:		Type type() const { return (m_type); }		const string name() const { return (m_name); }	};	//	// status_att ::= "MESSAGES" / "RECENT" / "UIDNEXT" /	//                "UIDVALIDITY" / "UNSEEN"	//	class status_att : public component	{	public:		void go(IMAPParser& parser, string& line, string::size_type* currentPos)		{			DEBUG_ENTER_COMPONENT("status_att");			string::size_type pos = *currentPos;			if (parser.checkWithArg <special_atom>(line, &pos, "messages", true))			{				m_type = MESSAGES;			}			else if (parser.checkWithArg <special_atom>(line, &pos, "recent", true))			{				m_type = RECENT;			}			else if (parser.checkWithArg <special_atom>(line, &pos, "uidnext", true))			{				m_type = UIDNEXT;			}			else if (parser.checkWithArg <special_atom>(line, &pos, "uidvalidity", true))			{				m_type = UIDVALIDITY;			}			else			{				parser.checkWithArg <special_atom>(line, &pos, "unseen");				m_type = UNSEEN;			}			*currentPos = pos;		}		enum Type		{			MESSAGES,			RECENT,			UIDNEXT,			UIDVALIDITY,			UNSEEN		};	private:		Type m_type;	public:		Type type() const { return (m_type); }	};	//	// capability ::= "AUTH=" auth_type / atom	//                ;; New capabilities MUST begin with "X" or be	//                ;; registered with IANA as standard or standards-track	//	class capability : public component	{	public:		capability()			: m_auth_type(NULL), m_atom(NULL)		{		}		~capability()		{			delete (m_auth_type);			delete (m_atom);		}		void go(IMAPParser& parser, string& line, string::size_type* currentPos)		{			DEBUG_ENTER_COMPONENT("capability");			string::size_type pos = *currentPos;			class atom* at = parser.get <IMAPParser::atom>(line, &pos);			string value = at->value();			const char* str = value.c_str();			if ((str[0] == 'a' || str[0] == 'A') &&			    (str[1] == 'u' || str[1] == 'U') &&			    (str[2] == 't' || str[2] == 'T') &&			    (str[3] == 'h' || str[3] == 'H') &&			    (str[4] == '='))			{				string::size_type pos = 5;				m_auth_type = parser.get <IMAPParser::auth_type>(value, &pos);				delete (at);			}			else			{				m_atom = at;			}			*currentPos = pos;		}	private:		IMAPParser::auth_type* m_auth_type;		IMAPParser::atom* m_atom;	public:		const IMAPParser::auth_type* auth_type() const { return (m_auth_type); }		const IMAPParser::atom* atom() const { return (m_atom); }	};	//	// capability_data ::= "CAPABILITY" SPACE [1#capability SPACE] "IMAP4rev1"	//                     [SPACE 1#capability]	//                     ;; IMAP4rev1 servers which offer RFC 1730	//                     ;; compatibility MUST list "IMAP4" as the first	//                     ;; capability.	//	class capability_data : public component	{	public:		~capability_data()		{			for (std::vector <capability*>::iterator it = m_capabilities.begin() ;			     it != m_capabilities.end() ; ++it)			{				delete (*it);			}		}		void go(IMAPParser& parser, string& line, string::size_type* currentPos)		{			DEBUG_ENTER_COMPONENT("capability_data");			string::size_type pos = *currentPos;			parser.checkWithArg <special_atom>(line, &pos, "capability");			while (parser.check <SPACE>(line, &pos, true))			{				capability* cap = parser.get <capability>(line, &pos);				if (cap == NULL) break;				m_capabilities.push_back(cap);			}			*currentPos = pos;		}	private:		std::vector <capability*> m_capabilities;	public:		const std::vector <capability*>& capabilities() const { return (m_capabilities); }	};	//	// date_day_fixed  ::= (SPACE digit) / 2digit	//                    ;; Fixed-format version of date_day	//	// date_month      ::= "Jan" / "Feb" / "Mar" / "Apr" / "May" / "Jun" /	//                    "Jul" / "Aug" / "Sep" / "Oct" / "Nov" / "Dec"	//	// date_year       ::= 4digit	//	// time            ::= 2digit ":" 2digit ":" 2digit	//                     ;; Hours minutes seconds	//	// zone            ::= ("+" / "-") 4digit	//                     ;; Signed four-digit value of hhmm representing	//                     ;; hours and minutes west of Greenwich (that is,	//                     ;; (the amount that the given time differs from	//                     ;; Universal Time).  Subtracting the timezone	//                     ;; from the given time will give the UT form.	//                     ;; The Universal Time zone is "+0000".	//	// date_time       ::= <"> date_day_fixed "-" date_month "-" date_year	//                     SPACE time SPACE zone <">	//	class date_time : public component	{	public:		void go(IMAPParser& parser, string& line, string::size_type* currentPos)		{			DEBUG_ENTER_COMPONENT("date_time");			string::size_type pos = *currentPos;			// <"> date_day_fixed "-" date_month "-" date_year			parser.check <one_char <'"'> >(line, &pos);			parser.check <SPACE>(line, &pos, true);			utility::auto_ptr <number> nd(parser.get <number>(line, &pos));			parser.check <one_char <'-'> >(line, &pos);			utility::auto_ptr <atom> amo(parser.get <atom>(line, &pos));			parser.check <one_char <'-'> >(line, &pos);			utility::auto_ptr <number> ny(parser.get <number>(line, &pos));			parser.check <SPACE>(line, &pos, true);			// 2digit ":" 2digit ":" 2digit			utility::auto_ptr <number> nh(parser.get <number>(line, &pos));			parser.check <one_char <':'> >(line, &pos);			utility::auto_ptr <number> nmi(parser.get <number>(line, &pos));			parser.check <one_char <':'> >(line, &pos);			utility::auto_ptr <number> ns(parser.get <number>(line, &pos));			parser.check <SPACE>(line, &pos, true);			// ("+" / "-") 4digit			int sign = 1;			if (!(parser.check <one_char <'+'> >(line, &pos, true)))				parser.check <one_char <'-'> >(line, &pos);			utility::auto_ptr <number> nz(parser.get <number>(line, &pos));			parser.check <one_char <'"'> >(line, &pos);			m_datetime.setHour(std::min(std::max(nh->value(), 0u), 23u));			m_datetime.setMinute(std::min(std::max(nmi->value(), 0u), 59u));			m_datetime.setSecond(std::min(std::max(ns->value(), 0u), 59u));			const int zone = static_cast <int>(nz->value());			const int zh = zone / 100;   // hour offset			const int zm = zone % 100;   // minute offset			m_datetime.setZone(((zh * 60) + zm) * sign);			m_datetime.setDay(std::min(std::max(nd->value(), 1u), 31u));			m_datetime.setYear(ny->value());			const string month(utility::stringUtils::toLower(amo->value()));			int mon = vmime::datetime::JANUARY;			if (month.length() >= 3)			{				switch (month[0])				{				case 'j':				{					switch (month[1])					{					case 'a': mon = vmime::datetime::JANUARY; break;					case 'u':					{						switch (month[2])						{						case 'n': mon = vmime::datetime::JUNE; break;						default:  mon = vmime::datetime::JULY; break;						}						break;					}					}					break;				}				case 'f': mon = vmime::datetime::FEBRUARY; break;				case 'm':				{					switch (month[2])					{					case 'r': mon = vmime::datetime::MARCH; break;					default:  mon = vmime::datetime::MAY; break;					}					break;				}				case 'a':				{					switch (month[1])					{					case 'p': mon = vmime::datetime::APRIL; break;					default:  mon = vmime::datetime::AUGUST; break;					}					break;				}				case 's': mon = vmime::datetime::SEPTEMBER; break;				case 'o': mon = vmime::datetime::OCTOBER; break;				case 'n': mon = vmime::datetime::NOVEMBER; break;				case 'd': mon = vmime::datetime::DECEMBER; break;				}			}			m_datetime.setMonth(mon);			*currentPos = pos;		}	private:		vmime::datetime m_datetime;	};	//	// header_fld_name ::= astring	//	typedef astring header_fld_name;	//	// header_list     ::= "(" 1#header_fld_name ")"	//	class header_list : public component	{	public:		~header_list()		{			for (std::vector <header_fld_name*>::iterator it = m_fld_names.begin() ;			     it != m_fld_names.end() ; ++it)			{				delete (*it);			}		}		void go(IMAPParser& parser, string& line, string::size_type* currentPos)		{			DEBUG_ENTER_COMPONENT("header_list");			string::size_type pos = *currentPos;			parser.check <one_char <'('> >(line, &pos);			while (!parser.check <one_char <')'> >(line, &pos, true))			{				m_fld_names.push_back(parser.get <header_fld_name>(line, &pos));				parser.check <SPACE>(line, &pos, true);			}			*currentPos = pos;		}	private:		std::vector <header_fld_name*> m_fld_names;	public:		const std::vector <header_fld_name*>& fld_names() const { return (m_fld_names); }	};	//	// body_extension  ::= nstring / number / "(" 1#body_extension ")"	//                     ;; Future expansion.  Client implementations	//                     ;; MUST accept body_extension fields.  Server	//                     ;; implementations MUST NOT generate	//                     ;; body_extension fields except as defined by	//                     ;; future standard or standards-track	//                     ;; revisions of this specification.	//	class body_extension : public component	{	public:		body_extension()			: m_nstring(NULL), m_number(NULL)		{		}		~body_extension()		{			delete (m_nstring);			delete (m_number);			for (std::vector <body_extension*>::iterator it = m_body_extensions.begin() ;			     it != m_body_extensions.end() ; ++it)			{				delete (*it);			}		}		void go(IMAPParser& parser, string& line, string::size_type* currentPos)		{			string::size_type pos = *currentPos;			if (parser.check <one_char <'('> >(line, &pos, true))			{				m_body_extensions.push_back					(parser.get <body_extension>(line, &pos));				while (!parser.check <one_char <')'> >(line, &pos, true))				{					m_body_extensions.push_back(parser.get <body_extension>(line, &pos));					parser.check <SPACE>(line, &pos, true);				}			}			else			{				if (!(m_nstring = parser.get <IMAPParser::nstring>(line, &pos, true)))					m_number = parser.get <IMAPParser::number>(line, &pos);			}			*currentPos = pos;		}	private:		IMAPParser::nstring* m_nstring;		IMAPParser::number* m_number;		std::vector <body_extension*> m_body_extensions;	public:		IMAPParser::nstring* nstring() const { return (m_nstring); }		IMAPParser::number* number() const { return (m_number); }		const std::vector <body_extension*>& body_extensions() const { return (m_body_extensions); }	};	//	// section_text    ::= "HEADER" / "HEADER.FIELDS" [".NOT"]	//                     SPACE header_list / "TEXT" / "MIME"	//	class section_text : public component	{	public:		section_text()			: m_header_list(NULL)		{		}		~section_text()		{			delete (m_header_list);		}		void go(IMAPParser& parser, string& line, string::size_type* currentPos)		{			DEBUG_ENTER_COMPONENT("section_text");			string::size_type pos = *currentPos;			// "HEADER.FIELDS" [".NOT"] SPACE header_list			const bool b1 = parser.checkWithArg <special_atom>(line, &pos, "header.fields.not", true);			const bool b2 = (b1 ? false : parser.checkWithArg <special_atom>(line, &pos, "header.fields", true));			if (b1 || b2)			{				m_type = b1 ? HEADER_FIELDS_NOT : HEADER_FIELDS;				parser.check <SPACE>(line, &pos);				m_header_list = parser.get <IMAPParser::header_list>(line, &pos);			}			// "HEADER"			else if (parser.checkWithArg <special_atom>(line, &pos, "header", true))			{				m_type = HEADER;			}			// "MIME"			else if (parser.checkWithArg <special_atom>(line, &pos, "mime", true))			{				m_type = MIME;			}			// "TEXT"			else			{				m_type = TEXT;				parser.checkWithArg <special_atom>(line, &pos, "text");			}			*currentPos = pos;		}		enum Type		{			HEADER,			HEADER_FIELDS,			HEADER_FIELDS_NOT,			MIME,			TEXT		};	private:		Type m_type;		IMAPParser::header_list* m_header_list;	public:		Type type() const { return (m_type); }		const IMAPParser::header_list* header_list() const { return (m_header_list); }	};	//	// section         ::= "[" [section_text / (nz_number *["." nz_number]	//                     ["." (section_text / "MIME")])] "]"	//	class section : public component	{	public:		section()			: m_section_text1(NULL), m_section_text2(NULL)		{		}		~section()

⌨️ 快捷键说明

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