|  | Home |

# QMailMessageBody Class Reference

The QMailMessageBody class contains the body element of a message or message part. More...

        #include <QMailMessageBody>

This class is under development and is subject to change.

Inherits QMailMessageBodyFwd.

- List of all members, including inherited members

## Public Functions

QMailMessageContentType | contentType () const
QByteArray | data ( EncodingFormat format ) const
QString | data () const
bool | isEmpty () const
int | length () const
bool | toFile ( const QString & filename, EncodingFormat format ) const
bool | toStream ( QDataStream & out, EncodingFormat format ) const
bool | toStream ( QTextStream & out ) const
TransferEncoding | transferEncoding () const

## Static Public Members

QMailMessageBody | fromData ( const QByteArray & input, const QMailMessageContentType & type, TransferEncoding encoding, EncodingStatus status )
QMailMessageBody | fromData ( const QString & input, const QMailMessageContentType & type, TransferEncoding encoding )
QMailMessageBody | fromFile ( const QString & filename, const QMailMessageContentType & type, TransferEncoding encoding, EncodingStatus status )
QMailMessageBody | fromStream ( QDataStream & in, const QMailMessageContentType & type, TransferEncoding encoding, EncodingStatus status )
QMailMessageBody | fromStream ( QTextStream & in, const QMailMessageContentType & type, TransferEncoding encoding )

## Detailed Description

The QMailMessageBody class contains the body element of a message or message part.

The body of a message or message part is treated as an atomic unit by the Qt Extended messaging library. It can only be inserted into a message part container or extracted from one. It can be inserted or extracted using either a QByteArray, a QDataStream or to/from a file. In the case of unicode text data, the insertion and extraction can operate on either a QString, a QTextStream or to/from a file.

The body data must be associated with a QMailMessageContentType describing that data. When extracting body data from a message or part to unicode text, the content type description must include a parameter named 'charset'; this parameter is used to locate a QTextCodec to be used to extract unicode data from the body data octet stream.

If the Content-Type of the data is a subtype of "text", then line-ending translation will be used to ensure that the text is transmitted with CR/LF line endings. The text data supplied to QMailMessageBody must conform to the RFC 2822 restrictions on maximum line lengths: "Each line of characters MUST be no more than 998 characters, and SHOULD be no more than 78 characters, excluding the CRLF." Textual message body data decoded from a QMailMessageBody object will have transmitted CR/LF line endings converted to `\n` on extraction.

The body data can also be encoded from 8-bit octets to 7-bit ASCII characters for safe transmission through obsolete email systems. When creating an instance of the QMailMessageBody class, the encoding to be used must be specified using the QMailMessageBody::TransferEncoding enum.

See also QMailMessagePart, QMailMessage, and QTextCodec.

## Member Function Documentation

### QMailMessageContentType QMailMessageBody::contentType () const

Returns the content type that the body was created with.

### QByteArray QMailMessageBody::data ( EncodingFormat format ) const

Returns the data of the message body as a QByteArray. If format is QMailMessageBody::Encoded, then the data is written in the transfer encoding it was created with; otherwise, it is written in unencoded form.

See also QMailCodec.

### QString QMailMessageBody::data () const

Returns the data of the message body as a QString, in unencoded form. Line-endings transmitted as CR/LF pairs are converted to `\n` on extraction.

The 'charset' parameter of the body's content type is used to locate the appropriate QTextCodec to convert the data from an octet stream to unicode, if necessary.

See also QMailCodec, QMailMessageContentType, and QTextCodec.

### QMailMessageBody QMailMessageBody::fromData ( const QByteArray & input, const QMailMessageContentType & type, TransferEncoding encoding, EncodingStatus status ) `[static]`

Creates a message body from the data contained in input, having the content type type. If status is QMailMessageBody::RequiresEncoding, the data from the file will be encoded to encoding for transmission; otherwise it must already be in that encoding, which will be reported to recipients of the data.

If type is a subtype of "text", the data will be treated as text, and line-ending translation will be employed. Otherwise, the file will be treated as containing binary data.

If encoding is QMailMessageBody::QuotedPrintable, encoding will be performed assuming conformance to RFC 2045.

See also QMailCodec and QMailQuotedPrintableCodec.

### QMailMessageBody QMailMessageBody::fromData ( const QString & input, const QMailMessageContentType & type, TransferEncoding encoding ) `[static]`

