KCodecs

kcodecsqp.h
Go to the documentation of this file.
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
35namespace 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*/
43{
44public:
45 /**
46 Constructs a QuotedPrintable codec.
47 */
49 : Codec()
50 {
51 }
52
53 /**
54 Destroys the codec.
55 */
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*/
108{
109public:
110 /**
111 Constructs a RFC2047Q codec.
112 */
114 : Codec()
115 {
116 }
117
118 /**
119 Destroys the codec.
120 */
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*/
170{
171public:
172 /**
173 Constructs a RFC2231 codec.
174 */
176 : Codec()
177 {
178 }
179
180 /**
181 Destroys the codec.
182 */
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
An abstract base class of codecs for common mail transfer encodings.
Definition kcodecs.h:324
Stateful CTE decoder class.
Definition kcodecs.h:580
Stateful encoder class.
Definition kcodecs.h:636
A class representing the codec for QuotedPrintable as specified in RFC2045 (section 6....
Definition kcodecsqp.h:43
qsizetype maxDecodedSizeFor(qsizetype insize, NewlineType newline=Codec::NewlineLF) const override
qsizetype maxEncodedSizeFor(qsizetype insize, NewlineType newline=Codec::NewlineLF) const override
Definition kcodecsqp.h:73
Encoder * makeEncoder(NewlineType newline=Codec::NewlineLF) const override
QuotedPrintableCodec()
Constructs a QuotedPrintable codec.
Definition kcodecsqp.h:48
const char * name() const override
Definition kcodecsqp.h:64
~QuotedPrintableCodec() override
Destroys the codec.
Definition kcodecsqp.h:56
Decoder * makeDecoder(NewlineType newline=Codec::NewlineLF) const override
A class representing the codec for the Q encoding as specified in RFC2047Q.
Definition kcodecsqp.h:108
qsizetype maxEncodedSizeFor(qsizetype insize, Codec::NewlineType newline=Codec::NewlineLF) const override
Definition kcodecsqp.h:138
Encoder * makeEncoder(Codec::NewlineType newline=Codec::NewlineLF) const override
Rfc2047QEncodingCodec()
Constructs a RFC2047Q codec.
Definition kcodecsqp.h:113
const char * name() const override
Definition kcodecsqp.h:129
qsizetype maxDecodedSizeFor(qsizetype insize, Codec::NewlineType newline=Codec::NewlineLF) const override
Decoder * makeDecoder(Codec::NewlineType newline=Codec::NewlineLF) const override
~Rfc2047QEncodingCodec() override
Destroys the codec.
Definition kcodecsqp.h:121
A class representing the codec for RFC2231.
Definition kcodecsqp.h:170
qsizetype maxDecodedSizeFor(qsizetype insize, Codec::NewlineType newline=Codec::NewlineLF) const override
Decoder * makeDecoder(Codec::NewlineType newline=Codec::NewlineLF) const override
Rfc2231EncodingCodec()
Constructs a RFC2231 codec.
Definition kcodecsqp.h:175
Encoder * makeEncoder(Codec::NewlineType newline=Codec::NewlineLF) const override
qsizetype maxEncodedSizeFor(qsizetype insize, Codec::NewlineType newline=Codec::NewlineLF) const override
Definition kcodecsqp.h:200
const char * name() const override
Definition kcodecsqp.h:191
~Rfc2231EncodingCodec() override
Destroys the codec.
Definition kcodecsqp.h:183
A wrapper class for the most commonly used encoding and decoding algorithms.
Definition kcodecs.cpp:41
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:47:24 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.