1/* -*- c++ -*-
2 kmime_codec_identity.cpp
3
4 KMime, the KDE Internet mail/usenet news message library.
5 Copyright (c) 2004 Marc Mutz <mutz@kde.org>
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
21*/
22/**
23 @file
24 This file is part of the API for handling @ref MIME data and
25 defines the Identity, @ref seven-bit-text, @ref eight-bit-text,
26 and @ref eight-bit-binary @ref Codec classes.
27
28 @brief
29 Defines the classes IdentityCodec, SevenBitCodec, EightBitCodec,
30 and BinaryCodec.
31
32 @authors Marc Mutz \<mutz@kde.org\>
33*/
34
35#include "kmime_codec_identity.h"
36
37#include <kdebug.h>
38#include <kglobal.h>
39
40#include <QtCore/QByteArray>
41
42#include <cassert>
43#include <cstring>
44
45using namespace KMime;
46
47namespace KMime {
48
49class IdentityEnDecoder : public Encoder, public Decoder
50{
51 protected:
52 friend class IdentityCodec;
53 IdentityEnDecoder( bool withCRLF ): Encoder( false )
54 {
55 kWarning( withCRLF ) << "IdentityEnDecoder: withCRLF isn't yet supported!";
56 }
57
58 public:
59 ~IdentityEnDecoder() {}
60
61 bool encode( const char* &scursor, const char *const send,
62 char* &dcursor, const char *const dend )
63 { return decode( scursor, send, dcursor, dend ); }
64
65 bool decode( const char* &scursor, const char *const send,
66 char* &dcursor, const char *const dend );
67
68 bool finish( char* &dcursor, const char *const dend )
69 { Q_UNUSED( dcursor ); Q_UNUSED( dend ); return true; }
70};
71
72Encoder *IdentityCodec::makeEncoder( bool withCRLF ) const
73{
74 return new IdentityEnDecoder( withCRLF );
75}
76
77Decoder *IdentityCodec::makeDecoder( bool withCRLF ) const
78{
79 return new IdentityEnDecoder( withCRLF );
80}
81
82/********************************************************/
83/********************************************************/
84/********************************************************/
85
86bool IdentityEnDecoder::decode( const char* &scursor, const char *const send,
87 char* &dcursor, const char *const dend )
88{
89 const int size = qMin( send - scursor, dcursor - dend );
90 if ( size > 0 ) {
91 std::memmove( dcursor, scursor, size );
92 dcursor += size;
93 scursor += size;
94 }
95 return scursor == send;
96}
97
98QByteArray IdentityCodec::encode( const QByteArray &src, bool withCRLF ) const
99{
100 kWarning( withCRLF ) << "IdentityCodec::encode(): withCRLF not yet supported!";
101 return src;
102}
103
104QByteArray IdentityCodec::decode( const QByteArray &src, bool withCRLF ) const
105{
106 kWarning( withCRLF ) << "IdentityCodec::decode(): withCRLF not yet supported!";
107 return src;
108}
109
110} // namespace KMime
111