acl/lib_acl_cpp/include/acl_cpp/mime/rfc822.hpp

102 lines
2.5 KiB
C++
Raw Normal View History

2014-11-19 00:25:21 +08:00
#pragma once
2017-06-02 14:47:24 +08:00
#include "../acl_cpp_define.hpp"
2014-11-19 00:25:21 +08:00
#include <list>
#include <time.h>
namespace acl {
/**
* <EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>ַ
*/
struct rfc822_addr
{
char* addr; // <20>ʼ<EFBFBD><CABC><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>ʽΪ<CABD><CEAA> xxx@xxx.xxx
char* comment; // <20>ʼ<EFBFBD><CABC><EFBFBD>ע
};
typedef enum
{
tzone_gmt,
tzone_cst
} tzone_t;
class ACL_CPP_API rfc822
{
public:
rfc822();
~rfc822();
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> RFC822 <EFBFBD><EFBFBD>׼<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
* @param in {const char*} ʱ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* Wed, 11 May 2011 09:44:37 +0800 (CST)
* Wed, 11 May 2011 16:17:39 GMT
*/
time_t parse_date(const char *in);
/**
* <EFBFBD><EFBFBD><EFBFBD>ɷ<EFBFBD><EFBFBD><EFBFBD> RFC822 <EFBFBD><EFBFBD>׼<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
* @param t {time_t}
* @param out {char*} <EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param size {size_t} out <EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD>С
* @param zone {tzone_t} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
*/
void mkdate(time_t t, char* out, size_t size, tzone_t zone = tzone_cst);
/**
* <EFBFBD><EFBFBD><EFBFBD>ɶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
* @param t {time_t}
* @param out {char*} <EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param size {size_t} out <EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD>С
*/
void mkdate_cst(time_t t, char* out, size_t size);
/**
* <EFBFBD><EFBFBD><EFBFBD>ɸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
* @param t {time_t}
* @param out {char*} <EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param size {size_t} out <EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD>С
*/
void mkdate_gmt(time_t t, char* out, size_t size);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>б<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> RFC822 <EFBFBD><EFBFBD>׼<EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>б<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>б<EFBFBD><EFBFBD><EFBFBD>ͬʱ<EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD>Ͳ<EFBFBD><EFBFBD>ֽ<EFBFBD><EFBFBD><EFBFBD>
* RFC2047<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param in {const char*} RFC822 <EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>б<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:
* "=?gb2312?B?1dSx+A==?= <zhaobing@51iker.com>;\r\n"
* "\t\"=?GB2312?B?t+vBosn6?=\" <fenglisheng@51iker.com>;\r\n"
* "\t\"zhengshuxin3\";\"zhengshuxin4\" <zhengshuxin2@51iker.com>;"
* "<xuganghui@51iker.com>;<wangwenquan@51iker.com>;"
* @param to_charset {const char*} Ŀ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>gbk, gb18030, utf-8
2014-11-19 00:25:21 +08:00
* @return {const std::list<rfc822_addr*>&} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
const std::list<rfc822_addr*>& parse_addrs(const char* in,
const char* to_charset = "utf-8");
2014-11-19 00:25:21 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> RFC822 <EFBFBD><EFBFBD>׼<EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>ͬʱ<EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD>Ͳ<EFBFBD><EFBFBD>ְ<EFBFBD>
* RFC2047 <EFBFBD><EFBFBD>׼<EFBFBD><EFBFBD><EFBFBD>н<EFBFBD><EFBFBD><EFBFBD>
* @param in {const char*} RFC822 <EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>ַ
* @param to_charset {const char*} Ŀ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>gbk, gb18030, utf-8
2014-11-19 00:25:21 +08:00
* @return {const rfc822_addr*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> NULL <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* RFC822 <EFBFBD>
*/
const rfc822_addr* parse_addr(const char* in,
const char* to_charset = "utf-8");
2014-11-19 00:25:21 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>Ƿ<EFBFBD><EFBFBD>Ϸ<EFBFBD>
* @param in {const char*} RFC822 <EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>ַ
* @return {bool}
*/
bool check_addr(const char* in);
private:
std::list<rfc822_addr*> addrs_;
void reset();
};
} // namespace acl