KIMAP Library
message_p.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef KIMAP_MESSAGE_P_H
00021 #define KIMAP_MESSAGE_P_H
00022
00023 #include <QtCore/QByteArray>
00024 #include <QtCore/QList>
00025 #include <QtCore/QMetaType>
00026
00027 namespace KIMAP {
00028
00029 struct Message
00030 {
00031 class Part
00032 {
00033 public:
00034 enum Type { String = 0, List };
00035
00036 explicit Part(const QByteArray &string)
00037 : m_type(String), m_string(string) { }
00038 explicit Part(const QList<QByteArray> &list)
00039 : m_type(List), m_list(list) { }
00040
00041 inline Type type() const { return m_type; }
00042 inline QByteArray toString() const { return m_string; }
00043 inline QList<QByteArray> toList() const { return m_list; }
00044
00045 private:
00046 Type m_type;
00047 QByteArray m_string;
00048 QList<QByteArray> m_list;
00049 };
00050
00051 inline QByteArray toString() const
00052 {
00053 QByteArray result;
00054
00055 foreach ( const Part &part, content ) {
00056 if ( part.type()==Part::List ) {
00057 result+='(';
00058 foreach ( const QByteArray &item, part.toList() ) {
00059 result+= ' ';
00060 result+= item;
00061 }
00062 result+=" ) ";
00063 } else {
00064 result+= part.toString()+' ';
00065 }
00066 }
00067
00068 if ( !responseCode.isEmpty() ) {
00069 result+="[ ";
00070 foreach ( const Part &part, responseCode ) {
00071 if ( part.type()==Part::List ) {
00072 result+='(';
00073 foreach ( const QByteArray &item, part.toList() ) {
00074 result+= ' ';
00075 result+= item;
00076 }
00077 result+=" ) ";
00078 } else {
00079 result+= part.toString()+' ';
00080 }
00081 }
00082 result+=" ]";
00083 }
00084
00085 return result;
00086 }
00087
00088 QList<Part> content;
00089 QList<Part> responseCode;
00090 };
00091
00092 }
00093
00094 Q_DECLARE_METATYPE(KIMAP::Message)
00095 static const int _kimap_messageTypeId = qRegisterMetaType<KIMAP::Message>();
00096
00097 #endif