KMIME Library
kmime_codec_identity.cpp
Go to the documentation of this file.
00001 /* -*- c++ -*- 00002 kmime_codec_identity.cpp 00003 00004 KMime, the KDE Internet mail/usenet news message library. 00005 Copyright (c) 2004 Marc Mutz <mutz@kde.org> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00020 Boston, MA 02110-1301, USA. 00021 */ 00035 #include "kmime_codec_identity.h" 00036 00037 #include <kdebug.h> 00038 #include <kglobal.h> 00039 00040 #include <QtCore/QByteArray> 00041 00042 #include <cassert> 00043 #include <cstring> 00044 00045 using namespace KMime; 00046 00047 namespace KMime { 00048 00049 class IdentityEnDecoder : public Encoder, public Decoder 00050 { 00051 protected: 00052 friend class IdentityCodec; 00053 IdentityEnDecoder( bool withCRLF ): Encoder( false ) 00054 { 00055 kWarning( withCRLF ) << "IdentityEnDecoder: withCRLF isn't yet supported!"; 00056 } 00057 00058 public: 00059 ~IdentityEnDecoder() {} 00060 00061 bool encode( const char* &scursor, const char *const send, 00062 char* &dcursor, const char *const dend ) 00063 { return decode( scursor, send, dcursor, dend ); } 00064 00065 bool decode( const char* &scursor, const char *const send, 00066 char* &dcursor, const char *const dend ); 00067 00068 bool finish( char* &dcursor, const char *const dend ) 00069 { Q_UNUSED( dcursor ); Q_UNUSED( dend ); return true; } 00070 }; 00071 00072 Encoder *IdentityCodec::makeEncoder( bool withCRLF ) const 00073 { 00074 return new IdentityEnDecoder( withCRLF ); 00075 } 00076 00077 Decoder *IdentityCodec::makeDecoder( bool withCRLF ) const 00078 { 00079 return new IdentityEnDecoder( withCRLF ); 00080 } 00081 00082 /********************************************************/ 00083 /********************************************************/ 00084 /********************************************************/ 00085 00086 bool IdentityEnDecoder::decode( const char* &scursor, const char *const send, 00087 char* &dcursor, const char *const dend ) 00088 { 00089 const int size = qMin( send - scursor, dcursor - dend ); 00090 if ( size > 0 ) { 00091 std::memmove( dcursor, scursor, size ); 00092 dcursor += size; 00093 scursor += size; 00094 } 00095 return scursor == send; 00096 } 00097 00098 QByteArray IdentityCodec::encode( const QByteArray &src, bool withCRLF ) const 00099 { 00100 kWarning( withCRLF ) << "IdentityCodec::encode(): withCRLF not yet supported!"; 00101 return src; 00102 } 00103 00104 QByteArray IdentityCodec::decode( const QByteArray &src, bool withCRLF ) const 00105 { 00106 kWarning( withCRLF ) << "IdentityCodec::decode(): withCRLF not yet supported!"; 00107 return src; 00108 } 00109 00110 } // namespace KMime