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

KMIME Library

  • kmime
kmime_codec_base64.h
Go to the documentation of this file.
1/* -*- c++ -*-
2 kmime_codec_base64.h
3
4 KMime, the KDE Internet mail/usenet news message library.
5 Copyright (c) 2001-2002 Marc Mutz <mutz@kde.org>
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
21*/
52#ifndef __KMIME_CODEC_BASE64__
53#define __KMIME_CODEC_BASE64__
54
55#include "kmime_codecs.h"
56
57namespace KMime {
58
64class KMIME_EXPORT Base64Codec : public Codec
65{
66 protected:
67 friend class Codec;
71 Base64Codec() : Codec() {}
72
73 public:
77 virtual ~Base64Codec() {}
78
83 const char *name() const
84 { return "base64"; }
85
90 int maxEncodedSizeFor( int insize, bool withCRLF=false ) const
91 {
92 // first, the total number of 4-char packets will be:
93 int totalNumPackets = ( insize + 2 ) / 3;
94 // now, after every 76/4'th packet there needs to be a linebreak:
95 int numLineBreaks = totalNumPackets / ( 76 / 4 );
96 // and at the very end, too:
97 ++numLineBreaks;
98 // putting it all together, we have:
99 return 4 * totalNumPackets + ( withCRLF ? 2 : 1 ) * numLineBreaks;
100 }
101
106 int maxDecodedSizeFor( int insize, bool withCRLF=false ) const
107 {
108 // assuming all characters are part of the base64 stream (which
109 // does almost never hold due to required linebreaking; but
110 // additional non-base64 chars don't affect the output size), each
111 // 4-tupel of them becomes a 3-tupel in the decoded octet
112 // stream. So:
113 int result = ( ( insize + 3 ) / 4 ) * 3;
114 // but all of them may be \n, so
115 if ( withCRLF ) {
116 result *= 2; // :-o
117 }
118
119 return result;
120 }
121
126 Encoder *makeEncoder( bool withCRLF=false ) const;
127
132 Decoder *makeDecoder( bool withCRLF=false ) const;
133};
134
140class KMIME_EXPORT Rfc2047BEncodingCodec : public Base64Codec
141{
142 protected:
143 friend class Codec;
147 Rfc2047BEncodingCodec() : Base64Codec() {}
148
149 public:
153 virtual ~Rfc2047BEncodingCodec() {}
154
159 const char *name() const
160 { return "b"; }
161
166 int maxEncodedSizeFor( int insize, bool withCRLF=false ) const
167 {
168 Q_UNUSED( withCRLF );
169 // Each (begun) 3-octet triple becomes a 4 char quartet, so:
170 return ( ( insize + 2 ) / 3 ) * 4;
171 }
172
177 int maxDecodedSizeFor( int insize, bool withCRLF=false ) const
178 {
179 Q_UNUSED( withCRLF );
180 // Each 4-char quartet becomes a 3-octet triple, the last one
181 // possibly even less. So:
182 return ( ( insize + 3 ) / 4 ) * 3;
183 }
184
189 Encoder *makeEncoder( bool withCRLF=false ) const;
190};
191
192} // namespace KMime
193
194#endif // __KMIME_CODEC_BASE64__
KMime::Base64Codec
A class representing the codec for Base64 as specified in RFC2045.
Definition kmime_codec_base64.h:65
KMime::Base64Codec::Base64Codec
Base64Codec()
Constructs a Base64 codec.
Definition kmime_codec_base64.h:71
KMime::Base64Codec::maxDecodedSizeFor
int maxDecodedSizeFor(int insize, bool withCRLF=false) const
Definition kmime_codec_base64.h:106
KMime::Base64Codec::name
const char * name() const
Definition kmime_codec_base64.h:83
KMime::Base64Codec::~Base64Codec
virtual ~Base64Codec()
Destroys the codec.
Definition kmime_codec_base64.h:77
KMime::Base64Codec::maxEncodedSizeFor
int maxEncodedSizeFor(int insize, bool withCRLF=false) const
Definition kmime_codec_base64.h:90
KMime::Codec
An abstract base class of codecs for common mail transfer encodings.
Definition kmime_codecs.h:84
KMime::Decoder
Stateful CTE decoder class.
Definition kmime_codecs.h:342
KMime::Encoder
Stateful encoder class.
Definition kmime_codecs.h:395
KMime::Rfc2047BEncodingCodec
A class representing the codec for the B encoding as specified in RFC2047B.
Definition kmime_codec_base64.h:141
KMime::Rfc2047BEncodingCodec::maxEncodedSizeFor
int maxEncodedSizeFor(int insize, bool withCRLF=false) const
Definition kmime_codec_base64.h:166
KMime::Rfc2047BEncodingCodec::name
const char * name() const
Definition kmime_codec_base64.h:159
KMime::Rfc2047BEncodingCodec::~Rfc2047BEncodingCodec
virtual ~Rfc2047BEncodingCodec()
Destroys the codec.
Definition kmime_codec_base64.h:153
KMime::Rfc2047BEncodingCodec::Rfc2047BEncodingCodec
Rfc2047BEncodingCodec()
Constructs a RFC2047B codec.
Definition kmime_codec_base64.h:147
KMime::Rfc2047BEncodingCodec::maxDecodedSizeFor
int maxDecodedSizeFor(int insize, bool withCRLF=false) const
Definition kmime_codec_base64.h:177
kmime_codecs.h
This file is part of the API for handling MIME data and defines the Codec class.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Jan 24 2024 00:00:00 by doxygen 1.10.0 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-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 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
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