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

KMIME Library

  • sources
  • kde-4.12
  • kdepimlibs
  • kmime
kmime_codecs.h
Go to the documentation of this file.
1 /* -*- c++ -*-
2 
3  KMime, the KDE Internet mail/usenet news message library.
4  Copyright (c) 2001-2002 Marc Mutz <mutz@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
60 #ifndef __KMIME_CODECS__
61 #define __KMIME_CODECS__
62 
63 #include <QtCore/QByteArray>
64 
65 #include <kdebug.h> // for kFatal()
66 
67 #include "kmime_export.h"
68 
69 namespace KMime {
70 
71 template <class Key, class T> class KAutoDeleteHash;
72 
73 class Encoder;
74 class Decoder;
75 
83 class KMIME_EXPORT Codec
84 {
85  protected:
86  //@cond PRIVATE
87  static KAutoDeleteHash<QByteArray, Codec> *all;
88  static void cleanupCodec();
89  //@endcond
93  Codec() {}
94 
95  public:
101  static Codec *codecForName( const char *name );
102 
108  static Codec *codecForName( const QByteArray &name );
109 
118  virtual int maxEncodedSizeFor( int insize, bool withCRLF=false ) const = 0;
119 
128  virtual int maxDecodedSizeFor( int insize, bool withCRLF=false ) const = 0;
129 
137  virtual Encoder *makeEncoder( bool withCRLF=false ) const = 0;
138 
146  virtual Decoder *makeDecoder( bool withCRLF=false ) const = 0;
147 
182  virtual bool encode( const char* &scursor, const char * const send,
183  char* &dcursor, const char * const dend,
184  bool withCRLF=false ) const;
185 
220  virtual bool decode( const char* &scursor, const char * const send,
221  char* &dcursor, const char * const dend,
222  bool withCRLF=false ) const;
223 
234  virtual QByteArray encode( const QByteArray &src, bool withCRLF=false ) const;
235 
246  virtual QByteArray decode( const QByteArray &src, bool withCRLF=false ) const;
247 
251  virtual const char *name() const = 0;
252 
256  virtual ~Codec() {}
257 
258  private:
262  static void fillDictionary();
263 };
264 
341 class Decoder
342 {
343  protected:
344  friend class Codec;
351  Decoder( bool withCRLF=false )
352  : mWithCRLF( withCRLF ) {}
353 
354  public:
358  virtual ~Decoder() {}
359 
369  virtual bool decode( const char* &scursor, const char * const send,
370  char* &dcursor, const char * const dend ) = 0;
371 
380  virtual bool finish( char* &dcursor, const char * const dend ) = 0;
381 
382  protected:
383  //@cond PRIVATE
384  const bool mWithCRLF;
385  //@endcond
386 };
387 
394 class Encoder
395 {
396  protected:
397  friend class Codec;
403  explicit Encoder( bool withCRLF=false )
404  : mOutputBufferCursor( 0 ), mWithCRLF( withCRLF ) {}
405 
406  public:
410  virtual ~Encoder() {}
411 
421  virtual bool encode( const char* &scursor, const char * const send,
422  char* &dcursor, const char * const dend ) = 0;
423 
431  virtual bool finish( char* &dcursor, const char * const dend ) = 0;
432 
433  protected:
437  enum {
438  maxBufferedChars = 8
439  };
440 
451  bool write( char ch, char* &dcursor, const char * const dend )
452  {
453  if ( dcursor != dend ) {
454  // if there's space in the output stream, write there:
455  *dcursor++ = ch;
456  return true;
457  } else {
458  // else buffer the output:
459  kFatal( mOutputBufferCursor >= maxBufferedChars )
460  << "KMime::Encoder: internal buffer overflow!";
461  mOutputBuffer[ mOutputBufferCursor++ ] = ch;
462  return false;
463  }
464  }
465 
476  bool flushOutputBuffer( char* &dcursor, const char * const dend );
477 
485  bool writeCRLF( char* &dcursor, const char * const dend )
486  {
487  if ( mWithCRLF ) {
488  write( '\r', dcursor, dend );
489  }
490  return write( '\n', dcursor, dend );
491  }
492 
493  private:
498  //@cond PRIVATE
499  char mOutputBuffer[ maxBufferedChars ];
500  //@endcond
501 
502  protected:
503  //@cond PRIVATE
504  uchar mOutputBufferCursor;
505  const bool mWithCRLF;
506  //@endcond
507 };
508 
509 } // namespace KMime
510 
511 #endif // __KMIME_CODECS__
KMime::Decoder::finish
virtual bool finish(char *&dcursor, const char *const dend)=0
Call this method to finalize the output stream.
KMime::Encoder::writeCRLF
bool writeCRLF(char *&dcursor, const char *const dend)
Convenience function.
Definition: kmime_codecs.h:485
KMime::Encoder
Stateful encoder class.
Definition: kmime_codecs.h:394
KMime::Encoder::Encoder
Encoder(bool withCRLF=false)
Protected constructor.
Definition: kmime_codecs.h:403
KMime::Codec::Codec
Codec()
Contructs the codec.
Definition: kmime_codecs.h:93
KMime::Codec
An abstract base class of codecs for common mail transfer encodings.
Definition: kmime_codecs.h:83
KMime::Decoder
Stateful CTE decoder class.
Definition: kmime_codecs.h:341
KMime::Codec::~Codec
virtual ~Codec()
Destroys the codec.
Definition: kmime_codecs.h:256
KMime::Encoder::write
bool write(char ch, char *&dcursor, const char *const dend)
Writes character ch to the output stream or the output buffer, depending on whether or not the output...
Definition: kmime_codecs.h:451
KMime::Encoder::finish
virtual bool finish(char *&dcursor, const char *const dend)=0
Call this method to finalize the output stream.
KMime::Decoder::decode
virtual bool decode(const char *&scursor, const char *const send, char *&dcursor, const char *const dend)=0
Decodes a chunk of data, maintaining state information between calls.
KMime::Encoder::encode
virtual bool encode(const char *&scursor, const char *const send, char *&dcursor, const char *const dend)=0
Encodes a chunk of data, maintaining state information between calls.
KMime::Decoder::Decoder
Decoder(bool withCRLF=false)
Protected constructor.
Definition: kmime_codecs.h:351
KMime::Decoder::~Decoder
virtual ~Decoder()
Destroys the decoder.
Definition: kmime_codecs.h:358
KMime::Encoder::flushOutputBuffer
bool flushOutputBuffer(char *&dcursor, const char *const dend)
Writes characters from the output buffer to the output stream.
Definition: kmime_codecs.cpp:214
KMime::KAutoDeleteHash
The KAutoDeleteHash class is a convenience QHash subclass that provides automatic deletion of the val...
Definition: kautodeletehash.h:49
KMime::Encoder::~Encoder
virtual ~Encoder()
Destroys the encoder.
Definition: kmime_codecs.h:410
KMime::Encoder::maxBufferedChars
Eight.
Definition: kmime_codecs.h:438
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:11 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
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

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