libkmime

kmime_codec_qp.h
1/*
2 kmime_codec_qp.h
3
4 This file is part of KMime, the KDE internet mail/usenet news message library.
5 Copyright (c) 2001-2002 Marc Mutz <mutz@kde.org>
6
7 KMime is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License, version 2, as
9 published by the Free Software Foundation.
10
11 KMime is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
20 In addition, as a special exception, the copyright holders give
21 permission to link the code of this library with any edition of
22 the TQt library by Trolltech AS, Norway (or with modified versions
23 of TQt that use the same license as TQt), and distribute linked
24 combinations including the two. You must obey the GNU General
25 Public License in all respects for all of the code used other than
26 TQt. If you modify this file, you may extend this exception to
27 your version of the file, but you are not obligated to do so. If
28 you do not wish to do so, delete this exception statement from
29 your version.
30*/
31
32#ifndef __KMIME_CODEC_TQP__
33#define __KMIME_CODEC_TQP__
34
35#include "kmime_codecs.h"
36
37namespace KMime {
38
39
40class QuotedPrintableCodec : public Codec {
41protected:
42 friend class Codec;
43 QuotedPrintableCodec() : Codec() {}
44
45public:
46 virtual ~QuotedPrintableCodec() {}
47
48 const char * name() const {
49 return "quoted-printable";
50 }
51
52 int maxEncodedSizeFor( int insize, bool withCRLF=false ) const {
53 // all chars encoded:
54 int result = 3*insize;
55 // then after 25 hexchars comes a soft linebreak: =(\r)\n
56 result += (withCRLF ? 3 : 2) * (insize/25);
57
58 return result;
59 }
60
61 int maxDecodedSizeFor( int insize, bool withCRLF=false ) const;
62
63 Encoder * makeEncoder( bool withCRLF=false ) const;
64 Decoder * makeDecoder( bool withCRLF=false ) const;
65};
66
67
68class Rfc2047TQEncodingCodec : public Codec {
69protected:
70 friend class Codec;
71 Rfc2047TQEncodingCodec() : Codec() {}
72
73public:
74 virtual ~Rfc2047TQEncodingCodec() {}
75
76 const char * name() const {
77 return "q";
78 }
79
80 int maxEncodedSizeFor( int insize, bool withCRLF=false ) const {
81 (void)withCRLF; // keep compiler happy
82 // this one is simple: We don't do linebreaking, so all that can
83 // happen is that every char needs encoding, so:
84 return 3*insize;
85 }
86
87 int maxDecodedSizeFor( int insize, bool withCRLF=false ) const;
88
89 Encoder * makeEncoder( bool withCRLF=false ) const;
90 Decoder * makeDecoder( bool withCRLF=false ) const;
91};
92
93
94class Rfc2231EncodingCodec : public Codec {
95protected:
96 friend class Codec;
97 Rfc2231EncodingCodec() : Codec() {}
98
99public:
100 virtual ~Rfc2231EncodingCodec() {}
101
102 const char * name() const {
103 return "x-kmime-rfc2231";
104 }
105
106 int maxEncodedSizeFor( int insize, bool withCRLF=false ) const {
107 (void)withCRLF; // keep compiler happy
108 // same as for "q" encoding:
109 return 3*insize;
110 }
111
112 int maxDecodedSizeFor( int insize, bool withCRLF=false ) const;
113
114 Encoder * makeEncoder( bool withCRLF=false ) const;
115 Decoder * makeDecoder( bool withCRLF=false ) const;
116};
117
118
119} // namespace KMime
120
121#endif // __KMIME_CODEC_TQP__