00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "imapinfo.h"
00043 #include "imapparser.h"
00044
00045 #include <kdebug.h>
00046
00047 imapInfo::imapInfo ():count_ (0),
00048 recent_ (0),
00049 unseen_ (0),
00050 uidValidity_ (0),
00051 uidNext_ (0),
00052 flags_ (0),
00053 permanentFlags_ (0),
00054 readWrite_ (false),
00055 countAvailable_ (false),
00056 recentAvailable_ (false),
00057 unseenAvailable_ (false),
00058 uidValidityAvailable_ (false),
00059 uidNextAvailable_ (false),
00060 flagsAvailable_ (false),
00061 permanentFlagsAvailable_ (false), readWriteAvailable_ (false)
00062 {
00063 }
00064
00065 imapInfo::imapInfo (const imapInfo & mi):count_ (mi.count_),
00066 recent_ (mi.recent_),
00067 unseen_ (mi.unseen_),
00068 uidValidity_ (mi.uidValidity_),
00069 uidNext_ (mi.uidNext_),
00070 flags_ (mi.flags_),
00071 permanentFlags_ (mi.permanentFlags_),
00072 readWrite_ (mi.readWrite_),
00073 countAvailable_ (mi.countAvailable_),
00074 recentAvailable_ (mi.recentAvailable_),
00075 unseenAvailable_ (mi.unseenAvailable_),
00076 uidValidityAvailable_ (mi.uidValidityAvailable_),
00077 uidNextAvailable_ (mi.uidNextAvailable_),
00078 flagsAvailable_ (mi.flagsAvailable_),
00079 permanentFlagsAvailable_ (mi.permanentFlagsAvailable_),
00080 readWriteAvailable_ (mi.readWriteAvailable_)
00081 {
00082 }
00083
00084 imapInfo & imapInfo::operator = (const imapInfo & mi)
00085 {
00086
00087 if (this == &mi)
00088 return *this;
00089
00090 count_ = mi.count_;
00091 recent_ = mi.recent_;
00092 unseen_ = mi.unseen_;
00093 uidValidity_ = mi.uidValidity_;
00094 uidNext_ = mi.uidNext_;
00095 flags_ = mi.flags_;
00096 permanentFlags_ = mi.permanentFlags_;
00097 readWrite_ = mi.readWrite_;
00098 countAvailable_ = mi.countAvailable_;
00099 recentAvailable_ = mi.recentAvailable_;
00100 unseenAvailable_ = mi.unseenAvailable_;
00101 uidValidityAvailable_ = mi.uidValidityAvailable_;
00102 uidNextAvailable_ = mi.uidNextAvailable_;
00103 flagsAvailable_ = mi.flagsAvailable_;
00104 permanentFlagsAvailable_ = mi.permanentFlagsAvailable_;
00105 readWriteAvailable_ = mi.readWriteAvailable_;
00106
00107 return *this;
00108 }
00109
00110 imapInfo::imapInfo (const QStringList & list):count_ (0),
00111 recent_ (0),
00112 unseen_ (0),
00113 uidValidity_ (0),
00114 uidNext_ (0),
00115 flags_ (0),
00116 permanentFlags_ (0),
00117 readWrite_ (false),
00118 countAvailable_ (false),
00119 recentAvailable_ (false),
00120 unseenAvailable_ (false),
00121 uidValidityAvailable_ (false),
00122 uidNextAvailable_ (false),
00123 flagsAvailable_ (false),
00124 permanentFlagsAvailable_ (false), readWriteAvailable_ (false)
00125 {
00126 for (QStringList::ConstIterator it (list.begin ()); it != list.end (); ++it)
00127 {
00128 QString line (*it);
00129
00130 line.truncate(line.length() - 2);
00131 QStringList tokens(QStringList::split (' ', line));
00132
00133 kdDebug(7116) << "Processing: " << line << endl;
00134 if (tokens[0] != "*")
00135 continue;
00136
00137 if (tokens[1] == "OK")
00138 {
00139 if (tokens[2] == "[UNSEEN")
00140 setUnseen (tokens[3].left (tokens[3].length () - 1).toULong ());
00141
00142 else if (tokens[2] == "[UIDVALIDITY")
00143 setUidValidity (tokens[3].left (tokens[3].length () - 1).toULong ());
00144
00145 else if (tokens[2] == "[UIDNEXT")
00146 setUidNext (tokens[3].left (tokens[3].length () - 1).toULong ());
00147
00148 else if (tokens[2] == "[PERMANENTFLAGS")
00149 {
00150 int flagsStart = line.find('(');
00151 int flagsEnd = line.find(')');
00152
00153 kdDebug(7116) << "Checking permFlags from " << flagsStart << " to " << flagsEnd << endl;
00154 if ((-1 != flagsStart) && (-1 != flagsEnd) && flagsStart < flagsEnd)
00155 setPermanentFlags (_flags (line.mid (flagsStart, flagsEnd).latin1()));
00156
00157 }
00158 else if (tokens[2] == "[READ-WRITE")
00159 {
00160 setReadWrite (true);
00161 }
00162 else if (tokens[2] == "[READ-ONLY")
00163 {
00164 setReadWrite (false);
00165 }
00166 else
00167 {
00168 kdDebug(7116) << "unknown token2: " << tokens[2] << endl;
00169 }
00170 }
00171 else if (tokens[1] == "FLAGS")
00172 {
00173 int flagsStart = line.find ('(');
00174 int flagsEnd = line.find (')');
00175
00176 if ((-1 != flagsStart) && (-1 != flagsEnd) && flagsStart < flagsEnd)
00177 setFlags (_flags (line.mid (flagsStart, flagsEnd).latin1() ));
00178 }
00179 else
00180 {
00181 if (tokens[2] == "EXISTS")
00182 setCount (tokens[1].toULong ());
00183
00184 else if (tokens[2] == "RECENT")
00185 setRecent (tokens[1].toULong ());
00186
00187 else
00188 kdDebug(7116) << "unknown token1/2: " << tokens[1] << " " << tokens[2] << endl;
00189 }
00190 }
00191
00192 }
00193
00194 ulong imapInfo::_flags (const QCString & inFlags)
00195 {
00196 ulong flags = 0;
00197 parseString flagsString;
00198 flagsString.data.duplicate(inFlags.data(), inFlags.length());
00199
00200 if (flagsString[0] == '(')
00201 flagsString.pos++;
00202
00203 while (!flagsString.isEmpty () && flagsString[0] != ')')
00204 {
00205 QCString entry = imapParser::parseOneWordC(flagsString).upper();
00206
00207 if (entry.isEmpty ())
00208 flagsString.clear();
00209 else if (0 != entry.contains ("\\SEEN"))
00210 flags ^= Seen;
00211 else if (0 != entry.contains ("\\ANSWERED"))
00212 flags ^= Answered;
00213 else if (0 != entry.contains ("\\FLAGGED"))
00214 flags ^= Flagged;
00215 else if (0 != entry.contains ("\\DELETED"))
00216 flags ^= Deleted;
00217 else if (0 != entry.contains ("\\DRAFT"))
00218 flags ^= Draft;
00219 else if (0 != entry.contains ("\\RECENT"))
00220 flags ^= Recent;
00221 else if (0 != entry.contains ("\\*"))
00222 flags ^= User;
00223
00224
00225 else if ( entry.contains( "KMAILFORWARDED" ) || entry.contains( "$FORWARDED" ) )
00226 flags = flags | Forwarded;
00227 else if ( entry.contains( "KMAILTODO" ) || entry.contains( "$TODO" ) )
00228 flags = flags | Todo;
00229 else if ( entry.contains( "KMAILWATCHED" ) || entry.contains( "$WATCHED" ) )
00230 flags = flags | Watched;
00231 else if ( entry.contains( "KMAILIGNORED" ) || entry.contains( "$IGNORED" ) )
00232 flags = flags | Ignored;
00233 }
00234
00235 return flags;
00236 }