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