acl/lib_acl_cpp/samples/mime/mime.cpp

498 lines
11 KiB
C++
Raw Normal View History

// mime.cpp : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̨Ӧ<CCA8>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ㡣
//
#include "stdafx.h"
#include "lib_acl.h"
#ifdef WIN32
#include <vld.h>
#else
#include <getopt.h>
#endif
#include <string>
#include <errno.h>
#include <string.h>
#include "acl_cpp/stdlib/string.hpp"
#include "acl_cpp/stream/ifstream.hpp"
#include "acl_cpp/stream/ofstream.hpp"
#include "acl_cpp/stdlib/charset_conv.hpp"
#include "acl_cpp/stdlib/log.hpp"
#include "acl_cpp/mime/mime.hpp"
#include "acl_cpp/mime/mime_body.hpp"
#include "acl_cpp/mime/rfc2047.hpp"
#include "acl_cpp/mime/mime_attach.hpp"
#include "pipeline_string.h"
using namespace std;
using namespace acl;
static void header_out(const acl::mime* mime)
{
printf("sender addr: %s\n", mime->sender().c_str());
printf("from addr: %s\n", mime->from().c_str());
printf("replyto addr: %s\n", mime->replyto().c_str());
printf("returnpath addr: %s\n", mime->returnpath().c_str());
const list<char*>& rcpts = mime->rcpt_list();
list<char*>::const_iterator cit;
for (cit = rcpts.begin(); cit != rcpts.end(); cit++)
{
const char* addr = *cit;
printf("rcpt addr: %s\n", addr);
}
const list<char*>& tos = mime->to_list();
for (cit = tos.begin(); cit != tos.end(); cit++)
{
const char* addr = *cit;
printf("to addr: %s\n", addr);
}
const list<char*>& ccs = mime->cc_list();
for (cit = ccs.begin(); cit != ccs.end(); cit++)
{
const char* addr = *cit;
printf("cc addr: %s\n", addr);
}
const char* to = mime->header_value("To");
acl::string out;
if (to)
rfc2047::decode(to, (int) strlen(to), &out);
printf(">>>>To: %s, %s\n", to ? to : "null", out.c_str());
}
// <20><><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD>ͷ<EFBFBD><CDB7>Ϣ
static void test_mime_header(acl::mime& mime, const char* path)
{
// <20><><EFBFBD>½<EFBFBD><C2BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>
printf("\r\n");
ACL_METER_TIME("---------------parse header begin--------------------");
acl::ifstream fp;
if (fp.open_read(path) == false) {
printf("open %s error %s\n", path, strerror(errno));
return;
}
acl::string buf;
const char* ptr;
size_t n;
// <20><>ʼ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
mime.update_begin(path); // update_begin <20>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD> reset()
while (1) {
if (fp.gets(buf, false) == false)
break;
if (buf == "\r\n" || buf == "\n")
break;
ptr = buf.c_str();
n = buf.length();
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> true <20><>ʾͷ<CABE><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, Ϊ<><CEAA>ʹ<EFBFBD>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> true,
// <20><><EFBFBD>뱣֤<EBB1A3><D6A4><EFBFBD>ô˺<C3B4><CBBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ "\r\n" <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
(void) mime.update(ptr, n);
}
mime.update_end();
header_out(&mime);
ACL_METER_TIME("---------------parse header end --------------------");
}
// <20><><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD><EFBFBD>ڻ<EFBFBD><DABB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD>ùܵ<C3B9><DCB5><EFBFBD>ģʽ<C4A3><CABD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD>ұ<EFBFBD><D2B1><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD>ʼ<EFBFBD><CABC>еĸ<D0B5><C4B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>
static void mime_test1(acl::mime& mime, const char* path, bool htmlFirst)
{
mime.reset();
acl::string buf;
acl::ofstream fp_out;
acl::mime_body* pBody = NULL;
printf("\r\n>>> %s: path: %s\n", __FUNCTION__, path);
ACL_METER_TIME("---------------parse begin --------------------");
if (mime.parse(path) == false)
{
printf("mime parse %s error\n", path);
return;
}
ACL_METER_TIME("---------------parse end --------------------");
pBody = mime.get_body_node(htmlFirst, true, "iso-2022-jp");
//////////////////////////////////////////////////////////////////////
// <20><><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>
printf("\r\n");
ACL_METER_TIME("---------------save_body begin--------------------");
header_out(&mime);
mime.mime_debug("./var");
buf = "./var/";
buf += path;
mime.save_as(buf.c_str());
if (pBody)
pBody->save_body("./var/body_gb.txt");
ACL_METER_TIME("---------------save_body end --------------------");
//////////////////////////////////////////////////////////////////////
// <20><><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD><EFBFBD>ڻ<EFBFBD><DABB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (pBody)
{
acl::string buf1;
pBody->save_body(buf1);
if (fp_out.open_write("./var/body_string.txt"))
{
fp_out.write(buf1.c_str(), buf1.length());
fp_out.close();
}
}
//////////////////////////////////////////////////////////////////////
// <20><><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> utf-8 <20><><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>
if (pBody)
{
printf("\r\n");
ACL_METER_TIME("---------------save_body begin--------------------");
acl::charset_conv jp2utf8;
jp2utf8.update_begin("iso-2022-jp", "utf-8");
acl::pipe_string pipe_out;
pipeline_string pipeline;
acl::pipe_manager manager;
manager.push_front(&pipe_out);
manager.push_front(&jp2utf8);
manager.push_front(&pipeline);
pBody->save(manager);
ACL_METER_TIME("---------------save_body end1 --------------------");
acl::string& sbuf = pipe_out.get_buf();
fp_out.close();
if (fp_out.open_write("./var/body_utf8.txt"))
{
fp_out.write(sbuf.c_str(), sbuf.length());
fp_out.close();
}
ACL_METER_TIME("---------------save_body end2 --------------------");
}
//////////////////////////////////////////////////////////////////////
// <20><><EFBFBD>ùܵ<C3B9><DCB5><EFBFBD>ģʽ<C4A3><CABD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD>ұ<EFBFBD><D2B1><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>
if (pBody)
{
printf("\r\n");
ACL_METER_TIME("---------------save_body begin--------------------");
acl::charset_conv utf8ToGb, gbToBig5;
utf8ToGb.update_begin("utf-8", "gbk");
gbToBig5.update_begin("gbk", "big5");
acl::pipe_string pipe_out;
acl::pipe_manager manager;
manager.push_front(&pipe_out);
manager.push_front(&gbToBig5);
manager.push_front(&utf8ToGb);
pBody->save(manager);
ACL_METER_TIME("---------------save_body end1 --------------------");
acl::string& sbuf = pipe_out.get_buf();
fp_out.close();
if (fp_out.open_write("./var/body_big5.txt"))
{
fp_out.write(sbuf.c_str(), sbuf.length());
fp_out.close();
}
ACL_METER_TIME("---------------save_body end2 --------------------");
}
//////////////////////////////////////////////////////////////////////
// <20><><EFBFBD>ʼ<EFBFBD><CABC>еĸ<D0B5><C4B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>
printf("---------------------------------------------------------\r\n");
printf(">>>> saving attach file now ...\r\n");
const std::list<acl::mime_attach*>& attaches = mime.get_attachments();
std::list<acl::mime_attach*>::const_iterator cit = attaches.begin();
for (; cit != attaches.end(); cit++)
{
buf = "./var/";
buf << (*cit)->get_filename();
acl::string attach_name;
acl::rfc2047 rfc2047;
rfc2047.reset(true);
rfc2047.decode_update(buf, (int) buf.length());
rfc2047.decode_finish("utf-8", &attach_name);
printf(">>> attach file: |%s|, len: %d\n",
attach_name.c_str(), (int) attach_name.length());
(*cit)->save(attach_name.c_str());
}
printf(">>>> saved attach file ok ...\r\n");
//////////////////////////////////////////////////////////////////////
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>
mime.save_mail("./var", "test.html");
}
// <20><>λ<EFBFBD><CEBB><EFBFBD>ļ<EFBFBD><C4BC>е<EFBFBD><D0B5>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD>н<EFBFBD><D0BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ڴ滺<DAB4><E6BBBA><EFBFBD><EFBFBD>
static void mime_test2(acl::mime& mime, const char* path)
{
// <20><><EFBFBD>½<EFBFBD><C2BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>
printf("\r\n");
ACL_METER_TIME("---------------parse mail begin--------------------");
acl::ifstream fp;
if (fp.open_read(path) == false) {
printf("open %s error %s\n", path, strerror(errno));
return;
}
acl::string buf;
const char* ptr;
size_t n;
// <20><>ʼ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
mime.update_begin(path);
while (1) {
if (fp.gets(buf, false) == false)
break;
ptr = buf.c_str();
n = buf.length();
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> true <20><>ʾͷ<CABE><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, Ϊ<><CEAA>ʹ<EFBFBD>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> true,
// <20><><EFBFBD>뱣֤<EBB1A3><D6A4><EFBFBD>ô˺<C3B4><CBBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ "\r\n" <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//printf(">>>>%s", ptr);
if (mime.update(ptr, n) == true)
{
printf(">>> parse over, last line: %s\n", ptr);
break;
}
buf.clear();
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> update_end
mime.update_end();
acl::mime_body* pBody;
pBody = mime.get_body_node(false);
if (pBody)
{
acl::string buf2;
pBody->save_body(buf2);
printf(">>>>>>>body: %s\n", buf2.c_str());
}
header_out(&mime);
ACL_METER_TIME("---------------parse mail end --------------------");
}
// <20><>λ<EFBFBD><CEBB><EFBFBD>ڴ<EFBFBD><DAB4>е<EFBFBD><D0B5>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD>н<EFBFBD><D0BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ڴ滺<DAB4><E6BBBA><EFBFBD><EFBFBD>
static void mime_test3(acl::mime& mime, const char* path)
{
// <20><><EFBFBD>½<EFBFBD><C2BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>
printf("\r\n");
ACL_METER_TIME("---------------parse mail begin--------------------");
acl::string buf;
if (acl::ifstream::load(path, &buf) == false)
{
printf("load %s error %s\n", path, strerror(errno));
return;
}
// <20><>ʼ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
mime.reset();
if (mime.update(buf.c_str(), buf.length()) != true)
{
printf("mime parse error\r\n");
return;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> update_end
mime.update_end();
acl::mime_body* pBody;
pBody = mime.get_body_node(false);
if (pBody)
{
acl::string out;
if (pBody->save_body(out, buf.c_str(), (ssize_t) buf.length()) == false)
printf(">>>>save_body to buffer error\r\n");
else
printf(">>>>>>>body: %s\n", out.c_str());
}
else
printf(">>>> no body\r\n");
header_out(&mime);
ACL_METER_TIME("---------------parse mail end --------------------");
}
// <20><>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>MIME<4D><45><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̣<EFBFBD><CCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
static void mime_test4(acl::mime& mime, const char* path)
{
mime.reset();
acl::ifstream in;
if (in.open_read(path) == false)
{
printf("open %s error %s\n", path, strerror(errno));
return;
}
acl::string buf;
size_t off = 0;
// <20>ȶ<EFBFBD><C8B6>ļ<EFBFBD>ͷ, <20><><EFBFBD>Թ<EFBFBD><D4B9>ļ<EFBFBD>ͷ
while (true)
{
if (in.gets(buf, false) == false)
break;
off += buf.length();
if (buf == "\n" || buf == "\r\n")
{
buf.clear();
break;
}
buf.clear();
}
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD>ʼ<EFBFBD><CABC>岿<EFBFBD><E5B2BF>
mime.update_begin(path);
// <20><>ʼ<EFBFBD><CABC><EFBFBD>ʼ<EFBFBD>
while (true)
{
if (in.gets(buf, false) == false)
break;
mime.update(buf.c_str(), buf.length());
buf.clear();
}
mime.update_end();
printf("\n-----------------------------------------------------\n\n");
acl::mime_body* pBody = mime.get_body_node(false, true, "gb2312", (off_t) off);
if (pBody)
{
acl::string buf2;
pBody->save_body(buf2);
printf(">>>>>>>body(%d): %s\n", (int) off, buf2.c_str());
}
}
//////////////////////////////////////////////////////////////////////////
static void usage(const char* procname)
{
printf("usage: %s [options]\r\n"
" -h [help]\r\n"
" -s [html first, or text first]\r\n"
" -t test0/test1/test2/test3/test4\r\n"
" -f mail_file\r\n", procname);
printf("test0: <20><><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD>ͷ<EFBFBD><CDB7>Ϣ\r\n"
"test1: <20><><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>\r\n"
"\t<EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\r\n"
"\t<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>\r\n"
"\t<EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>еĸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\r\n"
"\t<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>\r\n");
printf("test2: <20><>λ<EFBFBD><CEBB><EFBFBD>ļ<EFBFBD><C4BC>е<EFBFBD><D0B5>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD>н<EFBFBD><D0BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ڴ滺<DAB4><E6BBBA><EFBFBD><EFBFBD>\r\n");
printf("test3: <20><>λ<EFBFBD><CEBB><EFBFBD>ڴ<EFBFBD><DAB4>е<EFBFBD><D0B5>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD>н<EFBFBD><D0BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ڴ滺<DAB4><E6BBBA><EFBFBD><EFBFBD>\r\n");
printf("test4: <20><>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>MIME<4D><45><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̣<EFBFBD><CCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>(<28><><EFBFBD>ӣ<EFBFBD>test16.eml)\r\n");
}
int main(int argc, char* argv[])
{
char ch;
bool htmlFirst = false;
acl::string path("test.eml");
acl::string cmd("test1");
while ((ch = (char) getopt(argc, argv, "hst:f:")) > 0)
{
switch (ch)
{
case 'h':
usage(argv[0]);
return (0);
case 's':
htmlFirst = true;
break;
case 't':
cmd = optarg;
break;
case 'f':
path = optarg;
break;
default:
break;
}
}
logger_open("test.log", "mime", "all:1");
acl::mime mime;
//////////////////////////////////////////////////////////////////////
if (cmd == "test0")
test_mime_header(mime, path.c_str());
else if (cmd == "test1")
mime_test1(mime, path.c_str(), htmlFirst);
else if (cmd == "test2")
mime_test2(mime, path.c_str());
else if (cmd == "test3")
mime_test3(mime, path.c_str());
else if (cmd == "test4")
mime_test4(mime, path.c_str());
else
printf(">>> unknown cmd: %s\n", cmd.c_str());
//////////////////////////////////////////////////////////////////////
printf("enter any key to exit\r\n");
logger_close();
getchar();
return 0;
}