summaryrefslogtreecommitdiff
path: root/kmime/kmime_codec_identity.h
blob: 65f137ec7e8d1312d3360ac0f32eb88ac6f44149 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*  -*- c++ -*-
    kmime_codec_identity.h

    KMime, the KDE Internet mail/usenet news message library.
    Copyright (c) 2004 Marc Mutz <mutz@kde.org>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/
/**
  @file
  This file is part of the API for handling @ref MIME data and
  defines the Identity, @ref seven-bit-text, @ref eight-bit-text,
  and @ref eight-bit-binary @ref Codec classes.

  @brief
  Defines the classes IdentityCodec, SevenBitCodec, EightBitCodec,
  and BinaryCodec.

  @authors Marc Mutz \<mutz@kde.org\>
*/

#ifndef __KMIME_CODEC_IDENTITY_H__
#define __KMIME_CODEC_IDENTITY_H__

#include "kmime_codecs.h"

class QByteArray;

namespace KMime {

/**
  @brief
  A class representing the Identify @ref codec.
*/
class KMIME_EXPORT IdentityCodec : public Codec
{
  protected:
    friend class Codec;
    /**
      Constructs the Identity codec.
    */
    IdentityCodec() : Codec() {}

  public:
    /**
      Destroys the codec.
    */
    ~IdentityCodec() {}

    using Codec::encode;
    using Codec::decode;

    /**
      @copydoc
      QByteArray Codec::encode()
    */
    QByteArray encode( const QByteArray &src, bool withCRLF=false ) const;

    /**
      @copydoc
      QByteArray Codec::decode()
    */
    QByteArray decode( const QByteArray &src, bool withCRLF=false ) const;

    /**
      @copydoc
      Codec::maxEncodedSizeFor()
    */
    int maxEncodedSizeFor( int insize, bool withCRLF ) const
    {
      if ( withCRLF ) {
        return 2 * insize;
      } else {
        return insize;
      }
    }

    /**
      @copydoc
      Codec::maxDecodedSizeFor()
    */
    int maxDecodedSizeFor( int insize, bool withCRLF ) const
    {
      if ( withCRLF ) {
        return 2 * insize;
      } else {
        return insize;
      }
    }

    /**
      @copydoc
      Codec::makeEncoder()
    */
    Encoder *makeEncoder( bool withCRLF=false ) const;

    /**
      @copydoc
      Codec::makeDecoder()
    */
    Decoder *makeDecoder( bool withCRLF=false ) const;
};

/**
  @brief
  A class representing the @ref codec for @ref seven-bit-text.
*/
class KMIME_EXPORT SevenBitCodec : public IdentityCodec
{
  protected:
    friend class Codec;
    /**
      Constructs the 7-bit codec.
    */
    SevenBitCodec() : IdentityCodec() {}

  public:
    /**
      Destroys the codec.
    */
    ~SevenBitCodec() {}

    /**
      @copydoc
      Codec::name()
    */
    const char *name() const
    { return "7bit"; }
};

/**
  @brief
  A class representing the @ref codec for @ref eight-bit-text.
*/
class KMIME_EXPORT EightBitCodec : public IdentityCodec
{
  protected:
    friend class Codec;
    /**
      Constructs the 8-bit codec.
    */
    EightBitCodec() : IdentityCodec() {}

  public:
    /**
      Destroys the codec.
    */
    ~EightBitCodec() {}

    /**
      @copydoc
      Codec::name()
    */
    const char *name() const
    { return "8bit"; }
};

/**
  @brief
  A class representing the @ref codec for @ref eight-bit-binary.
*/
class KMIME_EXPORT BinaryCodec : public IdentityCodec
{
  protected:
    friend class Codec;
    /**
      Constructs the 8-bit-binary codec.
    */
    BinaryCodec() : IdentityCodec() {}

  public:
    /**
      Destroys the codec.
    */
    ~BinaryCodec() {}

    /**
      @copydoc
      Codec::name()
    */
    const char *name() const
    { return "binary"; }

    /**
      @copydoc
      Codec::maxEncodedSizeFor()
    */
    int maxEncodedSizeFor( int insize, bool withCRLF=false ) const
    { Q_UNUSED( withCRLF ); return insize; }

    /**
      @copydoc
      Codec::maxDecodedSizeFor()
    */
    int maxDecodedSizeFor( int insize, bool withCRLF=false ) const
    { Q_UNUSED( withCRLF ); return insize; }
};

} // namespace KMime

#endif // __KMIME_CODEC_IDENTITY_H__