Skip to content

Commit 99bf564

Browse files
committed
Unmerged MIME lib
1 parent 19d6973 commit 99bf564

18 files changed

+2635
-0
lines changed

boost/mime.hpp

Lines changed: 775 additions & 0 deletions
Large diffs are not rendered by default.

libs/mime/To-Do.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
To Do list for Boost.Mime:
2+
3+
General:
4+
* Finish the test suites
5+
** Compare results to python parser
6+
** Try to parse some bad mime inputs
7+
--> Added 0019-NoBoundary test
8+
* Integrate into cpp-netlib
9+
* Write some docs
10+
11+
Specific:
12+
* Rename make_mime into something better. Parse, Encode?
13+
--> Changed the name to 'parse_mime', and made the stream and iterator versions use the same name
14+
* Start using boost::exception
15+
* Look into making the parsing restartable
16+
* Figure out how to

libs/mime/doc/Jamfile.v2

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# (C) Copyright 2010 Marshall Clow
2+
#
3+
# Distributed under the Boost Software License, Version 1.0. (See accompanying
4+
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5+
6+
path-constant boost-images : doc/src/images ;
7+
8+
xml mime : mime.qbk ;
9+
10+
boostbook standalone
11+
:
12+
mime
13+
:
14+
# HTML options first:
15+
# Use graphics not text for navigation:
16+
<xsl:param>navig.graphics=1
17+
# How far down we chunk nested sections, basically all of them:
18+
<xsl:param>chunk.section.depth=3
19+
# Don't put the first section on the same page as the TOC:
20+
<xsl:param>chunk.first.sections=1
21+
# How far down sections get TOC's
22+
<xsl:param>toc.section.depth=10
23+
# Max depth in each TOC:
24+
<xsl:param>toc.max.depth=3
25+
# How far down we go with TOC's
26+
<xsl:param>generate.section.toc.level=10
27+
# Path for links to Boost:
28+
<xsl:param>boost.root=http://cpp-netlib.github.com/
29+
# Path for libraries index:
30+
<xsl:param>boost.libraries=http://www.boost.org/libs/libraries.htm
31+
# Use the main Boost stylesheet:
32+
<xsl:param>html.stylesheet=../boostbook.css
33+
34+
# PDF Options:
35+
# TOC Generation: this is needed for FOP-0.9 and later:
36+
#<xsl:param>fop1.extensions=1
37+
# Or enable this if you're using XEP:
38+
<xsl:param>xep.extensions=1
39+
# TOC generation: this is needed for FOP 0.2, but must not be set to zero for FOP-0.9!
40+
<xsl:param>fop.extensions=0
41+
# No indent on body text:
42+
<xsl:param>body.start.indent=0pt
43+
# Margin size:
44+
<xsl:param>page.margin.inner=0.5in
45+
# Margin size:
46+
<xsl:param>page.margin.outer=0.5in
47+
# Yes, we want graphics for admonishments:
48+
<xsl:param>admon.graphics=1
49+
# Set this one for PDF generation *only*:
50+
# default pnd graphics are awful in PDF form,
51+
# better use SVG's instead:
52+
<format>pdf:<xsl:param>admon.graphics.extension=".svg"
53+
<format>pdf:<xsl:param>admon.graphics.path=$(boost-images)/
54+
;
55+

