acl/lib_acl_cpp/include/acl_cpp/smtp/mail_body.hpp

211 lines
5.8 KiB
C++
Raw Normal View History

#pragma once
2017-06-02 14:47:24 +08:00
#include "../acl_cpp_define.hpp"
#include <vector>
2017-06-02 14:47:24 +08:00
#include "../stdlib/string.hpp"
#include "../stdlib/noncopyable.hpp"
2017-06-02 14:47:24 +08:00
#include "../http/http_ctype.hpp"
#if !defined(ACL_MIME_DISABLE)
namespace acl {
class mime_code;
class mail_attach;
2015-09-16 21:03:02 +08:00
/**
* <EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2015-09-16 21:03:02 +08:00
*/
class ACL_CPP_API mail_body : public noncopyable
{
public:
2015-09-16 21:03:02 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param charset {const char*} <EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
* @param encoding {const char*} <EFBFBD><EFBFBD><EFBFBD>ĵı<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
2015-09-16 21:03:02 +08:00
*/
mail_body(const char* charset = "utf-8",
const char* encoding = "base64");
~mail_body();
2015-09-16 21:03:02 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2015-09-16 21:03:02 +08:00
* @return {const string&}
*/
const string& get_content_type() const
{
return content_type_;
}
2015-09-16 21:03:02 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><EFBFBD><EFBFBD>
2015-09-16 21:03:02 +08:00
* @return {const http_ctype&}
*/
const http_ctype& get_ctype() const
{
return ctype_;
}
2015-09-16 21:03:02 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ TEXT/HTML <EFBFBD><EFBFBD>ʽ
* @param html {const char*} HTML <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param len {size_t} html <EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>(<EFBFBD><EFBFBD>Ȼ html <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> strlen <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
2015-09-16 21:03:02 +08:00
* @return {mail_body&}
*/
mail_body& set_html(const char* html, size_t len);
2015-09-16 21:03:02 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ TEXT/PLAIN <EFBFBD><EFBFBD>ʽ
* @param plain {const char*} TEXT <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param len {size_t} plain <EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>(<EFBFBD><EFBFBD>Ȼ plain <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> strlen <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
2015-09-16 21:03:02 +08:00
* @return {mail_body&}
*/
mail_body& set_plain(const char* plain, size_t len);
2015-09-16 21:03:02 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ multipart/alternative <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>
* @param html {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD> HTML <EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD>ǿ<EFBFBD>)
* @param hlen {size_t} html <EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>(>0)
* @param plain {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD> TEXT <EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD>ǿ<EFBFBD>)
* @param plen {size_t} plain <EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>(>0)
2015-09-16 21:03:02 +08:00
* @return {mail_body&}
*/
mail_body& set_alternative(const char* html, size_t hlen,
const char* plain, size_t plen);
2015-09-16 21:03:02 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ multipart/relative <EFBFBD><EFBFBD>ʽʱ<EFBFBD><EFBFBD><EFBFBD>ô˺<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param html {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD> HTML <EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD>ǿ<EFBFBD>)
* @param hlen {size_t} html <EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>(>0)
* @param plain {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD> plain <EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD>ǿ<EFBFBD>)
* @param plen {size_t} plain <EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>(>0)
* @param attachments {const std::vector<mail_attach*>&} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD> html <EFBFBD>е<EFBFBD> cid <EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>ͼƬ<EFBFBD>ȸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2015-09-16 21:03:02 +08:00
* @return {mail_body&}
*/
mail_body& set_relative(const char* html, size_t hlen,
const char* plain, size_t plen,
const std::vector<mail_attach*>& attachments);
2015-09-16 21:03:02 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> set_html <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD> html/plain <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param len {size_t} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD>Ƚ<EFBFBD><EFBFBD><EFBFBD>
2015-09-16 21:03:02 +08:00
* @return {const char*}
*/
const char* get_html(size_t& len) const
{
len = hlen_;
return html_;
}
2015-09-16 21:03:02 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> set_plain <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD> plain/plain <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param len {size_t} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD>Ƚ<EFBFBD><EFBFBD><EFBFBD>
2015-09-16 21:03:02 +08:00
* @return {const char*}
*/
const char* get_plain(size_t& len) const
{
len = plen_;
return plain_;
}
2015-09-16 21:03:02 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> set_attachments <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õĸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2015-09-16 21:03:02 +08:00
* @return {const std::vector<mail_attach*>*}
*/
const std::vector<mail_attach*>* get_attachments() const
{
return attachments_;
}
2015-09-16 21:03:02 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>׷<EFBFBD><EFBFBD><EFBFBD>ڸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param out {ostream&} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
2015-09-16 21:03:02 +08:00
*/
bool save_to(ostream& out) const;
2015-09-16 21:03:02 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>׷<EFBFBD><EFBFBD><EFBFBD>ڸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param out {string&} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
2015-09-16 21:03:02 +08:00
*/
bool save_to(string& out) const;
2015-09-16 21:03:02 +08:00
/**
* text/html <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>
* @param in {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> html <EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param len {size_t} in <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
* @param out {string&} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>׷<EFBFBD>ӷ<EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
2015-09-16 21:03:02 +08:00
*/
bool save_html(const char* in, size_t len, string& out) const;
2015-09-16 21:03:02 +08:00
/**
* text/plain <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>
* @param in {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> plain <EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param len {size_t} in <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
* @param out {string&} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>׷<EFBFBD>ӷ<EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
2015-09-16 21:03:02 +08:00
*/
bool save_plain(const char* in, size_t len, string& out) const;
2015-09-16 21:03:02 +08:00
/**
* multipart/relative <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>
* @param html {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> html <EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param hlen {size_t} html <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
* @param plain {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD> TEXT <EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD>ǿ<EFBFBD>)
* @param plen {size_t} plain <EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>(>0)
* @param attachments {const std::vector<mail_attach*>&} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD> html <EFBFBD>е<EFBFBD> cid <EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>ͼƬ<EFBFBD>ȸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param out {string&} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>׷<EFBFBD>ӷ<EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
2015-09-16 21:03:02 +08:00
*/
bool save_relative(const char* html, size_t hlen,
const char* plain, size_t plen,
const std::vector<mail_attach*>& attachments,
string& out) const;
2015-09-16 21:03:02 +08:00
/**
* multipart/alternative <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>
* @param html {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> html <EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param hlen {size_t} html <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
* @param plain {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD> TEXT <EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD>ǿ<EFBFBD>)
* @param plen {size_t} plain <EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>(>0)
* @param out {string&} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>׷<EFBFBD>ӷ<EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
2015-09-16 21:03:02 +08:00
*/
bool save_alternative(const char* html, size_t hlen,
const char* plain, size_t plen, string& out) const;
private:
string charset_;
string content_type_;
string transfer_encoding_;
mime_code* coder_;
string boundary_;
http_ctype ctype_;
int mime_stype_;
const char* html_;
size_t hlen_;
const char* plain_;
size_t plen_;
const std::vector<mail_attach*>* attachments_;
bool build(const char* in, size_t len, const char* content_type,
const char* charset, mime_code& coder, string& out) const;
bool build_html(const char* in, size_t len,
const char* charset, string& out) const;
bool build_plain(const char* in, size_t len,
const char* charset, string& out) const;
void set_content_type(const char* content_type);
};
} // namespace acl
#endif // !defined(ACL_MIME_DISABLE)