/src/kcodecs/src/kcodecsqp.h
Line | Count | Source |
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 | | #ifndef KCODECS_QP_H |
8 | | #define KCODECS_QP_H |
9 | | |
10 | | #include "kcodecs.h" |
11 | | |
12 | | namespace KCodecs |
13 | | { |
14 | | /* |
15 | | A class representing the codec for QuotedPrintable as specified in |
16 | | RFC2045 (section 6.7). |
17 | | */ |
18 | | class QuotedPrintableCodec : public Codec |
19 | | { |
20 | | public: |
21 | 1 | constexpr QuotedPrintableCodec() = default; |
22 | | |
23 | | constexpr ~QuotedPrintableCodec() override = default; |
24 | | |
25 | | constexpr const char *name() const override |
26 | 731 | { |
27 | 731 | return "quoted-printable"; |
28 | 731 | } |
29 | | |
30 | | qsizetype maxEncodedSizeFor(qsizetype insize, NewlineType newline = Codec::NewlineLF) const override |
31 | 0 | { |
32 | | // all chars encoded: |
33 | 0 | qsizetype result = 3 * insize; |
34 | | // then after 25 hexchars comes a soft linebreak: =(\r)\n |
35 | 0 | result += (newline == Codec::NewlineCRLF ? 3 : 2) * (insize / 25); |
36 | |
|
37 | 0 | return result; |
38 | 0 | } |
39 | | |
40 | | qsizetype maxDecodedSizeFor(qsizetype insize, NewlineType newline = Codec::NewlineLF) const override; |
41 | | |
42 | | Encoder *makeEncoder(NewlineType newline = Codec::NewlineLF) const override; |
43 | | |
44 | | Decoder *makeDecoder(NewlineType newline = Codec::NewlineLF) const override; |
45 | | }; |
46 | | |
47 | | /* |
48 | | A class representing the codec for the Q encoding as specified |
49 | | in RFC2047Q. |
50 | | */ |
51 | | class Rfc2047QEncodingCodec : public Codec |
52 | | { |
53 | | public: |
54 | 1 | constexpr Rfc2047QEncodingCodec() = default; |
55 | | |
56 | | constexpr ~Rfc2047QEncodingCodec() override = default; |
57 | | |
58 | | constexpr const char *name() const override |
59 | 351 | { |
60 | 351 | return "q"; |
61 | 351 | } |
62 | | |
63 | | qsizetype maxEncodedSizeFor(qsizetype insize, Codec::NewlineType newline = Codec::NewlineLF) const override |
64 | 0 | { |
65 | 0 | Q_UNUSED(newline); |
66 | | // this one is simple: We don't do linebreaking, so all that can |
67 | | // happen is that every char needs encoding, so: |
68 | 0 | return 3 * insize; |
69 | 0 | } |
70 | | |
71 | | qsizetype maxDecodedSizeFor(qsizetype insize, Codec::NewlineType newline = Codec::NewlineLF) const override; |
72 | | |
73 | | Encoder *makeEncoder(Codec::NewlineType newline = Codec::NewlineLF) const override; |
74 | | |
75 | | Decoder *makeDecoder(Codec::NewlineType newline = Codec::NewlineLF) const override; |
76 | | }; |
77 | | |
78 | | /* |
79 | | A class representing the codec for RFC2231. |
80 | | */ |
81 | | class Rfc2231EncodingCodec : public Codec |
82 | | { |
83 | | public: |
84 | 1 | constexpr Rfc2231EncodingCodec() = default; |
85 | | |
86 | | constexpr ~Rfc2231EncodingCodec() override = default; |
87 | | |
88 | | constexpr const char *name() const override |
89 | 0 | { |
90 | 0 | return "x-kmime-rfc2231"; |
91 | 0 | } |
92 | | |
93 | | qsizetype maxEncodedSizeFor(qsizetype insize, Codec::NewlineType newline = Codec::NewlineLF) const override |
94 | 0 | { |
95 | 0 | Q_UNUSED(newline); |
96 | | // same as for "q" encoding: |
97 | 0 | return 3 * insize; |
98 | 0 | } |
99 | | |
100 | | qsizetype maxDecodedSizeFor(qsizetype insize, Codec::NewlineType newline = Codec::NewlineLF) const override; |
101 | | |
102 | | Encoder *makeEncoder(Codec::NewlineType newline = Codec::NewlineLF) const override; |
103 | | |
104 | | Decoder *makeDecoder(Codec::NewlineType newline = Codec::NewlineLF) const override; |
105 | | }; |
106 | | |
107 | | } // namespace KCodecs |
108 | | |
109 | | #endif // KCODECS_QP_H |