KMIME Library
kmime_codec_base64.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00052 #ifndef __KMIME_CODEC_BASE64__
00053 #define __KMIME_CODEC_BASE64__
00054
00055 #include "kmime_codecs.h"
00056
00057 namespace KMime {
00058
00064 class KMIME_EXPORT Base64Codec : public Codec
00065 {
00066 protected:
00067 friend class Codec;
00071 Base64Codec() : Codec() {}
00072
00073 public:
00077 virtual ~Base64Codec() {}
00078
00083 const char *name() const
00084 { return "base64"; }
00085
00090 int maxEncodedSizeFor( int insize, bool withCRLF=false ) const
00091 {
00092
00093 int totalNumPackets = ( insize + 2 ) / 3;
00094
00095 int numLineBreaks = totalNumPackets / (76/4);
00096
00097 ++numLineBreaks;
00098
00099 return 4 * totalNumPackets + ( withCRLF ? 2 : 1 ) * numLineBreaks;
00100 }
00101
00106 int maxDecodedSizeFor( int insize, bool withCRLF=false ) const
00107 {
00108
00109
00110
00111
00112
00113 int result = ( ( insize + 3 ) / 4 ) * 3;
00114
00115 if ( withCRLF ) {
00116 result *= 2;
00117 }
00118
00119 return result;
00120 }
00121
00126 Encoder *makeEncoder( bool withCRLF=false ) const;
00127
00132 Decoder *makeDecoder( bool withCRLF=false ) const;
00133 };
00134
00140 class KMIME_EXPORT Rfc2047BEncodingCodec : public Base64Codec
00141 {
00142 protected:
00143 friend class Codec;
00147 Rfc2047BEncodingCodec() : Base64Codec() {}
00148
00149 public:
00153 virtual ~Rfc2047BEncodingCodec() {}
00154
00159 const char *name() const
00160 { return "b"; }
00161
00166 int maxEncodedSizeFor( int insize, bool withCRLF=false ) const
00167 {
00168 Q_UNUSED( withCRLF );
00169
00170 return ( ( insize + 2 ) / 3 ) * 4;
00171 }
00172
00177 int maxDecodedSizeFor( int insize, bool withCRLF=false ) const
00178 {
00179 Q_UNUSED( withCRLF );
00180
00181
00182 return ( ( insize + 3 ) / 4 ) * 3;
00183 }
00184
00189 Encoder *makeEncoder( bool withCRLF=false ) const;
00190 };
00191
00192 }
00193
00194 #endif // __KMIME_CODEC_BASE64__