• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

KMIME Library

  • KMime
  • Codec
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
KMime::Codec Class Referenceabstract

#include <kmime_codecs.h>

Inheritance diagram for KMime::Codec:
Inheritance graph
[legend]

Public Member Functions

virtual ~Codec ()
 
virtual bool decode (const char *&scursor, const char *const send, char *&dcursor, const char *const dend, bool withCRLF=false) const
 
virtual QByteArray decode (const QByteArray &src, bool withCRLF=false) const
 
virtual bool encode (const char *&scursor, const char *const send, char *&dcursor, const char *const dend, bool withCRLF=false) const
 
virtual QByteArray encode (const QByteArray &src, bool withCRLF=false) const
 
virtual Decoder * makeDecoder (bool withCRLF=false) const =0
 
virtual Encoder * makeEncoder (bool withCRLF=false) const =0
 
virtual int maxDecodedSizeFor (int insize, bool withCRLF=false) const =0
 
virtual int maxEncodedSizeFor (int insize, bool withCRLF=false) const =0
 
virtual const char * name () const =0
 

Static Public Member Functions

static Codec * codecForName (const char *name)
 
static Codec * codecForName (const QByteArray &name)
 

Protected Member Functions

 Codec ()
 

Detailed Description

An abstract base class of codecs for common mail transfer encodings.

Provides an abstract base class of codecs like base64 and quoted-printable. Implemented as a singleton.

Definition at line 83 of file kmime_codecs.h.

Constructor & Destructor Documentation

KMime::Codec::Codec ( )
inlineprotected

Contructs the codec.

Definition at line 93 of file kmime_codecs.h.

virtual KMime::Codec::~Codec ( )
inlinevirtual

Destroys the codec.

Definition at line 256 of file kmime_codecs.h.

Member Function Documentation

Codec * KMime::Codec::codecForName ( const char *  name)
static

Returns a codec associated with the specified name.

Parameters
namepoints to a character string containing a valid codec name.

Definition at line 82 of file kmime_codecs.cpp.

Codec * KMime::Codec::codecForName ( const QByteArray &  name)
static

Returns a codec associated with the specified name.

Parameters
nameis a QByteArray containing a valid codec name.

Definition at line 88 of file kmime_codecs.cpp.

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" );
kFatal( !codec ) << "no base64 codec found!?";
QByteArray out( in.size() ); // good guess for any encoding...
QByteArray::Iterator iit = in.begin();
QByteArray::Iterator oit = out.begin();
if ( !codec->decode( iit, in.end(), oit, out.end() ) ) {
  kDebug() << "output buffer too small";
  return;
}
kDebug() << "Size of decoded data:" << oit - out.begin();
Parameters
scursoris a pointer to the start of the input buffer.
sendis a pointer to the end of the input buffer.
dcursoris a pointer to the start of the output buffer.
dendis a pointer to the end of the output buffer.
withCRLFif true, make the newlines CRLF; else use LF.
Returns
false if the decoded data didn't fit into the output buffer; true otherwise.

Definition at line 183 of file kmime_codecs.cpp.

QByteArray KMime::Codec::decode ( const QByteArray &  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 QByteArray to the actual size again.

For use with small src.

Parameters
srcis a QByteArray containing the data to decode.
withCRLFif true, make the newlines CRLF; else use LF.

Reimplemented in KMime::IdentityCodec.

Definition at line 160 of file kmime_codecs.cpp.

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" );
kFatal( !codec ) << "no base64 codec found!?";
QByteArray out( in.size()*1.4 ); // crude maximal size of b64 encoding
QByteArray::Iterator iit = in.begin();
QByteArray::Iterator oit = out.begin();
if ( !codec->encode( iit, in.end(), oit, out.end() ) ) {
  kDebug() << "output buffer too small";
  return;
}
kDebug() << "Size of encoded data:" << oit - out.begin();
Parameters
scursoris a pointer to the start of the input buffer.
sendis a pointer to the end of the input buffer.
dcursoris a pointer to the start of the output buffer.
dendis a pointer to the end of the output buffer.
withCRLFif true, make the newlines CRLF; else use LF.
Returns
false if the encoded data didn't fit into the output buffer; true otherwise.

Definition at line 108 of file kmime_codecs.cpp.

QByteArray KMime::Codec::encode ( const QByteArray &  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 QByteArray to the actual size again.

For use with small src.

Parameters
srcis a QByteArray containing the data to encode.
withCRLFif true, make the newlines CRLF; else use LF.

Reimplemented in KMime::IdentityCodec.

Definition at line 137 of file kmime_codecs.cpp.

virtual Decoder* KMime::Codec::makeDecoder ( bool  withCRLF = false) const
pure virtual

Creates the decoder for the codec.

Parameters
withCRLFif true, make the newlines CRLF; else use LF.
Returns
a pointer to an instance of the codec's decoder.

Implemented in KMime::Rfc2231EncodingCodec, KMime::Rfc2047QEncodingCodec, KMime::Base64Codec, KMime::IdentityCodec, KMime::QuotedPrintableCodec, and KMime::UUCodec.

virtual Encoder* KMime::Codec::makeEncoder ( bool  withCRLF = false) const
pure virtual

Creates the encoder for the codec.

Parameters
withCRLFif true, make the newlines CRLF; else use LF.
Returns
a pointer to an instance of the codec's encoder.

Implemented in KMime::Rfc2231EncodingCodec, KMime::Rfc2047BEncodingCodec, KMime::Rfc2047QEncodingCodec, KMime::Base64Codec, KMime::IdentityCodec, KMime::QuotedPrintableCodec, and KMime::UUCodec.

virtual int KMime::Codec::maxDecodedSizeFor ( int  insize,
bool  withCRLF = false 
) const
pure virtual

Computes the maximum size, in characters, needed for the deccoding.

Parameters
insizeis the number of input characters to be decoded.
withCRLFif true, make the newlines CRLF; else use LF.
Returns
the maximum number of characters in the decoding.

Implemented in KMime::Rfc2231EncodingCodec, KMime::BinaryCodec, KMime::Rfc2047BEncodingCodec, KMime::Rfc2047QEncodingCodec, KMime::Base64Codec, KMime::QuotedPrintableCodec, KMime::IdentityCodec, and KMime::UUCodec.

virtual int KMime::Codec::maxEncodedSizeFor ( int  insize,
bool  withCRLF = false 
) const
pure virtual

Computes the maximum size, in characters, needed for the encoding.

Parameters
insizeis the number of input characters to be encoded.
withCRLFif true, make the newlines CRLF; else use LF.
Returns
the maximum number of characters in the encoding.

Implemented in KMime::BinaryCodec, KMime::Rfc2231EncodingCodec, KMime::Rfc2047BEncodingCodec, KMime::Rfc2047QEncodingCodec, KMime::Base64Codec, KMime::QuotedPrintableCodec, KMime::IdentityCodec, and KMime::UUCodec.

virtual const char* KMime::Codec::name ( ) const
pure virtual

Returns the name of the encoding.

Guaranteed to be lowercase.

Implemented in KMime::BinaryCodec, KMime::Rfc2231EncodingCodec, KMime::EightBitCodec, KMime::Rfc2047BEncodingCodec, KMime::SevenBitCodec, KMime::Rfc2047QEncodingCodec, KMime::Base64Codec, KMime::QuotedPrintableCodec, and KMime::UUCodec.


The documentation for this class was generated from the following files:
  • kmime_codecs.h
  • kmime_codecs.cpp
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:37:18 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KMIME Library

Skip menu "KMIME Library"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal