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