|  | Home |

# QMailCodec Class Reference

The QMailCodec class provides mechanisms for encoding and decoding between 7-bit ASCII strings and arbitrary octet sequences. More...

        #include <QMailCodec>

This class is under development and is subject to change.

Inherited by QMailBase64Codec, QMailLineEndingCodec, QMailPassThroughCodec, and QMailQuotedPrintableCodec.

- List of all members, including inherited members

## Public Functions

virtual | ~QMailCodec ()
virtual void | decode ( QTextStream & out, QDataStream & in, const QString & charset )
virtual void | decode ( QDataStream & out, QDataStream & in )
QString | decode ( const QByteArray & input, const QString & charset )
QByteArray | decode ( const QByteArray & input )
virtual void | encode ( QDataStream & out, QTextStream & in, const QString & charset = "UTF-8" )
virtual void | encode ( QDataStream & out, QDataStream & in )
QByteArray | encode ( const QString & input, const QString & charset = "UTF-8" )
QByteArray | encode ( const QByteArray & input )
virtual QString | name () const = 0

## Static Public Members

QTextCodec * | codecForName ( const QByteArray & charset, bool translateAscii = true )
void | copy ( QDataStream & out, QDataStream & in )
void | copy ( QTextStream & out, QTextStream & in )

## Protected Functions

virtual void | decodeChunk ( QDataStream & out, const char * input, int length, bool finalChunk ) = 0
virtual void | encodeChunk ( QDataStream & out, const unsigned char * input, int length, bool finalChunk ) = 0

## Detailed Description

The QMailCodec class provides mechanisms for encoding and decoding between 7-bit ASCII strings and arbitrary octet sequences.

Messages transferred via the SMTP protocol must be encoded in 7-bit ASCII characters, even though their contents are typically composed in sequences of 8-bit octets. The QMailCodec class provides an interface through which data can be easily converted between an 8-bit octet sequence and a 7-bit ASCII character sequence.

QMailCodec is an abstract class; in order to perform a coding operation, a derived class must be used that provides a policy for mapping 8-bit data to and from 7-bit ASCII characters. This policy is implemented by overriding the encodeChunk() and decodeChunk() virtual functions.

Using the QMailCodec interface, data can be encoded or decoded from an input QDataStream to an output QDataStream, or for convenience, from an input QByteArray to an output QByteArray.

If the data to be encoded is in unicode form, then the QMailCodec interface can be used to convert the data to ASCII via an intermediate QTextCodec, which converts the incoming text to a sequence of octets. The QTextCodec used is specified by the name of the encoding produced, or that decoded when decoding an ASCII input sequence. QMailCodec provides functions to encode from a QTextStream to a QDataStream, and to decode from a QDataStream to a QTextStream. For convenience, it is also possible to encode a QString to a QByteArray, and to decode a QByteArray to a QString.

See also QDataStream, QTextStream, and QTextCodec.

## Member Function Documentation

### QMailCodec::~QMailCodec () `[virtual]`

Destroys a QMailCodec instance.

### QTextCodec * QMailCodec::codecForName ( const QByteArray & charset, bool translateAscii = true ) `[static]`

Returns a pointer to an appropriate QTextCodec based on charset. If charset is ascii and translateAscii is true, it will use the Latin-1 codec.

Returns 0 if could not locate a codec.

### void QMailCodec::copy ( QDataStream & out, QDataStream & in ) `[static]`

Writes the data read from the stream in to the stream out, without conversion.

### void QMailCodec::copy ( QTextStream & out, QTextStream & in ) `[static]`

Writes the data read from the stream in to the stream out, without conversion.

### void QMailCodec::decode ( QTextStream & out, QDataStream & in, const QString & charset ) `[virtual]`

Writes the data read from the stream in to the stream out, converting from a sequence of 7-bit ASCII characters. The characters read from in are decoded from the text encoding charset to unicode.

See also QTextCodec::codecForName().

### void QMailCodec::decode ( QDataStream & out, QDataStream & in ) `[virtual]`

Writes the data read from the stream in to the stream out, converting from a sequence of 7-bit ASCII characters.

### QString QMailCodec::decode ( const QByteArray & input, const QString & charset )

Returns a QString containing characters decoded from the text encoding charset, which are decoded from the sequence of 7-bit ASCII characters read from input.

See also QTextCodec::codecForName().

### QByteArray QMailCodec::decode ( const QByteArray & input )

Returns a QByteArray containing the octets decoded from the sequence of 7-bit ASCII characters in input.

### void QMailCodec::decodeChunk ( QDataStream & out, const char * input, int length, bool finalChunk ) `[pure virtual protected]`

Overridden by derived classes to perform a decoding operation. The implementation function must decode length ASCII characters at the location input, writing the resulting octets to the stream out. If finalChunk is false, further calls will be made to decodeChunk() with continued input data. Otherwise, the decoding operation is complete.

### void QMailCodec::encode ( QDataStream & out, QTextStream & in, const QString & charset = "UTF-8" ) `[virtual]`

Writes the data read from the stream in to the stream out, as a sequence of 7-bit ASCII characters. The unicode characters read from in are first encoded to the text encoding charset.

See also QTextCodec::codecForName().

### void QMailCodec::encode ( QDataStream & out, QDataStream & in ) `[virtual]`

Writes the data read from the stream in to the stream out, as a sequence of 7-bit ASCII characters.

### QByteArray QMailCodec::encode ( const QString & input, const QString & charset = "UTF-8" )

Returns a QByteArray containing the string input, encoded to the text encoding charset and then to a sequence of 7-bit ASCII characters.

See also QTextCodec::codecForName().

### QByteArray QMailCodec::encode ( const QByteArray & input )

Returns a QByteArray containing the octets from input, encoded to a sequence of 7-bit ASCII characters.

### void QMailCodec::encodeChunk ( QDataStream & out, const unsigned char * input, int length, bool finalChunk ) `[pure virtual protected]`

Overridden by derived classes to perform an encoding operation. The implementation function must encode length 8-bit octets at the location input, writing the resulting ASCII characters to the stream out. If finalChunk is false, further calls will be made to encodeChunk() with continued input data. Otherwise, the encoding operation is complete.

### QString QMailCodec::name () const `[pure virtual]`

Returns a string that identifies the subclass of QMailCodec that this instance belongs to.