libs/mime/doc/mime.qbk

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
[/
2+
(C) Copyright 2010 Marshall Clow
3+
Distributed under the Boost Software License, Version 1.0.
4+
(See accompanying file LICENSE_1_0.txt or copy at
5+
http://www.boost.org/LICENSE_1_0.txt).
6+
]
7+
8+
[article C++ Mime Library
9+
[quickbook 1.4]
10+
[version 0.5]
11+
[authors [Clow, Marshall]]
12+
[copyright 2010 Marshall Clow]
13+
[purpose C++ library for MIME parsing, manipulation and printing]
14+
[category text]
15+
[license
16+
Distributed under the Boost Software License, Version 1.0.
17+
(See accompanying file LICENSE_1_0.txt or copy at
18+
[@http://www.boost.org/LICENSE_1_0.txt])
19+
]
20+
]
21+
22+
23+
[def __boost__ [@http://www.boost.org/ the Boost C++ Libraries]]
24+
[def __boost_org__ [@http://www.boost.org/]]
25+
[def __boost_asio__ [@http://www.boost.org/libs/asio/index.html Boost.Asio]]
26+
[def __boost_system__ [@http://www.boost.org/libs/system/index.html Boost.System]]
27+
[def __boost_type_traits__ [@http://www.boost.org/libs/type_traits/index.html Boost.TypeTraits]]
28+
[def __boost_doc__ [@http://www.boost.org/doc/libs/]]
29+
[def __pion__ [@http://www.pion.org/projects/pion-network-library the Pion Network Library]]
30+
[def __cnl__ C++ Network Library]
31+
[def __message__ `basic_message`]
32+
[def __uri__ `basic_uri`]
33+
[def __python__ [@http://www.python.org Python]]
34+
[def __libcurl__ [@http://curl.haxx.se/ libcurl]]
35+
[def __mozilla_netlib__ [@http://www.mozilla.org/projects/netlib/ mozilla-netlib]]
36+
[def __sf_cpp_netlib__ [@http://sourceforge.net/projects/cpp-netlib/ sourceforge]]
37+
[def __github__ [@http://github.com/mikhailberis/cpp-netlib github]]
38+
[def __default_constructible__ [@http://www.boost.org/doc/html/DefaultConstructible.html DefaultConstructible]]
39+
[def __copy_constructible__ [@http://www.boost.org/doc/html/CopyConstructible.html CopyConstructible]]
40+
[def __assignable__ [@http://www.boost.org/doc/html/Assignable.html Assignable]]
41+
[def __equality_comparable__ [@http://www.boost.org/doc/html/Assignable.html Assignable]]
42+
43+
44+
[def __quick_start__ quick start]
45+
46+
47+
[include quick_start.qbk]
48+
#[include intro.qbk]
49+
#[include using.qbk]
50+
#[/include architecture.qbk]
51+
#[include message.qbk]
52+
#[include uri.qbk]
53+
#[include protocol.qbk]
54+
#[include examples.qbk]
55+
#[include reference.qbk]
56+
#[include acknowledgements.qbk]
57+
#[include appendices.qbk]
58+
#[include contributors.qbk]

libs/mime/doc/quick_start.qbk

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[/
2+
(C) Copyright 2010 Marshall Clow
3+
Distributed under the Boost Software License, Version 1.0.
4+
(See accompanying file LICENSE_1_0.txt or copy at
5+
http://www.boost.org/LICENSE_1_0.txt).
6+
]
7+
8+
9+
[section:quick_start Quick Start]
10+
11+
[endsect] [/ quick_start]

libs/mime/example/Jamfile.v2

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#
2+
# Copyright Marshall Clow 2010.
3+
# Distributed under the Boost Software License, Version 1.0.
4+
# (See accompanying file LICENSE_1_0.txt or copy at
5+
# http://www.boost.org/LICENSE_1_0.txt)
6+
7+
import os ;
8+
9+
project mime_examples :
10+
requirements
11+
<include>../../../
12+
<include>$BOOST_ROOT
13+
<toolset>msvc:<define>WIN32_LEAN_AND_MEAN
14+
<toolset>msvc:<define>_SCL_SECURE_NO_WARNINGS
15+
<c++-template-depth>256
16+
<link>static
17+
;
18+
19+
exe basic_usage : basic_usage.cpp ;
20+
exe basic_parsing : basic_parsing.cpp ;
21+

libs/mime/example/basic_parsing.cpp

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
//
2+
// Copyright Marshall Clow 2009-2010
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
//
7+
//
8+
9+
#include <boost/mime.hpp>
10+
11+
#include <fstream>
12+
#include <iostream>
13+
#include <iterator>
14+
#include <sstream>
15+
16+
struct my_traits {
17+
typedef std::string string_type;
18+
// typedef std::pair < std::string, string_type > header_type;
19+
typedef std::string body_type;
20+
};
21+
22+
//typedef boost::mime::mime_part<> mime_part;
23+
typedef boost::mime::basic_mime<my_traits> mime_part;
24+
25+
template <typename Container>
26+
void DumpContainer ( std::ostream & out, const std::string &prefix, const Container &c ) {
27+
out << prefix << ' ';
28+
if ( c.size () < 10 ) {
29+
for ( typename Container::const_iterator iter = c.begin(); iter != c.end(); ++iter )
30+
out << (int) *iter << ' ';
31+
}
32+
else {
33+
for ( int i = 0; i < 5; i++ )
34+
out << int(c.begin()[i]) << ' ';
35+
out << "... ";
36+
for ( int i = 0; i < 5; i++ )
37+
out << int(c.rbegin()[i]) << ' ';
38+
}
39+
out << std::endl;
40+
}
41+
42+
43+
void DumpStructure ( std::ostream & out, const char *title, const mime_part &mp, std::string prefix ) {
44+
std::string content_type = mp.get_content_type ();
45+
if ( NULL != title )
46+
out << prefix << "Data from: " << title << std::endl;
47+
out << prefix << "Content-Type: " << content_type << std::endl;
48+
out << prefix << "There are " << std::distance ( mp.header_begin (), mp.header_end ()) << " headers" << std::endl;
49+
size_t subpart_count = std::distance ( mp.subpart_begin (), mp.subpart_end ());
50+
switch ( mp.get_part_kind ()) {
51+
case mime_part::simple_part:
52+
if ( subpart_count != 0 )
53+
out << str ( boost::format ( "%s ### %d subparts on a simple (%s) type!" ) % prefix % subpart_count % content_type ) << std::endl;
54+
out << prefix << "The body is " << mp.body_size () << " bytes long" << std::endl;
55+
DumpContainer ( out, prefix, *mp.body ());
56+
break;
57+
58+
case mime_part::multi_part:
59+
break;
60+
61+
case mime_part::message_part:
62+
if ( boost::iequals ( content_type, "message/delivery-status" ))
63+
out << prefix << "The body is " << mp.body_size () << " bytes long" << std::endl;
64+
else if ( 1 != subpart_count )
65+
out << str ( boost::format ( "%s ### %d subparts on a message (%s) type!" ) % subpart_count % prefix % content_type ) << std::endl;
66+
break;
67+
}
68+
69+
if ( subpart_count != 0 ) {
70+
out << prefix << "There are " << std::distance ( mp.subpart_begin (), mp.subpart_end ()) << " sub parts" << std::endl;
71+
for ( mime_part::constPartIter iter = mp.subpart_begin (); iter != mp.subpart_end (); ++iter )
72+
DumpStructure ( out, NULL, **iter, prefix + " " );
73+
}
74+
}
75+
76+
int main ( int argc, char * argv[] ) {
77+
78+
if ( argc == 1 )
79+
std::cerr << "Usage: basic_parsing <files-to-parse>" << std::endl;
80+
81+
for ( int i = 1; i < argc; ++i ) {
82+
boost::shared_ptr<mime_part> rmp;
83+
try {
84+
std::ifstream in ( argv[i] );
85+
if ( !in ) {
86+
std::cerr << "Can't open file " << argv[i] << std::endl;
87+
continue;
88+
}
89+
90+
in >> std::noskipws;
91+
std::cout << "**********************************" << std::endl;
92+
rmp = mime_part::parse_mime ( in );
93+
}
94+
catch ( const boost::mime::mime_parsing_error &err ) {
95+
std::cout << "Caught an error parsing '" << argv[i] << "'" << std::endl;
96+
std::cout << " " << err.what () << std::endl;
97+
continue;
98+
}
99+
catch ( const boost::exception &berr ) {
100+
std::cout << "Caught an boost error parsing '" << argv[i] << "'" << std::endl;
101+
// std::cout << " " << berr.what () << std::endl;
102+
continue;
103+
}
104+
105+
try {
106+
DumpStructure ( std::cout, argv[i], *rmp, std::string ());
107+
// std::ofstream out ( (std::string ( argv[i] ) + "-Results").c_str (), std::ios::binary );
108+
// out << rmp;
109+
}
110+
catch ( const std::runtime_error &err ) {
111+
std::cout << "Caught an error writing '" << argv[i] << "'" << std::endl;
112+
std::cout << " " << err.what () << std::endl;
113+
continue;
114+
}
115+
}
116+
117+
return 0;
118+
}

libs/mime/example/basic_usage.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//
2+
// Copyright Marshall Clow 2009-2010
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
//
7+
//
8+
9+
#include <boost/mime.hpp>
10+
11+
#include <fstream>
12+
#include <iostream>
13+
#include <iterator>
14+
#include <sstream>
15+
16+
struct my_traits {
17+
typedef std::string string_type;
18+
// typedef std::pair < std::string, string_type > header_type;
19+
typedef std::string body_type;
20+
};
21+
22+
typedef boost::mime::basic_mime<my_traits> mime_part;
23+
24+
int main ( int argc, char * argv[] ) {
25+
26+
// (1) a really simple part
27+
mime_part mp ( "text", "plain" );
28+
mp.set_body ( "Hello World\n", 12 );
29+
std::cout << mp;
30+
31+
// Three trips around the house before we go through the door.
32+
// Make a part, copy it onto the heap, and wrap it into a shared pointer.
33+
std::cout << "*******" << std::endl;
34+
std::string str ( "<HTML><HEAD></HEAD><BODY>Hi Mom!</BODY></HTML>\n" );
35+
boost::shared_ptr<mime_part> mp0 (
36+
new mime_part ( mime_part::make_simple_part ( "text", "html", str.begin (), str.end ())));
37+
std::cout << mp0;
38+
39+
std::cout << "*******" << std::endl;
40+
boost::shared_ptr<mime_part> mp1 ( new mime_part ( "text", "plain" ));
41+
mp1->set_body ( "This is a test.....\n", 20 );
42+
mp1->append_phrase_to_content_type ( "charset", "usascii" );
43+
std::cout << mp1;
44+
45+
// Build a multipart
46+
mime_part mp2 ( "multipart", "multiple" );
47+
mp2.set_body ( "This is the body of a multipart\n", 32 );
48+
mp2.append_part ( mp0 );
49+
mp2.append_part ( mp1 );
50+
51+
// stream it out to a string, then make a new part from the string
52+
std::ostringstream os1, os2;
53+
os1 << mp2;
54+
std::istringstream is ( os1.str()); is >> std::noskipws;
55+
boost::shared_ptr<mime_part> strmp = mime_part::parse_mime ( is );
56+
os2 << strmp;
57+
if ( os1.str () == os2.str ())
58+
std::cout << "Strings match!!" << std::endl;
59+
else {
60+
// Write the differences out to files for examination
61+
std::cout << "##Strings differ!!" << std::endl;
62+
std::ofstream t1 ( "test1.out", std::ios::binary );
63+
t1 << os1.str ();
64+
std::ofstream t2 ( "test2.out", std::ios::binary );
65+
t2 << os2.str ();
66+
}
67+
68+
return 0;
69+
}

libs/mime/test/Jamfile.v2

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# Copyright Marshall Clow 2010
3+
# Distributed under the Boost Software License, Version 1.0.
4+
# (See accompanying file LICENSE_1_0.txt or copy at
5+
# http://www.boost.org/LICENSE_1_0.txt)
6+
7+
import os ;
8+
9+
project mime_test :
10+
requirements
11+
<include>../../../
12+
<source>/boost//unit_test_framework
13+
<toolset>msvc:<define>WIN32_LEAN_AND_MEAN
14+
<toolset>msvc:<define>_SCL_SECURE_NO_WARNINGS
15+
<c++-template-depth>256
16+
<link>static
17+
;
18+
19+
unit-test mime_round_trip : mime-roundtrip.cpp ;
20+
21+
exe mime-structure : mime-structure.cpp ;
22+

0 commit comments

Comments
 (0)