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

KMIME Library

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

#include <kmime_codecs.h>

Inherited by KMime::Base64Decoder, KMime::IdentityEnDecoder, KMime::QuotedPrintableDecoder, and KMime::UUDecoder.

Public Member Functions

virtual ~Decoder ()
 
virtual bool decode (const char *&scursor, const char *const send, char *&dcursor, const char *const dend)=0
 
virtual bool finish (char *&dcursor, const char *const dend)=0
 

Protected Member Functions

 Decoder (bool withCRLF=false)
 

Detailed Description

Stateful CTE decoder class.

Stateful decoder class, modelled after QTextDecoder.

Overview

KMime decoders are designed to be able to process encoded data in chunks of arbitrary size and to work with output buffers of also arbitrary size. They maintain any state necessary to go on where the previous call left off.

The class consists of only two methods of interest: see decode, which decodes an input block and finalize, which flushes any remaining data to the output stream.

Typically, you will create a decoder instance, call decode as often as necessary, then call finalize (most often a single call suffices, but it might be that during that call the output buffer is filled, so you should be prepared to call finalize as often as necessary, ie. until it returns true).

Values

Both methods return true to indicate that they've finished their job. For decode, a return value of true means that the current input block has been finished (false most often means that the output buffer is full, but that isn't required behavior. The decode call is free to return at arbitrary times during processing).

For finalize, a return value of true means that all data implicitly or explicitly stored in the decoder instance has been flushed to the output buffer. A false return value should be interpreted as "check if the output buffer is full and call me again", just as with decode.

Pattern

Since the decoder maintains state, you can only use it once. After a sequence of input blocks has been processed, you finalize the output and then delete the decoder instance. If you want to process another input block sequence, you create a new instance.

Typical usage (in contains the (base64-encoded) input data), taking into account all the conventions detailed above:

KMime::Codec *codec = KMime::Codec::codecForName( "base64" );
kFatal( !codec ) << "No codec found for base64!";
KMime::Decoder *dec = codec->makeDecoder();
assert( dec ); // should not happen
QByteArray out( 256 ); // small buffer is enough ;-)
QByteArray::Iterator iit = in.begin();
QByteArray::Iterator oit = out.begin();
// decode the chunk
while ( !dec->decode( iit, in.end(), oit, out.end() ) )
  if ( oit == out.end() ) { // output buffer full, process contents
    do_something_with( out );
    oit = out.begin();
  }
// repeat while loop for each input block
// ...
// finish (flush remaining data from decoder):
while ( !dec->finish( oit, out.end() ) )
  if ( oit == out.end() ) { // output buffer full, process contents
    do_something_with( out );
    oit = out.begin();
  }
// now process last chunk:
out.resize( oit - out.begin() );
do_something_with( out );
// delete the decoder, but not the codec:
delete dec;

Definition at line 341 of file kmime_codecs.h.

Constructor & Destructor Documentation

KMime::Decoder::Decoder ( bool  withCRLF = false)
inlineprotected

Protected constructor.

Use KMime::Codec::makeDecoder to create an instance.

Parameters
withCRLFif true, make the newlines CRLF; else use LF.

Definition at line 351 of file kmime_codecs.h.

virtual KMime::Decoder::~Decoder ( )
inlinevirtual

Destroys the decoder.

Definition at line 358 of file kmime_codecs.h.

Member Function Documentation

virtual bool KMime::Decoder::decode ( const char *&  scursor,
const char *const  send,
char *&  dcursor,
const char *const  dend 
)
pure virtual

Decodes a chunk of data, maintaining state information between calls.

See class decumentation for calling conventions.

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.
virtual bool KMime::Decoder::finish ( char *&  dcursor,
const char *const  dend 
)
pure virtual

Call this method to finalize the output stream.

Writes all remaining data and resets the decoder. See KMime::Codec for calling conventions.

Parameters
dcursoris a pointer to the start of the output buffer.
dendis a pointer to the end of the output buffer.

The documentation for this class was generated from the following file:
  • kmime_codecs.h
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