Creates a message body from the data contained in input, having the content type type. The data from input will be encoded to encoding for transmission, and line-ending translation will be employed. The unicode text data will be converted to an octet stream using a QTextCodec object identified by the 'charset' parameter of type.

If encoding is QMailMessageBody::QuotedPrintable, encoding will be performed assuming conformance to RFC 2045.

See also QMailCodec, QMailMessageContentType, and QTextCodec.

### QMailMessageBody QMailMessageBody::fromFile ( const QString & filename, const QMailMessageContentType & type, TransferEncoding encoding, EncodingStatus status ) `[static]`

Creates a message body from the data contained in the file filename, having the content type type. If status is QMailMessageBody::RequiresEncoding, the data from the file will be encoded to encoding for transmission; otherwise it must already be in that encoding, which will be reported to recipients of the data.

If type is a subtype of "text", the data will be treated as text, and line-ending translation will be employed. Otherwise, the file will be treated as containing binary data. If the file contains unicode text data, it will be converted to an octet stream using a QTextCodec object identified by the 'charset' parameter of type.

If encoding is QMailMessageBody::QuotedPrintable, encoding will be performed assuming conformance to RFC 2045.

Note that the data is not actually read from the file until it is requested by another function.

See also QMailCodec, QMailQuotedPrintableCodec, QMailMessageContentType, and QTextCodec.

### QMailMessageBody QMailMessageBody::fromStream ( QDataStream & in, const QMailMessageContentType & type, TransferEncoding encoding, EncodingStatus status ) `[static]`

Creates a message body from the data read from in, having the content type type. If status is QMailMessageBody::RequiresEncoding, the data from the file will be encoded to encoding for transmission; otherwise it must already be in that encoding, which will be reported to recipients of the data.

If type is a subtype of "text", the data will be treated as text, and line-ending translation will be employed. Otherwise, the file will be treated as containing binary data.

If encoding is QMailMessageBody::QuotedPrintable, encoding will be performed assuming conformance to RFC 2045.

See also QMailCodec and QMailQuotedPrintableCodec.

### QMailMessageBody QMailMessageBody::fromStream ( QTextStream & in, const QMailMessageContentType & type, TransferEncoding encoding ) `[static]`

Creates a message body from the data read from in, having the content type type. The data read from in will be encoded to encoding for transmission, and line-ending translation will be employed. The unicode text data will be converted to an octet stream using a QTextCodec object identified by the 'charset' parameter of type.

If encoding is QMailMessageBody::QuotedPrintable, encoding will be performed assuming conformance to RFC 2045.

See also QMailCodec, QMailQuotedPrintableCodec, QMailMessageContentType, and QTextCodec.

### bool QMailMessageBody::isEmpty () const

Returns true if the body does not contain any data.

### int QMailMessageBody::length () const

Returns the length of the body data in bytes.

### bool QMailMessageBody::toFile ( const QString & filename, EncodingFormat format ) const

Writes the data of the message body to the file named filename. If format is QMailMessageBody::Encoded, then the data is written in the transfer encoding it was created with; otherwise, it is written in unencoded form.

If the body has a content type with a QMailMessageContentType::type() of "text", and the content type parameter 'charset' is not empty, then the unencoded data will be written as unicode text data, using the charset parameter to locate the appropriate QTextCodec.

Returns false if the operation causes an error; otherwise returns true.

See also QMailCodec, QMailMessageContentType, and QTextCodec.

### bool QMailMessageBody::toStream ( QDataStream & out, EncodingFormat format ) const

Writes the data of the message body to the stream out. If format is QMailMessageBody::Encoded, then the data is written in the transfer encoding it was created with; otherwise, it is written in unencoded form.

Returns false if the operation causes an error; otherwise returns true.

See also QMailCodec.

### bool QMailMessageBody::toStream ( QTextStream & out ) const

Writes the data of the message body to the stream out, in unencoded form. Line-endings transmitted as CR/LF pairs are converted to `\n` on extraction. Returns false if the operation causes an error; otherwise returns true.

The 'charset' parameter of the body's content type is used to locate the appropriate QTextCodec to convert the data from an octet stream to unicode, if necessary.

See also QMailCodec, QMailMessageContentType, and QTextCodec.

### TransferEncoding QMailMessageBody::transferEncoding () const

Returns the transfer encoding type that the body was created with.