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.
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]
This is an overloaded member function, provided for convenience.
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]
This is an overloaded member function, provided for convenience.
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 )
This is an overloaded member function, provided for convenience.
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().
This is an overloaded member function, provided for convenience.
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]
This is an overloaded member function, provided for convenience.
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" )
This is an overloaded member function, provided for convenience.
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().
This is an overloaded member function, provided for convenience.
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.