VMime
body Class Reference

#include <body.hpp>

Inheritance diagram for body:
Collaboration diagram for body:

Public Member Functions

 body ()
 ~body ()
void appendPart (shared_ptr< bodyPart > part)
void insertPartBefore (shared_ptr< bodyPart > beforePart, shared_ptr< bodyPart > part)
void insertPartBefore (const size_t pos, shared_ptr< bodyPart > part)
void insertPartAfter (shared_ptr< bodyPart > afterPart, shared_ptr< bodyPart > part)
void insertPartAfter (const size_t pos, shared_ptr< bodyPart > part)
void removePart (shared_ptr< bodyPart > part)
void removePart (const size_t pos)
void removeAllParts ()
size_t getPartCount () const
bool isEmpty () const
shared_ptr< bodyPartgetPartAt (const size_t pos)
const shared_ptr< const bodyPartgetPartAt (const size_t pos) const
const std::vector< shared_ptr< const bodyPart > > getPartList () const
const std::vector< shared_ptr< bodyPart > > getPartList ()
const stringgetPrologText () const
void setPrologText (const string &prologText)
const stringgetEpilogText () const
void setEpilogText (const string &epilogText)
const shared_ptr< const contentHandlergetContents () const
void setContents (shared_ptr< const contentHandler > contents)
void setContents (shared_ptr< const contentHandler > contents, const mediaType &type)
void setContents (shared_ptr< const contentHandler > contents, const mediaType &type, const charset &chset)
void setContents (shared_ptr< const contentHandler > contents, const mediaType &type, const charset &chset, const encoding &enc)
void setContentType (const mediaType &type, const charset &chset)
void setContentType (const mediaType &type)
const mediaType getContentType () const
void setCharset (const charset &chset)
const charset getCharset () const
void setEncoding (const encoding &enc)
const encoding getEncoding () const
shared_ptr< componentclone () const
void copyFrom (const component &other)
bodyoperator= (const body &other)
const std::vector< shared_ptr< component > > getChildComponents ()
size_t getGeneratedSize (const generationContext &ctx)
Public Member Functions inherited from component
 component ()
virtual ~component ()
void parse (const string &buffer)
void parse (const parsingContext &ctx, const string &buffer)
void parse (shared_ptr< utility::inputStream > inputStream, const size_t length)
void parse (const string &buffer, const size_t position, const size_t end, size_t *newPosition=NULL)
void parse (const parsingContext &ctx, const string &buffer, const size_t position, const size_t end, size_t *newPosition=NULL)
void parse (shared_ptr< utility::inputStream > inputStream, const size_t position, const size_t end, size_t *newPosition=NULL)
void parse (const parsingContext &ctx, shared_ptr< utility::inputStream > inputStream, const size_t position, const size_t end, size_t *newPosition=NULL)
virtual const string generate (const size_t maxLineLength=lineLengthLimits::infinite, const size_t curLinePos=0) const
virtual void generate (utility::outputStream &outputStream, const size_t curLinePos=0, size_t *newLinePos=NULL) const
virtual void generate (const generationContext &ctx, utility::outputStream &outputStream, const size_t curLinePos=0, size_t *newLinePos=NULL) const
size_t getParsedOffset () const
size_t getParsedLength () const

Static Public Member Functions

static const string generateRandomBoundaryString ()
static bool isValidBoundary (const string &boundary)

Protected Member Functions

size_t findNextBoundaryPosition (shared_ptr< utility::parserInputStreamAdapter > parser, const string &boundary, const size_t position, const size_t end, size_t *boundaryStart, size_t *boundaryEnd)
void parseImpl (const parsingContext &ctx, shared_ptr< utility::parserInputStreamAdapter > parser, const size_t position, const size_t end, size_t *newPosition=NULL)
void generateImpl (const generationContext &ctx, utility::outputStream &os, const size_t curLinePos=0, size_t *newLinePos=NULL) const
Protected Member Functions inherited from component
void setParsedBounds (const size_t start, const size_t end)
virtual void parseImpl (const parsingContext &ctx, const string &buffer, const size_t position, const size_t end, size_t *newPosition=NULL)
Protected Member Functions inherited from object
 object ()
 object (const object &)
objectoperator= (const object &)
virtual ~object ()

Detailed Description

Body section of a MIME part.

Constructor & Destructor Documentation

◆ body()

body ( )

Referenced by bodyPart, copyFrom(), and operator=().

◆ ~body()

~body ( )

Member Function Documentation

◆ appendPart()

void appendPart ( shared_ptr< bodyPart > part)

Add a part at the end of the list.

Parameters
partpart to append

Referenced by bodyPart.

◆ clone()

shared_ptr< component > clone ( ) const
virtual

Clone this component.

Returns
a copy of this component

Implements component.

Referenced by bodyPart.

◆ copyFrom()

