| 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 | QuotedPrintableCodec() |
| 22 | : Codec() |
| 23 | { |
| 24 | } |
| 25 | |
| 26 | ~QuotedPrintableCodec() override |
| 27 | { |
| 28 | } |
| 29 | |
| 30 | const char *name() const override |
| 31 | { |
| 32 | return "quoted-printable"; |
| 33 | } |
| 34 | |
| 35 | qsizetype maxEncodedSizeFor(qsizetype insize, NewlineType newline = Codec::NewlineLF) const override |
| 36 | { |
| 37 | // all chars encoded: |
| 38 | qsizetype result = 3 * insize; |
| 39 | // then after 25 hexchars comes a soft linebreak: =(\r)\n |
| 40 | result += (newline == Codec::NewlineCRLF ? 3 : 2) * (insize / 25); |
| 41 | |
| 42 | return result; |
| 43 | } |
| 44 | |
| 45 | qsizetype maxDecodedSizeFor(qsizetype insize, NewlineType newline = Codec::NewlineLF) const override; |
| 46 | |
| 47 | Encoder *makeEncoder(NewlineType newline = Codec::NewlineLF) const override; |
| 48 | |
| 49 | Decoder *makeDecoder(NewlineType newline = Codec::NewlineLF) const override; |
| 50 | }; |
| 51 | |
| 52 | /* |
| 53 | A class representing the codec for the Q encoding as specified |
| 54 | in RFC2047Q. |
| 55 | */ |
| 56 | class Rfc2047QEncodingCodec : public Codec |
| 57 | { |
| 58 | public: |
| 59 | Rfc2047QEncodingCodec() |
| 60 | : Codec() |
| 61 | { |
| 62 | } |
| 63 | |
| 64 | ~Rfc2047QEncodingCodec() override |
| 65 | { |
| 66 | } |
| 67 | |
| 68 | const char *name() const override |
| 69 | { |
| 70 | return "q"; |
| 71 | } |
| 72 | |
| 73 | qsizetype maxEncodedSizeFor(qsizetype insize, Codec::NewlineType newline = Codec::NewlineLF) const override |
| 74 | { |
| 75 | Q_UNUSED(newline); |
| 76 | // this one is simple: We don't do linebreaking, so all that can |
| 77 | // happen is that every char needs encoding, so: |
| 78 | return 3 * insize; |
| 79 | } |
| 80 | |
| 81 | qsizetype maxDecodedSizeFor(qsizetype insize, Codec::NewlineType newline = Codec::NewlineLF) const override; |
| 82 | |
| 83 | Encoder *makeEncoder(Codec::NewlineType newline = Codec::NewlineLF) const override; |
| 84 | |
| 85 | Decoder *makeDecoder(Codec::NewlineType newline = Codec::NewlineLF) const override; |
| 86 | }; |
| 87 | |
| 88 | /* |
| 89 | A class representing the codec for RFC2231. |
| 90 | */ |
| 91 | class Rfc2231EncodingCodec : public Codec |
| 92 | { |
| 93 | public: |
| 94 | Rfc2231EncodingCodec() |
| 95 | : Codec() |
| 96 | { |
| 97 | } |
| 98 | |
| 99 | ~Rfc2231EncodingCodec() override |
| 100 | { |
| 101 | } |
| 102 | |
| 103 | const char *name() const override |
| 104 | { |
| 105 | return "x-kmime-rfc2231"; |
| 106 | } |
| 107 | |
| 108 | qsizetype maxEncodedSizeFor(qsizetype insize, Codec::NewlineType newline = Codec::NewlineLF) const override |
| 109 | { |
| 110 | Q_UNUSED(newline); |
| 111 | // same as for "q" encoding: |
| 112 | return 3 * insize; |
| 113 | } |
| 114 | |
| 115 | qsizetype maxDecodedSizeFor(qsizetype insize, Codec::NewlineType newline = Codec::NewlineLF) const override; |
| 116 | |
| 117 | Encoder *makeEncoder(Codec::NewlineType newline = Codec::NewlineLF) const override; |
| 118 | |
| 119 | Decoder *makeDecoder(Codec::NewlineType newline = Codec::NewlineLF) const override; |
| 120 | }; |
| 121 | |
| 122 | } // namespace KCodecs |
| 123 | |
| 124 | #endif // KCODECS_QP_H |
| 125 |
