MIME section information objects get instantiated by:
x::mime::make_multipart_parser
()
and
x::mime::make_message_rfc822_parser
().
This also incldues the derived
x::mime::make_parser
().
x::mime::sectioninfo
is a reference to
a reference-counted
x::mime::sectioninfoObj
object.
This object contains the size of the header and the body portion of the
MIME object, and a std::vector
of
x::mime::const_sectioninfo
for the entities
in a multipart MIME entity (or the sole
message/rfc822
).
It's possible to subclass
x::mime::sectioninfoObj
in order to store
additional custom metadata about each MIME section, and have the
entity parser functions take care of constructing all the section
information objects for all MIME entities in the document.
The requirements for a subclass of a
x::mime::sectioninfoObj
are:
A default constructor and a constructor for the subsection of a parent MIME entity.
A create_subsection
() method that returns
an x::ref
to
a new instance of the subclass which was constructed by passing
a x::ref
referencing the parent object, the
one whose create_subsection
() method
got invoked, to the x::mime::sectioninfoObj
constructor for the new object's instance.
A reference to the custom subclass gets passed to:
The last parameter to
x::mime::make_document_entity_parser
().
In place of the x::mime::sectioninfo
parameter tox::mime::make_multipart_parser
(),
x::mime::make_message_rfc822_parser
(),
and x::mime::make_parser
().
The section processor factory that gets passed to these
entity parser creators receives a reference to the custom
subclass in place of the
x::mime::sectioninfo
.
x::mime::make_document_entity_parser
()
forwards the parameter it receives itself, and the others
take care of invoking create_subsection
().
examples/mime/bodydecoder5.C
is a modified version of bodydecoder3.C
that
shows how to use a custom section information class that holds each
MIME entity's MIME type, that's added to the output of the
MIME document's structure:
$ cat bodydecoder3.txt
Subject: test
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="xxx"
--xxx
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
Hello=A0
--xxx
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
world!
--xxx--
$ ./bodydecoder <bodydecoder3.txt
Hello world!
MIME section 1 (multipart/mixed) starts at character offset 0
79 bytes in the header, 217 bytes in the body.
4 lines in the header, 12 lines in the body.
MIME section 1.1 (text/plain) starts at character offset 85
90 bytes in the header, 8 bytes in the body.
3 lines in the header, 1 lines in the body.
No trailing newline
MIME section 1.2 (text/plain) starts at character offset 190
90 bytes in the header, 7 bytes in the body.
3 lines in the header, 1 lines in the body.