File indexing completed on 2024-10-06 12:16:34
0001 /* -*- c++ -*- 0002 SPDX-FileCopyrightText: 2001-2002 Marc Mutz <mutz@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 /** 0007 @file 0008 This file is part of the API for handling @ref MIME data and 0009 defines the @ref QuotedPrintable, @ref RFC2047Q, and 0010 @ref RFC2231 @ref Codec classes. 0011 0012 @brief 0013 Defines the classes QuotedPrintableCodec, Rfc2047QEncodingCodec, and 0014 Rfc2231EncodingCodec. 0015 0016 @authors Marc Mutz \<mutz@kde.org\> 0017 0018 @glossary @anchor QuotedPrintable @anchor quotedprintable @b quoted-printable: 0019 a binary to text encoding scheme based on Section 6.7 of @ref RFC2045. 0020 0021 @glossary @anchor RFC2047Q @anchor rfc2047q @b RFC @b 2047Q: 0022 Section 4.2 of @ref RFC2047. 0023 0024 @glossary @anchor RFC2231 @anchor rfc2231 @b RFC @b 2231: 0025 RFC that defines the <a href="http://tools.ietf.org/html/rfc2231"> 0026 MIME Parameter Value and Encoded Word Extensions: Character Sets, Languages, 0027 and Continuations</a>. 0028 */ 0029 0030 #ifndef KCODECS_QP_H 0031 #define KCODECS_QP_H 0032 0033 #include "kcodecs.h" 0034 0035 namespace KCodecs 0036 { 0037 /** 0038 @brief 0039 A class representing the @ref codec for @ref QuotedPrintable as specified in 0040 @ref RFC2045 (section 6.7). 0041 */ 0042 class QuotedPrintableCodec : public Codec 0043 { 0044 public: 0045 /** 0046 Constructs a QuotedPrintable codec. 0047 */ 0048 QuotedPrintableCodec() 0049 : Codec() 0050 { 0051 } 0052 0053 /** 0054 Destroys the codec. 0055 */ 0056 ~QuotedPrintableCodec() override 0057 { 0058 } 0059 0060 /** 0061 @copydoc 0062 Codec::name() 0063 */ 0064 const char *name() const override 0065 { 0066 return "quoted-printable"; 0067 } 0068 0069 /** 0070 @copydoc 0071 Codec::maxEncodedSizeFor() 0072 */ 0073 int maxEncodedSizeFor(int insize, NewlineType newline = Codec::NewlineLF) const override 0074 { 0075 // all chars encoded: 0076 int result = 3 * insize; 0077 // then after 25 hexchars comes a soft linebreak: =(\r)\n 0078 result += (newline == Codec::NewlineCRLF ? 3 : 2) * (insize / 25); 0079 0080 return result; 0081 } 0082 0083 /** 0084 @copydoc 0085 Codec::maxDecodedSizeFor() 0086 */ 0087 int maxDecodedSizeFor(int insize, NewlineType newline = Codec::NewlineLF) const override; 0088 0089 /** 0090 @copydoc 0091 Codec::makeEncoder() 0092 */ 0093 Encoder *makeEncoder(NewlineType newline = Codec::NewlineLF) const override; 0094 0095 /** 0096 @copydoc 0097 Codec::makeDecoder() 0098 */ 0099 Decoder *makeDecoder(NewlineType newline = Codec::NewlineLF) const override; 0100 }; 0101 0102 /** 0103 @brief 0104 A class representing the @ref codec for the Q encoding as specified 0105 in @ref RFC2047Q. 0106 */ 0107 class Rfc2047QEncodingCodec : public Codec 0108 { 0109 public: 0110 /** 0111 Constructs a RFC2047Q codec. 0112 */ 0113 Rfc2047QEncodingCodec() 0114 : Codec() 0115 { 0116 } 0117 0118 /** 0119 Destroys the codec. 0120 */ 0121 ~Rfc2047QEncodingCodec() override 0122 { 0123 } 0124 0125 /** 0126 @copydoc 0127 Codec::name() 0128 */ 0129 const char *name() const override 0130 { 0131 return "q"; 0132 } 0133 0134 /** 0135 @copydoc 0136 Codec::maxEncodedSizeFor() 0137 */ 0138 int maxEncodedSizeFor(int insize, Codec::NewlineType newline = Codec::NewlineLF) const override 0139 { 0140 Q_UNUSED(newline); 0141 // this one is simple: We don't do linebreaking, so all that can 0142 // happen is that every char needs encoding, so: 0143 return 3 * insize; 0144 } 0145 0146 /** 0147 @copydoc 0148 Codec::maxDecodedSizeFor() 0149 */ 0150 int maxDecodedSizeFor(int insize, Codec::NewlineType newline = Codec::NewlineLF) const override; 0151 0152 /** 0153 @copydoc 0154 Codec::makeEncoder() 0155 */ 0156 Encoder *makeEncoder(Codec::NewlineType newline = Codec::NewlineLF) const override; 0157 0158 /** 0159 @copydoc 0160 Codec::makeDecoder() 0161 */ 0162 Decoder *makeDecoder(Codec::NewlineType newline = Codec::NewlineLF) const override; 0163 }; 0164 0165 /** 0166 @brief 0167 A class representing the @ref codec for @ref RFC2231. 0168 */ 0169 class Rfc2231EncodingCodec : public Codec 0170 { 0171 public: 0172 /** 0173 Constructs a RFC2231 codec. 0174 */ 0175 Rfc2231EncodingCodec() 0176 : Codec() 0177 { 0178 } 0179 0180 /** 0181 Destroys the codec. 0182 */ 0183 ~Rfc2231EncodingCodec() override 0184 { 0185 } 0186 0187 /** 0188 @copydoc 0189 Codec::name() 0190 */ 0191 const char *name() const override 0192 { 0193 return "x-kmime-rfc2231"; 0194 } 0195 0196 /** 0197 @copydoc 0198 Codec::maxEncodedSizeFor() 0199 */ 0200 int maxEncodedSizeFor(int insize, Codec::NewlineType newline = Codec::NewlineLF) const override 0201 { 0202 Q_UNUSED(newline); 0203 // same as for "q" encoding: 0204 return 3 * insize; 0205 } 0206 0207 /** 0208 @copydoc 0209 Codec::maxDecodedSizeFor() 0210 */ 0211 int maxDecodedSizeFor(int insize, Codec::NewlineType newline = Codec::NewlineLF) const override; 0212 0213 /** 0214 @copydoc 0215 Codec::makeEncoder() 0216 */ 0217 Encoder *makeEncoder(Codec::NewlineType newline = Codec::NewlineLF) const override; 0218 0219 /** 0220 @copydoc 0221 Codec::makeDecoder() 0222 */ 0223 Decoder *makeDecoder(Codec::NewlineType newline = Codec::NewlineLF) const override; 0224 }; 0225 0226 } // namespace KCodecs 0227 0228 #endif // KCODECS_QP_H