1 | /* -*- c++ -*- |
2 | kmime_codec_qp.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 | */ |
22 | /** |
23 | @file |
24 | This file is part of the API for handling @ref MIME data and |
25 | defines the @ref QuotedPrintable, @ref RFC2047Q, and |
26 | @ref RFC2231 @ref Codec classes. |
27 | |
28 | @brief |
29 | Defines the classes QuotedPrintableCodec, Rfc2047QEncodingCodec, and |
30 | Rfc2231EncodingCodec. |
31 | |
32 | @authors Marc Mutz \<mutz@kde.org\> |
33 | |
34 | @glossary @anchor QuotedPrintable @anchor quotedprintable @b quoted-printable: |
35 | a binary to text encoding scheme based on Section 6.7 of @ref RFC2045. |
36 | |
37 | @glossary @anchor RFC2047Q @anchor rfc2047q @b RFC @b 2047Q: |
38 | Section 4.2 of @ref RFC2047. |
39 | |
40 | @glossary @anchor RFC2231 @anchor rfc2231 @b RFC @b 2231: |
41 | RFC that defines the <a href="http://tools.ietf.org/html/rfc2231"> |
42 | MIME Parameter Value and Encoded Word Extensions: Character Sets, Languages, |
43 | and Continuations</a>. |
44 | */ |
45 | |
46 | #ifndef __KMIME_CODEC_QP__ |
47 | #define __KMIME_CODEC_QP__ |
48 | |
49 | #include "kmime_codecs.h" |
50 | |
51 | namespace KMime { |
52 | |
53 | /** |
54 | @brief |
55 | A class representing the @ref codec for @ref QuotedPrintable as specified in |
56 | @ref RFC2045 (section 6.7). |
57 | */ |
58 | class KMIME_EXPORT QuotedPrintableCodec : public Codec |
59 | { |
60 | protected: |
61 | friend class Codec; |
62 | /** |
63 | Constructs a QuotedPrintable codec. |
64 | */ |
65 | QuotedPrintableCodec() : Codec() {} |
66 | |
67 | public: |
68 | /** |
69 | Destroys the codec. |
70 | */ |
71 | virtual ~QuotedPrintableCodec() {} |
72 | |
73 | /** |
74 | @copydoc |
75 | Codec::name() |
76 | */ |
77 | const char *name() const |
78 | { return "quoted-printable" ; } |
79 | |
80 | /** |
81 | @copydoc |
82 | Codec::maxEncodedSizeFor() |
83 | */ |
84 | int maxEncodedSizeFor( int insize, bool withCRLF=false ) const |
85 | { // all chars encoded: |
86 | int result = 3*insize; |
87 | // then after 25 hexchars comes a soft linebreak: =(\r)\n |
88 | result += ( withCRLF ? 3 : 2 ) * ( insize / 25 ); |
89 | |
90 | return result; |
91 | } |
92 | |
93 | /** |
94 | @copydoc |
95 | Codec::maxDecodedSizeFor() |
96 | */ |
97 | int maxDecodedSizeFor( int insize, bool withCRLF=false ) const; |
98 | |
99 | /** |
100 | @copydoc |
101 | Codec::makeEncoder() |
102 | */ |
103 | Encoder *makeEncoder( bool withCRLF=false ) const; |
104 | |
105 | /** |
106 | @copydoc |
107 | Codec::makeDecoder() |
108 | */ |
109 | Decoder *makeDecoder( bool withCRLF=false ) const; |
110 | }; |
111 | |
112 | /** |
113 | @brief |
114 | A class representing the @ref codec for the Q encoding as specified |
115 | in @ref RFC2047Q. |
116 | */ |
117 | class KMIME_EXPORT Rfc2047QEncodingCodec : public Codec |
118 | { |
119 | protected: |
120 | friend class Codec; |
121 | /** |
122 | Constructs a RFC2047Q codec. |
123 | */ |
124 | Rfc2047QEncodingCodec() : Codec() {} |
125 | |
126 | public: |
127 | /** |
128 | Destroys the codec. |
129 | */ |
130 | virtual ~Rfc2047QEncodingCodec() {} |
131 | |
132 | /** |
133 | @copydoc |
134 | Codec::name() |
135 | */ |
136 | const char *name() const |
137 | { return "q" ; } |
138 | |
139 | /** |
140 | @copydoc |
141 | Codec::maxEncodedSizeFor() |
142 | */ |
143 | int maxEncodedSizeFor( int insize, bool withCRLF=false ) const |
144 | { |
145 | Q_UNUSED( withCRLF ); |
146 | // this one is simple: We don't do linebreaking, so all that can |
147 | // happen is that every char needs encoding, so: |
148 | return 3 * insize; |
149 | } |
150 | |
151 | /** |
152 | @copydoc |
153 | Codec::maxDecodedSizeFor() |
154 | */ |
155 | int maxDecodedSizeFor( int insize, bool withCRLF=false ) const; |
156 | |
157 | /** |
158 | @copydoc |
159 | Codec::makeEncoder() |
160 | */ |
161 | Encoder *makeEncoder( bool withCRLF=false ) const; |
162 | |
163 | /** |
164 | @copydoc |
165 | Codec::makeDecoder() |
166 | */ |
167 | Decoder *makeDecoder( bool withCRLF=false ) const; |
168 | }; |
169 | |
170 | /** |
171 | @brief |
172 | A class representing the @ref codec for @ref RFC2231. |
173 | */ |
174 | class KMIME_EXPORT Rfc2231EncodingCodec : public Codec |
175 | { |
176 | protected: |
177 | friend class Codec; |
178 | /** |
179 | Constructs a RFC2231 codec. |
180 | */ |
181 | Rfc2231EncodingCodec() : Codec() {} |
182 | |
183 | public: |
184 | /** |
185 | Destroys the codec. |
186 | */ |
187 | virtual ~Rfc2231EncodingCodec() {} |
188 | |
189 | /** |
190 | @copydoc |
191 | Codec::name() |
192 | */ |
193 | const char *name() const |
194 | { return "x-kmime-rfc2231" ; } |
195 | |
196 | /** |
197 | @copydoc |
198 | Codec::maxEncodedSizeFor() |
199 | */ |
200 | int maxEncodedSizeFor( int insize, bool withCRLF=false ) const |
201 | { |
202 | Q_UNUSED( withCRLF ); |
203 | // same as for "q" encoding: |
204 | return 3 * insize; |
205 | } |
206 | |
207 | /** |
208 | @copydoc |
209 | Codec::maxDecodedSizeFor() |
210 | */ |
211 | int maxDecodedSizeFor( int insize, bool withCRLF=false ) const; |
212 | |
213 | /** |
214 | @copydoc |
215 | Codec::makeEncoder() |
216 | */ |
217 | Encoder *makeEncoder( bool withCRLF=false ) const; |
218 | |
219 | /** |
220 | @copydoc |
221 | Codec::makeDecoder() |
222 | */ |
223 | Decoder *makeDecoder( bool withCRLF=false ) const; |
224 | }; |
225 | |
226 | } // namespace KMime |
227 | |
228 | #endif // __KMIME_CODEC_QP__ |
229 | |