Class Bodypart.

Inherits Multipart

The Bodypart class models a single MIME body part. It is a subclass of Multipart, and an adjunct to Message.

Every Bodypart has a number(), and contains text(), data(), or a message(), based on its contentType(). It knows how many numBytes(), numEncodedBytes() and numEncodedLines() of data it contains, and can present itself asText().

This class is also responsible for parsing bodyparts in messages.

Bodypart::Bodypart( uint n, Multipart * p )

Constructs a Bodypart with number n and parent p.

Bodypart::Bodypart()

Constructs an empty Bodypart. This is meant to be used only by parseBodypart().

Reimplements Multipart::Multipart().

EString Bodypart::asText() const

Returns the text representation of this Bodypart.

Notes: This function seems uncomfortable. It returns just one of many possible text representations, and the exact choice seems arbitrary, and finally, it does rather overlap with text() and data().

We probably should transition away from this function.

The exact representation returned uses base64 encoding for data types and no ContentTransferEncoding. For text types, it encodes the text according to the ContentType.

EString::Encoding Bodypart::contentTransferEncoding() const

Returns the content transfer encoding of this Bodypart, which may be any of EString::Binary, EString::QuotedPrintable and EString::Base64.

Note that data() and text() return the canonical representation of the body, not encoded with this.

ContentType * Bodypart::contentType() const

Returns the ContentType of this Bodypart, which may be a null pointer in case the Content-Type is the default one. The default is either text/plain or message/rfc822.

The Bodypart cannot find the default alone, since it depends on the surrounding type.

EString Bodypart::data() const

Returns this Bodypart's content, provided it has an 8-bit type. If this Bodypart is a text part, data() returns an empty string.

EString Bodypart::error() const

Returns an error message describing why this bodypart is bad, or an empty string if nothing seems to be the matter.

uint Bodypart::id() const

Returns the id of this bodypart in the bodyparts table, or 0 if it has not been stored there yet.

bool Bodypart::isBodypart() const

Returns true.

Reimplements Multipart::isBodypart().

Message * Bodypart::message() const

Returns a pointer to the subsidiary message, provided this is a message/rfc822 bodypart, or a null pointer in other cases.

uint Bodypart::numBytes() const

Returns the number of bytes in this body part, as set using setNumBytes().

uint Bodypart::numEncodedBytes() const

Returns the value set by setNumEncodedBytes(). Compare to numBytes().

uint Bodypart::numEncodedLines() const

Returns the number of lines in this body part, as set using setNumEncodedLines().

uint Bodypart::number() const

Returns a number that reflects this Bodypart's position within its containing Multipart.

static Bodypart * Bodypart::parseBodypart( uint start, uint end, const EString & rfc2822, Header * h, Multipart * parent )

Parses the part of rfc2822 from start to end (not including end) as a single bodypart with MIME/RFC 822 header h.

This removes the "charset" argument from the Content-Type field in h.

The parent argument is provided so that nested message/rfc822 bodyparts without a Date field may be fixed with reference to the Date field in the enclosing bodypart.

static void Bodypart::parseMultipart( uint i, uint end, const EString & rfc2822, const EString & divider, bool digest, List< Bodypart > * children, Multipart * parent )

Parses the part of rfc2822 from index i to (but not including) end, dividing the part into bodyparts wherever the boundary divider occurs and adding each bodypart to children, and setting the correct parent. divider does not contain the leading or trailing hyphens. digest is true for multipart/digest and false for other types.

void Bodypart::setData( const EString & s )

Sets the data of this Bodypart to s. For use only by MessageBodyFetcher for now.

void Bodypart::setId( uint id )

Sets the id of this bodypart to id. Meant for use only by the Injector.

void Bodypart::setMessage( Message * m )

Notifies this Bodypart that it has a subsidiary message m. This function is only meaningful if the Bodypart has content-type message/rfc822.

void Bodypart::setNumBytes( uint n )

Notifies this Bodypart that it contains n bytes of data(). The initial value is 0.

void Bodypart::setNumEncodedBytes( uint n )

Notifies this Bodypart that it contains n bytes of asText() when fully encoded using the current ContentTransferEncoding. The initial value is 0.

Compare to numBytes(), which returns the raw number of bytes.

void Bodypart::setNumEncodedLines( uint n )

Notifies this Bodypart that it contains n lines of text() once encoded some ContentTransferEncoding. The initial value is 0.

void Bodypart::setText( const UString & s )

Sets the text of this Bodypart to s. For use only by MessageBodyFetcher for now.

UString Bodypart::text() const

Returns the text of this Bodypart. MUST NOT be called for non-text parts (whose contents are not known to be well-formed text).

This web page based on source code belonging to The Archiveopteryx Developers. All rights reserved.