1 | /* |
2 | Copyright (c) 2009 Kevin Ottens <ervin@kde.org> |
3 | |
4 | This library is free software; you can redistribute it and/or modify it |
5 | under the terms of the GNU Library General Public License as published by |
6 | the Free Software Foundation; either version 2 of the License, or (at your |
7 | option) any later version. |
8 | |
9 | This library is distributed in the hope that it will be useful, but WITHOUT |
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public |
12 | License for more details. |
13 | |
14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to the |
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
17 | 02110-1301, USA. |
18 | */ |
19 | |
20 | #ifndef KIMAP_MESSAGE_P_H |
21 | #define KIMAP_MESSAGE_P_H |
22 | |
23 | #include <QtCore/QByteArray> |
24 | #include <QtCore/QList> |
25 | #include <QtCore/QMetaType> |
26 | |
27 | namespace KIMAP { |
28 | |
29 | struct Message |
30 | { |
31 | class Part |
32 | { |
33 | public: |
34 | enum Type { String = 0, List }; |
35 | |
36 | explicit Part(const QByteArray &string) |
37 | : m_type( String ), m_string( string ) { } |
38 | explicit Part(const QList<QByteArray> &list) |
39 | : m_type( List ), m_list( list ) { } |
40 | |
41 | inline Type type() const { return m_type; } |
42 | inline QByteArray toString() const { return m_string; } |
43 | inline QList<QByteArray> toList() const { return m_list; } |
44 | |
45 | private: |
46 | Type m_type; |
47 | QByteArray m_string; |
48 | QList<QByteArray> m_list; |
49 | }; |
50 | |
51 | inline QByteArray toString() const |
52 | { |
53 | QByteArray result; |
54 | |
55 | foreach ( const Part &part, content ) { |
56 | if ( part.type() == Part::List ) { |
57 | result += '('; |
58 | foreach ( const QByteArray &item, part.toList() ) { |
59 | result += ' '; |
60 | result += item; |
61 | } |
62 | result += " ) " ; |
63 | } else { |
64 | result += part.toString() + ' '; |
65 | } |
66 | } |
67 | |
68 | if ( !responseCode.isEmpty() ) { |
69 | result+="[ " ; |
70 | foreach ( const Part &part, responseCode ) { |
71 | if ( part.type() == Part::List ) { |
72 | result+='('; |
73 | foreach ( const QByteArray &item, part.toList() ) { |
74 | result+= ' '; |
75 | result+= item; |
76 | } |
77 | result+=" ) " ; |
78 | } else { |
79 | result+= part.toString() + ' '; |
80 | } |
81 | } |
82 | result+=" ]" ; |
83 | } |
84 | |
85 | return result; |
86 | } |
87 | |
88 | QList<Part> content; |
89 | QList<Part> responseCode; |
90 | }; |
91 | |
92 | } |
93 | |
94 | Q_DECLARE_METATYPE( KIMAP::Message ) |
95 | static const int _kimap_messageTypeId = qRegisterMetaType<KIMAP::Message>(); |
96 | |
97 | #endif |
98 | |