|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 #ifndef QMAILCODEC_H |
|
42 #define QMAILCODEC_H |
|
43 |
|
44 #include "qmailglobal.h" |
|
45 #include <QByteArray> |
|
46 #include <QDataStream> |
|
47 #include <QString> |
|
48 #include <QTextStream> |
|
49 |
|
50 class QTOPIAMAIL_EXPORT QMailCodec |
|
51 { |
|
52 public: |
|
53 enum { ChunkCharacters = 8192 }; |
|
54 |
|
55 virtual ~QMailCodec(); |
|
56 |
|
57 virtual QString name() const = 0; |
|
58 |
|
59 // Stream conversion interface including character translation |
|
60 virtual void encode(QDataStream& out, QTextStream& in, const QString& charset = "UTF-8"); |
|
61 virtual void decode(QTextStream& out, QDataStream& in, const QString& charset); |
|
62 |
|
63 // Stream conversion interface |
|
64 virtual void encode(QDataStream& out, QDataStream& in); |
|
65 virtual void decode(QDataStream& out, QDataStream& in); |
|
66 |
|
67 // Convenience functions to encapsulate stream processing |
|
68 QByteArray encode(const QString& in, const QString& charset = "UTF-8"); |
|
69 QString decode(const QByteArray& in, const QString& charset); |
|
70 |
|
71 QByteArray encode(const QByteArray& in); |
|
72 QByteArray decode(const QByteArray& in); |
|
73 |
|
74 // Static helper functions |
|
75 static void copy(QDataStream& out, QDataStream& in); |
|
76 static void copy(QTextStream& out, QTextStream& in); |
|
77 |
|
78 protected: |
|
79 // Helper functions to convert stream chunks |
|
80 virtual void encodeChunk(QDataStream& out, const unsigned char* in, int length, bool finalChunk) = 0; |
|
81 virtual void decodeChunk(QDataStream& out, const char* in, int length, bool finalChunk) = 0; |
|
82 }; |
|
83 |
|
84 class QTOPIAMAIL_EXPORT QMailBase64Codec : public QMailCodec |
|
85 { |
|
86 public: |
|
87 enum ContentType { Text, Binary }; |
|
88 |
|
89 QMailBase64Codec(ContentType content, int maximumLineLength = -1); |
|
90 |
|
91 virtual QString name() const; |
|
92 |
|
93 protected: |
|
94 virtual void encodeChunk(QDataStream& out, const unsigned char* in, int length, bool finalChunk); |
|
95 virtual void decodeChunk(QDataStream& out, const char* in, int length, bool finalChunk); |
|
96 |
|
97 private: |
|
98 ContentType _content; |
|
99 int _maximumLineLength; |
|
100 |
|
101 unsigned char _encodeBuffer[3]; |
|
102 unsigned char* _encodeBufferOut; |
|
103 int _encodeLineCharsRemaining; |
|
104 |
|
105 unsigned char _decodeBuffer[4]; |
|
106 unsigned char* _decodeBufferOut; |
|
107 int _decodePaddingCount; |
|
108 |
|
109 unsigned char _lastChar; |
|
110 }; |
|
111 |
|
112 class QTOPIAMAIL_EXPORT QMailQuotedPrintableCodec : public QMailCodec |
|
113 { |
|
114 public: |
|
115 enum ContentType { Text, Binary }; |
|
116 enum ConformanceType { Rfc2045, Rfc2047 }; |
|
117 |
|
118 QMailQuotedPrintableCodec(ContentType content, ConformanceType conformance, int maximumLineLength = -1); |
|
119 |
|
120 virtual QString name() const; |
|
121 |
|
122 protected: |
|
123 virtual void encodeChunk(QDataStream& out, const unsigned char* in, int length, bool finalChunk); |
|
124 virtual void decodeChunk(QDataStream& out, const char* in, int length, bool finalChunk); |
|
125 |
|
126 private: |
|
127 ContentType _content; |
|
128 ConformanceType _conformance; |
|
129 int _maximumLineLength; |
|
130 |
|
131 int _encodeLineCharsRemaining; |
|
132 unsigned char _encodeLastChar; |
|
133 |
|
134 char _decodePrecedingInput; |
|
135 unsigned char _decodeLastChar; |
|
136 }; |
|
137 |
|
138 class QTOPIAMAIL_EXPORT QMailPassThroughCodec : public QMailCodec |
|
139 { |
|
140 virtual QString name() const; |
|
141 |
|
142 protected: |
|
143 virtual void encodeChunk(QDataStream& out, const unsigned char* in, int length, bool finalChunk); |
|
144 virtual void decodeChunk(QDataStream& out, const char* in, int length, bool finalChunk); |
|
145 }; |
|
146 |
|
147 class QTOPIAMAIL_EXPORT QMailLineEndingCodec : public QMailCodec |
|
148 { |
|
149 virtual QString name() const; |
|
150 |
|
151 public: |
|
152 QMailLineEndingCodec(); |
|
153 |
|
154 protected: |
|
155 virtual void encodeChunk(QDataStream& out, const unsigned char* in, int length, bool finalChunk); |
|
156 virtual void decodeChunk(QDataStream& out, const char* in, int length, bool finalChunk); |
|
157 |
|
158 private: |
|
159 unsigned char _lastChar; |
|
160 }; |
|
161 |
|
162 #endif |