void copyFrom ( const component & other)
virtual

Replace data in this component by data in other component.

Both components must be of the same type.

Exceptions
std::bad_cast_exceptionif the components are not of the same (dynamic) type
Parameters
otherother component to copy data from

Implements component.

References body(), component::component(), getPartAt(), getPartCount(), and removeAllParts().

Referenced by bodyPart, and operator=().

◆ findNextBoundaryPosition()

size_t findNextBoundaryPosition ( shared_ptr< utility::parserInputStreamAdapter > parser,
const string & boundary,
const size_t position,
const size_t end,
size_t * boundaryStart,
size_t * boundaryEnd )
protected

Finds the next boundary position in the parsing buffer.

Parameters
parserparser object
boundaryboundary string (without "--" nor CR/LF)
positionstart position
endend position
boundaryStartwill hold the start position of the boundary (including any CR/LF and "--" before the boundary)
boundaryEndwill hold the end position of the boundary (position just before the CRLF or "--" which follows)
Returns
the position of the boundary string, or npos if not found

References vmime::end(), and vmime::npos.

Referenced by bodyPart, and parseImpl().

◆ generateImpl()

◆ generateRandomBoundaryString()

const string generateRandomBoundaryString ( )
static

Generate a new random boundary string.

Returns
randomly generated boundary string

References random::getNext(), and random::getTime().

Referenced by bodyPart, and generateImpl().

◆ getCharset()

const charset getCharset ( ) const

Return the charset of the data contained in the body contents.

This is a shortcut for getHeader()->ContentType()->getCharset() on the parent part.

Returns
charset of body contents

References vmime::fields::CONTENT_TYPE, and vmime::charsets::US_ASCII.

Referenced by bodyPart.

◆ getChildComponents()

const std::vector< shared_ptr< component > > getChildComponents ( )
virtual

Return the list of children of this component.

Returns
list of child components

Implements component.

References vmime::copy_vector().

Referenced by bodyPart.

◆ getContents()

const shared_ptr< const contentHandler > getContents ( ) const

Return a read-only reference to body contents.

Returns
read-only body contents

Referenced by bodyPart.

◆ getContentType()

const mediaType getContentType ( ) const

Return the media type of the data contained in the body contents.

This is a shortcut for getHeader()->ContentType()->getValue() on the parent part.

Returns
media type of body contents

References vmime::fields::CONTENT_TYPE, vmime::mediaTypes::TEXT, and vmime::mediaTypes::TEXT_PLAIN.

Referenced by bodyPart, and generateImpl().

◆ getEncoding()

const encoding getEncoding ( ) const

Return the encoding used to encode the body contents.

This is a shortcut for getHeader()->ContentTransferEncoding()->getValue() on the parent part.

Returns
encoding of body contents

References vmime::fields::CONTENT_TRANSFER_ENCODING, and vmime::encodingTypes::SEVEN_BIT.

Referenced by bodyPart, generateImpl(), and getGeneratedSize().

◆ getEpilogText()

const string & getEpilogText ( ) const

Return the epilog text.

Returns
epilog text

Referenced by bodyPart.

◆ getGeneratedSize()

size_t getGeneratedSize ( const generationContext & ctx)
virtual

Get the number of bytes that will be used by this component when it is generated.

This may be a heuristically-derived estimate, but such an estimated size should always be larger than the actual generated size.

Parameters
ctxgeneration context
Returns
component size when generated

Reimplemented from component.

References text::encodeAndFold(), text::FORCE_NO_ENCODING, encoding::getEncoder(), getEncoding(), getPartAt(), getPartCount(), text::isEmpty(), and text::NO_NEW_LINE_SEQUENCE.

Referenced by bodyPart.

◆ getPartAt() [1/2]

shared_ptr< bodyPart > getPartAt ( const size_t pos)

Return the part at the specified position.

Parameters
posposition
Returns
part at position 'pos'

Referenced by bodyPart, copyFrom(), generateImpl(), and getGeneratedSize().

◆ getPartAt() [2/2]

const shared_ptr< const bodyPart > getPartAt ( const size_t pos) const

Return the part at the specified position.

Parameters
posposition
Returns
part at position 'pos'

◆ getPartCount()

size_t getPartCount ( ) const

Return the number of parts in the list.

Returns
number of parts

Referenced by bodyPart, copyFrom(), generateImpl(), and getGeneratedSize().

◆ getPartList() [1/2]

const std::vector< shared_ptr< bodyPart > > getPartList ( )

Return the part list.

Returns
list of parts

◆ getPartList() [2/2]

const std::vector< shared_ptr< const bodyPart > > getPartList ( ) const

Return the part list.

Returns
list of parts

Referenced by bodyPart.

◆ getPrologText()

const string & getPrologText ( ) const

Return the prolog text.

Returns
prolog text

