00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "imapcommand.h"
00025 #include "rfcdecoder.h"
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 imapCommand::imapCommand ()
00059 {
00060 mComplete = false;
00061 mId = QString::null;
00062 }
00063
00064 imapCommand::imapCommand (const QString & command, const QString & parameter)
00065
00066
00067
00068 {
00069 mComplete = false;
00070 aCommand = command;
00071 aParameter = parameter;
00072 mId = QString::null;
00073 }
00074
00075 bool
00076 imapCommand::isComplete ()
00077 {
00078 return mComplete;
00079 }
00080
00081 const QString &
00082 imapCommand::result ()
00083 {
00084 return mResult;
00085 }
00086
00087 const QString &
00088 imapCommand::resultInfo ()
00089 {
00090 return mResultInfo;
00091 }
00092
00093 const QString &
00094 imapCommand::id ()
00095 {
00096 return mId;
00097 }
00098
00099 const QString &
00100 imapCommand::parameter ()
00101 {
00102 return aParameter;
00103 }
00104
00105 const QString &
00106 imapCommand::command ()
00107 {
00108 return aCommand;
00109 }
00110
00111 void
00112 imapCommand::setId (const QString & id)
00113 {
00114 if (mId.isEmpty ())
00115 mId = id;
00116 }
00117
00118 void
00119 imapCommand::setComplete ()
00120 {
00121 mComplete = true;
00122 }
00123
00124 void
00125 imapCommand::setResult (const QString & result)
00126 {
00127 mResult = result;
00128 }
00129
00130 void
00131 imapCommand::setResultInfo (const QString & result)
00132 {
00133 mResultInfo = result;
00134 }
00135
00136 void
00137 imapCommand::setCommand (const QString & command)
00138 {
00139 aCommand = command;
00140 }
00141
00142 void
00143 imapCommand::setParameter (const QString & parameter)
00144 {
00145 aParameter = parameter;
00146 }
00147
00148 const QString
00149 imapCommand::getStr ()
00150 {
00151 if (parameter().isEmpty())
00152 return id() + " " + command() + "\r\n";
00153 else
00154 return id() + " " + command() + " " + parameter() + "\r\n";
00155 }
00156
00157 imapCommand *
00158 imapCommand::clientNoop ()
00159 {
00160 return new imapCommand ("NOOP", "");
00161 }
00162
00163 imapCommand *
00164 imapCommand::clientFetch (ulong uid, const QString & fields, bool nouid)
00165 {
00166 return clientFetch (uid, uid, fields, nouid);
00167 }
00168
00169 imapCommand *
00170 imapCommand::clientFetch (ulong fromUid, ulong toUid, const QString & fields,
00171 bool nouid)
00172 {
00173 QString uid = QString::number(fromUid);
00174
00175 if (fromUid != toUid)
00176 {
00177 uid += ":";
00178 if (toUid < fromUid)
00179 uid += "*";
00180 else
00181 uid += QString::number(toUid);
00182 }
00183 return clientFetch (uid, fields, nouid);
00184 }
00185
00186 imapCommand *
00187 imapCommand::clientFetch (const QString & sequence, const QString & fields,
00188 bool nouid)
00189 {
00190 return new imapCommand (nouid ? "FETCH" : "UID FETCH",
00191 sequence + " (" + fields + ")");
00192 }
00193
00194 imapCommand *
00195 imapCommand::clientList (const QString & reference, const QString & path,
00196 bool lsub)
00197 {
00198 return new imapCommand (lsub ? "LSUB" : "LIST",
00199 QString ("\"") + rfcDecoder::toIMAP (reference) +
00200 "\" \"" + rfcDecoder::toIMAP (path) + "\"");
00201 }
00202
00203 imapCommand *
00204 imapCommand::clientSelect (const QString & path, bool examine)
00205 {
00206 Q_UNUSED(examine);
00210 return new imapCommand ("SELECT",
00211 QString ("\"") + rfcDecoder::toIMAP (path) + "\"");
00212 }
00213
00214 imapCommand *
00215 imapCommand::clientClose()
00216 {
00217 return new imapCommand("CLOSE", "");
00218 }
00219
00220 imapCommand *
00221 imapCommand::clientCopy (const QString & box, const QString & sequence,
00222 bool nouid)
00223 {
00224 return new imapCommand (nouid ? "COPY" : "UID COPY",
00225 sequence + " \"" + rfcDecoder::toIMAP (box) + "\"");
00226 }
00227
00228 imapCommand *
00229 imapCommand::clientAppend (const QString & box, const QString & flags,
00230 ulong size)
00231 {
00232 return new imapCommand ("APPEND",
00233 "\"" + rfcDecoder::toIMAP (box) + "\" " +
00234 ((flags.isEmpty()) ? "" : ("(" + flags + ") ")) +
00235 "{" + QString::number(size) + "}");
00236 }
00237
00238 imapCommand *
00239 imapCommand::clientStatus (const QString & path, const QString & parameters)
00240 {
00241 return new imapCommand ("STATUS",
00242 QString ("\"") + rfcDecoder::toIMAP (path) +
00243 "\" (" + parameters + ")");
00244 }
00245
00246 imapCommand *
00247 imapCommand::clientCreate (const QString & path)
00248 {
00249 return new imapCommand ("CREATE",
00250 QString ("\"") + rfcDecoder::toIMAP (path) + "\"");
00251 }
00252
00253 imapCommand *
00254 imapCommand::clientDelete (const QString & path)
00255 {
00256 return new imapCommand ("DELETE",
00257 QString ("\"") + rfcDecoder::toIMAP (path) + "\"");
00258 }
00259
00260 imapCommand *
00261 imapCommand::clientSubscribe (const QString & path)
00262 {
00263 return new imapCommand ("SUBSCRIBE",
00264 QString ("\"") + rfcDecoder::toIMAP (path) + "\"");
00265 }
00266
00267 imapCommand *
00268 imapCommand::clientUnsubscribe (const QString & path)
00269 {
00270 return new imapCommand ("UNSUBSCRIBE",
00271 QString ("\"") + rfcDecoder::toIMAP (path) + "\"");
00272 }
00273
00274 imapCommand *
00275 imapCommand::clientExpunge ()
00276 {
00277 return new imapCommand ("EXPUNGE", QString (""));
00278 }
00279
00280 imapCommand *
00281 imapCommand::clientRename (const QString & src, const QString & dest)
00282 {
00283 return new imapCommand ("RENAME",
00284 QString ("\"") + rfcDecoder::toIMAP (src) +
00285 "\" \"" + rfcDecoder::toIMAP (dest) + "\"");
00286 }
00287
00288 imapCommand *
00289 imapCommand::clientSearch (const QString & search, bool nouid)
00290 {
00291 return new imapCommand (nouid ? "SEARCH" : "UID SEARCH", search);
00292 }
00293
00294 imapCommand *
00295 imapCommand::clientStore (const QString & set, const QString & item,
00296 const QString & data, bool nouid)
00297 {
00298 return new imapCommand (nouid ? "STORE" : "UID STORE",
00299 set + " " + item + " (" + data + ")");
00300 }
00301
00302 imapCommand *
00303 imapCommand::clientLogout ()
00304 {
00305 return new imapCommand ("LOGOUT", "");
00306 }
00307
00308 imapCommand *
00309 imapCommand::clientStartTLS ()
00310 {
00311 return new imapCommand ("STARTTLS", "");
00312 }
00313
00314 imapCommand *
00315 imapCommand::clientSetACL( const QString& box, const QString& user, const QString& acl )
00316 {
00317 return new imapCommand ("SETACL", QString("\"") + rfcDecoder::toIMAP (box)
00318 + "\" \"" + rfcDecoder::toIMAP (user)
00319 + "\" \"" + rfcDecoder::toIMAP (acl) + "\"");
00320 }
00321
00322 imapCommand *
00323 imapCommand::clientDeleteACL( const QString& box, const QString& user )
00324 {
00325 return new imapCommand ("DELETEACL", QString("\"") + rfcDecoder::toIMAP (box)
00326 + "\" \"" + rfcDecoder::toIMAP (user)
00327 + "\"");
00328 }
00329
00330 imapCommand *
00331 imapCommand::clientGetACL( const QString& box )
00332 {
00333 return new imapCommand ("GETACL", QString("\"") + rfcDecoder::toIMAP (box)
00334 + "\"");
00335 }
00336
00337 imapCommand *
00338 imapCommand::clientListRights( const QString& box, const QString& user )
00339 {
00340 return new imapCommand ("LISTRIGHTS", QString("\"") + rfcDecoder::toIMAP (box)
00341 + "\" \"" + rfcDecoder::toIMAP (user)
00342 + "\"");
00343 }
00344
00345 imapCommand *
00346 imapCommand::clientMyRights( const QString& box )
00347 {
00348 return new imapCommand ("MYRIGHTS", QString("\"") + rfcDecoder::toIMAP (box)
00349 + "\"");
00350 }
00351
00352 imapCommand *
00353 imapCommand::clientSetAnnotation( const QString& box, const QString& entry, const QMap<QString, QString>& attributes )
00354 {
00355 QString parameter = QString("\"") + rfcDecoder::toIMAP (box)
00356 + "\" \"" + rfcDecoder::toIMAP (entry)
00357 + "\" (";
00358 for( QMap<QString,QString>::ConstIterator it = attributes.begin(); it != attributes.end(); ++it ) {
00359 parameter += "\"";
00360 parameter += rfcDecoder::toIMAP (it.key());
00361 parameter += "\" \"";
00362 parameter += rfcDecoder::toIMAP (it.data());
00363 parameter += "\" ";
00364 }
00365
00366 parameter[parameter.length()-1] = ')';
00367
00368 return new imapCommand ("SETANNOTATION", parameter);
00369 }
00370
00371 imapCommand *
00372 imapCommand::clientGetAnnotation( const QString& box, const QString& entry, const QStringList& attributeNames )
00373 {
00374 QString parameter = QString("\"") + rfcDecoder::toIMAP (box)
00375 + "\" \"" + rfcDecoder::toIMAP (entry)
00376 + "\" ";
00377 if ( attributeNames.count() == 1 )
00378 parameter += "\"" + rfcDecoder::toIMAP (attributeNames.first()) + '"';
00379 else {
00380 parameter += '(';
00381 for( QStringList::ConstIterator it = attributeNames.begin(); it != attributeNames.end(); ++it ) {
00382 parameter += "\"" + rfcDecoder::toIMAP (*it) + "\" ";
00383 }
00384
00385 parameter[parameter.length()-1] = ')';
00386 }
00387 return new imapCommand ("GETANNOTATION", parameter);
00388 }
00389
00390 imapCommand *
00391 imapCommand::clientNamespace()
00392 {
00393 return new imapCommand("NAMESPACE", "");
00394 }
00395
00396 imapCommand *
00397 imapCommand::clientGetQuotaroot( const QString& box )
00398 {
00399 QString parameter = QString("\"") + rfcDecoder::toIMAP (box) + '"';
00400 return new imapCommand ("GETQUOTAROOT", parameter);
00401 }
00402
00403 imapCommand *
00404 imapCommand::clientCustom( const QString& command, const QString& arguments )
00405 {
00406 return new imapCommand (command, arguments);
00407 }
00408