1/* -*- c++ -*-
2 kmime_codec_identity.h
3
4 KMime, the KDE Internet mail/usenet news message library.
5 Copyright (c) 2004 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*/
22/**
23 @file
24 This file is part of the API for handling @ref MIME data and
25 defines the Identity, @ref seven-bit-text, @ref eight-bit-text,
26 and @ref eight-bit-binary @ref Codec classes.
27
28 @brief
29 Defines the classes IdentityCodec, SevenBitCodec, EightBitCodec,
30 and BinaryCodec.
31
32 @authors Marc Mutz \<mutz@kde.org\>
33*/
34
35#ifndef __KMIME_CODEC_IDENTITY_H__
36#define __KMIME_CODEC_IDENTITY_H__
37
38#include "kmime_codecs.h"
39
40class QByteArray;
41
42namespace KMime {
43
44/**
45 @brief
46 A class representing the Identify @ref codec.
47*/
48class KMIME_EXPORT IdentityCodec : public Codec
49{
50 protected:
51 friend class Codec;
52 /**
53 Constructs the Identity codec.
54 */
55 IdentityCodec() : Codec() {}
56
57 public:
58 /**
59 Destroys the codec.
60 */
61 ~IdentityCodec() {}
62
63 using Codec::encode;
64 using Codec::decode;
65
66 /**
67 @copydoc
68 QByteArray Codec::encode()
69 */
70 QByteArray encode( const QByteArray &src, bool withCRLF=false ) const;
71
72 /**
73 @copydoc
74 QByteArray Codec::decode()
75 */
76 QByteArray decode( const QByteArray &src, bool withCRLF=false ) const;
77
78 /**
79 @copydoc
80 Codec::maxEncodedSizeFor()
81 */
82 int maxEncodedSizeFor( int insize, bool withCRLF ) const
83 {
84 if ( withCRLF ) {
85 return 2 * insize;
86 } else {
87 return insize;
88 }
89 }
90
91 /**
92 @copydoc
93 Codec::maxDecodedSizeFor()
94 */
95 int maxDecodedSizeFor( int insize, bool withCRLF ) const
96 {
97 if ( withCRLF ) {
98 return 2 * insize;
99 } else {
100 return insize;
101 }
102 }
103
104 /**
105 @copydoc
106 Codec::makeEncoder()
107 */
108 Encoder *makeEncoder( bool withCRLF=false ) const;
109
110 /**
111 @copydoc
112 Codec::makeDecoder()
113 */
114 Decoder *makeDecoder( bool withCRLF=false ) const;
115};
116
117/**
118 @brief
119 A class representing the @ref codec for @ref seven-bit-text.
120*/
121class KMIME_EXPORT SevenBitCodec : public IdentityCodec
122{
123 protected:
124 friend class Codec;
125 /**
126 Constructs the 7-bit codec.
127 */
128 SevenBitCodec() : IdentityCodec() {}
129
130 public:
131 /**
132 Destroys the codec.
133 */
134 ~SevenBitCodec() {}
135
136 /**
137 @copydoc
138 Codec::name()
139 */
140 const char *name() const
141 { return "7bit"; }
142};
143
144/**
145 @brief
146 A class representing the @ref codec for @ref eight-bit-text.
147*/
148class KMIME_EXPORT EightBitCodec : public IdentityCodec
149{
150 protected:
151 friend class Codec;
152 /**
153 Constructs the 8-bit codec.
154 */
155 EightBitCodec() : IdentityCodec() {}
156
157 public:
158 /**
159 Destroys the codec.
160 */
161 ~EightBitCodec() {}
162
163 /**
164 @copydoc
165 Codec::name()
166 */
167 const char *name() const
168 { return "8bit"; }
169};
170
171/**
172 @brief
173 A class representing the @ref codec for @ref eight-bit-binary.
174*/
175class KMIME_EXPORT BinaryCodec : public IdentityCodec
176{
177 protected:
178 friend class Codec;
179 /**
180 Constructs the 8-bit-binary codec.
181 */
182 BinaryCodec() : IdentityCodec() {}
183
184 public:
185 /**
186 Destroys the codec.
187 */
188 ~BinaryCodec() {}
189
190 /**
191 @copydoc
192 Codec::name()
193 */
194 const char *name() const
195 { return "binary"; }
196
197 /**
198 @copydoc
199 Codec::maxEncodedSizeFor()
200 */
201 int maxEncodedSizeFor( int insize, bool withCRLF=false ) const
202 { Q_UNUSED( withCRLF ); return insize; }
203
204 /**
205 @copydoc
206 Codec::maxDecodedSizeFor()
207 */
208 int maxDecodedSizeFor( int insize, bool withCRLF=false ) const
209 { Q_UNUSED( withCRLF ); return insize; }
210};
211
212} // namespace KMime
213
214#endif // __KMIME_CODEC_IDENTITY_H__
215