Referenced by bodyPart.

◆ insertPartAfter() [1/2]

void insertPartAfter ( const size_t pos,
shared_ptr< bodyPart > part )

Insert a new part after the specified position.

Parameters
posposition of the part before the new part
partpart to insert

◆ insertPartAfter() [2/2]

void insertPartAfter ( shared_ptr< bodyPart > afterPart,
shared_ptr< bodyPart > part )

Insert a new part after the specified part.

Parameters
afterPartpart after which the new part will be inserted
partpart to insert
Exceptions
exceptions::no_such_partif the part is not in the list

Referenced by bodyPart.

◆ insertPartBefore() [1/2]

void insertPartBefore ( const size_t pos,
shared_ptr< bodyPart > part )

Insert a new part before the specified position.

Parameters
posposition at which to insert the new part (0 to insert at the beginning of the list)
partpart to insert

◆ insertPartBefore() [2/2]

void insertPartBefore ( shared_ptr< bodyPart > beforePart,
shared_ptr< bodyPart > part )

Insert a new part before the specified part.

Parameters
beforePartpart before which the new part will be inserted
partpart to insert
Exceptions
exceptions::no_such_partif the part is not in the list

Referenced by bodyPart.

◆ isEmpty()

bool isEmpty ( ) const

Tests whether the list of parts is empty.

Returns
true if there is no part, false otherwise

Referenced by bodyPart.

◆ isValidBoundary()

bool isValidBoundary ( const string & boundary)
static

Test a boundary string for validity (as defined in RFC #1521, page 19).

Parameters
boundaryboundary string to test
Returns
true if the boundary string is valid, false otherwise

References vmime::end().

Referenced by bodyPart.

◆ operator=()

body & operator= ( const body & other)

References body(), and copyFrom().

Referenced by bodyPart.

◆ parseImpl()

◆ removeAllParts()

void removeAllParts ( )

Remove all parts from the list.

Referenced by bodyPart, copyFrom(), and parseImpl().

◆ removePart() [1/2]

void removePart ( const size_t pos)

Remove the part at the specified position.

Parameters
posposition of the part to remove

◆ removePart() [2/2]

void removePart ( shared_ptr< bodyPart > part)

Remove the specified part from the list.

Parameters
partpart to remove
Exceptions
exceptions::no_such_partif the part is not in the list

Referenced by bodyPart.

◆ setCharset()

void setCharset ( const charset & chset)

Set the charset of contents.

If the type is not set, it will be set to default "text/plain" type.

Parameters
chsetcharset of contents

References vmime::fields::CONTENT_TYPE, setContentType(), vmime::mediaTypes::TEXT, and vmime::mediaTypes::TEXT_PLAIN.

Referenced by bodyPart.

◆ setContents() [1/4]

void setContents ( shared_ptr< const contentHandler > contents)

Set the body contents.

Parameters
contentsnew body contents

Referenced by bodyPart.

◆ setContents() [2/4]

void setContents ( shared_ptr< const contentHandler > contents,
const mediaType & type )

Set the body contents and type.

Parameters
contentsnew body contents
typetype of contents

References setContentType().

◆ setContents() [3/4]

void setContents ( shared_ptr< const contentHandler > contents,
const mediaType & type,
const charset & chset )

Set the body contents, type and charset.

Parameters
contentsnew body contents
typetype of contents
chsetcharset of contents

References setContentType().

◆ setContents() [4/4]

void setContents ( shared_ptr< const contentHandler > contents,
const mediaType & type,
const charset & chset,
const encoding & enc )

Set the body contents, type, charset and encoding.

Parameters
contentsnew body contents
typetype of contents
chsetcharset of contents
enccontents encoding

References setContentType(), and setEncoding().

◆ setContentType() [1/2]

void setContentType ( const mediaType & type)

Set the MIME type of contents.

Parameters
typeMIME media type of contents

◆ setContentType() [2/2]

void setContentType ( const mediaType & type,
const charset & chset )

Set the MIME type and charset of contents.

If a charset is defined, it will not be modified.

Parameters
typeMIME media type of contents
chsetcharset of contents

References vmime::dynamicCast().

Referenced by bodyPart, setCharset(), setContents(), setContents(), and setContents().

◆ setEncoding()

void setEncoding ( const encoding & enc)

Set the output encoding of contents.

Contents will be encoded (or re-encoded) when this node is being generated.

Parameters
encencoding of contents

References headerField::setValue().

Referenced by bodyPart, and setContents().

◆ setEpilogText()

void setEpilogText ( const string & epilogText)

Set the epilog text.

Parameters
epilogTextnew epilog text

Referenced by bodyPart.

◆ setPrologText()

void setPrologText ( const string & prologText)

Set the prolog text.

Parameters
prologTextnew prolog text

Referenced by bodyPart.


The documentation for this class was generated from the following files: