libkmime

#include <kmime_codecs.h>

Inherited by KMime::Base64Codec, KMime::IdentityCodec, KMime::QuotedPrintableCodec, KMime::Rfc2047TQEncodingCodec, KMime::Rfc2231EncodingCodec, and KMime::UUCodec.

Public Member Functions

virtual int maxEncodedSizeFor (int insize, bool withCRLF=false) const =0
 
virtual int maxDecodedSizeFor (int insize, bool withCRLF=false) const =0
 
virtual EncodermakeEncoder (bool withCRLF=false) const =0
 
virtual DecodermakeDecoder (bool withCRLF=false) const =0
 
virtual bool encode (const char *&scursor, const char *const send, char *&dcursor, const char *const dend, bool withCRLF=false) const
 
virtual bool decode (const char *&scursor, const char *const send, char *&dcursor, const char *const dend, bool withCRLF=false) const
 
virtual TQByteArray encode (const TQByteArray &src, bool withCRLF=false) const
 
virtual TQCString encodeToTQCString (const TQByteArray &src, bool withCRLF=false) const
 
virtual TQByteArray decode (const TQByteArray &src, bool withCRLF=false) const
 
virtual const char * name () const =0
 

Static Public Member Functions

static CodeccodecForName (const char *name)
 
static CodeccodecForName (const TQCString &name)
 

Static Protected Attributes

static TQAsciiDict< Codec > * all = 0
 

Detailed Description

Abstract base class of codecs like base64 and quoted-printable.

It's a singleton.

Codecs for common mail transfer encodings.

Author
Marc Mutz mutz@.nosp@m.kde..nosp@m.org

Definition at line 57 of file kmime_codecs.h.

Member Function Documentation

◆ decode() [1/2]

bool KMime::Codec::decode ( const char *&  scursor,
const char *const  send,
char *&  dcursor,
const char *const  dend,
bool  withCRLF = false 
) const
virtual

Convenience wrapper that can be used for small chunks of data when you can provide a large enough buffer.

The default implementation creates a Decoder and uses it.

Decodes a chunk of bytes starting at scursor and extending to send into the buffer described by dcursor and dend.

This function doesn't support chaining of blocks. The returned block cannot be added to, but you don't need to finalize it, too.

Example usage (in contains the input data):

KMime::Codec * codec = KMime::Codec::codecForName( "base64" );
kdFatal( !codec ) << "no base64 codec found!?" << endl;
TQByteArray out( in.size() ); // good guess for any encoding...
TQByteArray::Iterator iit = in.begin();
TQByteArray::Iterator oit = out.begin();
if ( !codec->decode( iit, in.end(), oit, out.end() ) ) {
  kdDebug() << "output buffer too small" << endl;
  return;
}
kdDebug() << "Size of decoded data: " << oit - out.begin() << endl;
Parameters
scursor/sendbegin and end of input buffer
dcursor/dendbegin and end of output buffer
withCRLFIf true, make the lineends CRLF, else make them LF only.
Returns
false if the decoded data didn't fit into the output buffer.

Definition at line 194 of file kmime_codecs.cpp.

◆ decode() [2/2]

TQByteArray KMime::Codec::decode ( const TQByteArray &  src,
bool  withCRLF = false 
) const
virtual

Even more convenient, but also a bit slower and more memory intensive, since it allocates storage for the worst case and then shrinks the result TQByteArray to the actual size again.

For use with small src.

Definition at line 172 of file kmime_codecs.cpp.

◆ encode() [1/2]

bool KMime::Codec::encode ( const char *&  scursor,
const char *const  send,
char *&  dcursor,
const char *const  dend,
bool  withCRLF = false 
) const
virtual

Convenience wrapper that can be used for small chunks of data when you can provide a large enough buffer.

The default implementation creates an Encoder and uses it.

Encodes a chunk of bytes starting at scursor and extending to send into the buffer described by dcursor and dend.

This function doesn't support chaining of blocks. The returned block cannot be added to, but you don't need to finalize it, too.

Example usage (in contains the input data):

KMime::Codec * codec = KMime::Codec::codecForName( "base64" );
kdFatal( !codec ) << "no base64 codec found!?" << endl;
TQByteArray out( in.size()*1.4 ); // crude maximal size of b64 encoding
TQByteArray::Iterator iit = in.begin();
TQByteArray::Iterator oit = out.begin();
if ( !codec->encode( iit, in.end(), oit, out.end() ) ) {
  kdDebug() << "output buffer too small" << endl;
  return;
}
kdDebug() << "Size of encoded data: " << oit - out.begin() << endl;
Parameters
scursor/sendbegin and end of input buffer
dcursor/dendbegin and end of output buffer
withCRLFIf true, make the lineends CRLF, else make them LF only.
Returns
false if the encoded data didn't fit into the output buffer.

Definition at line 101 of file kmime_codecs.cpp.

◆ encode() [2/2]

TQByteArray KMime::Codec::encode ( const TQByteArray &  src,
bool  withCRLF = false 
) const
virtual

Even more convenient, but also a bit slower and more memory intensive, since it allocates storage for the worst case and then shrinks the result TQByteArray to the actual size again.

For use with small src.

Definition at line 128 of file kmime_codecs.cpp.

◆ encodeToTQCString()

TQCString KMime::Codec::encodeToTQCString ( const TQByteArray &  src,
bool  withCRLF = false 
) const
virtual

Even more convenient, but also a bit slower and more memory intensive, since it allocates storage for the worst case and then shrinks the result TQCString to the actual size again.

For use with small src.

This method only works for codecs whose output is in the 8bit domain (ie. not in the binary domain). Codecs that do not fall into this category will return a null TQCString.

Definition at line 150 of file kmime_codecs.cpp.

◆ name()

virtual const char* KMime::Codec::name ( ) const
pure virtual
Returns
the name of the encoding. Guaranteed to be lowercase.

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