kioslave/imap4
imapcommand.cpp
00001 /********************************************************************** 00002 * 00003 * imapcommand.cc - IMAP4rev1 command handler 00004 * Copyright (C) 2000 Sven Carstens <s.carstens@gmx.de> 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * Send comments and bug fixes to s.carstens@gmx.de 00021 * 00022 *********************************************************************/ 00023 00024 #include "imapcommand.h" 00025 #include <kimap/rfccodecs.h> 00026 00027 /*#include <stdlib.h> 00028 00029 #include <sys/types.h> 00030 #include <sys/socket.h> 00031 #include <sys/wait.h> 00032 #include <sys/stat.h> 00033 00034 #include <fcntl.h> 00035 00036 #include <netinet/in.h> 00037 #include <arpa/inet.h> 00038 00039 #include <errno.h> 00040 #include <signal.h> 00041 #include <stdio.h> 00042 #include <netdb.h> 00043 #include <unistd.h> 00044 #include <stdlib.h> 00045 00046 #include <QRegExp> 00047 #include <QBuffer> 00048 00049 #include <kprotocolmanager.h> 00050 #include <ksock.h> 00051 #include <kdebug.h> 00052 #include <kcomponentdata.h> 00053 #include <kio/connection.h> 00054 #include <kio/slaveinterface.h> 00055 #include <kio/passdlg.h> 00056 #include <klocale.h> */ 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 // aCommand(NULL), 00068 // mResult(NULL), 00069 // mParameter(NULL) 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 CommandPtr 00160 imapCommand::clientNoop () 00161 { 00162 return CommandPtr( new imapCommand ("NOOP", "") ); 00163 } 00164 00165 CommandPtr 00166 imapCommand::clientFetch (ulong uid, const QString & fields, bool nouid) 00167 { 00168 return CommandPtr( clientFetch (uid, uid, fields, nouid) ); 00169 } 00170 00171 CommandPtr 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 CommandPtr 00189 imapCommand::clientFetch (const QString & sequence, const QString & fields, 00190 bool nouid) 00191 { 00192 return CommandPtr( new imapCommand (nouid ? "FETCH" : "UID FETCH", 00193 sequence + " (" + fields + ')') ); 00194 } 00195 00196 CommandPtr 00197 imapCommand::clientList (const QString & reference, const QString & path, 00198 bool lsub) 00199 { 00200 return CommandPtr( new imapCommand (lsub ? "LSUB" : "LIST", 00201 QString ("\"") + KIMAP::encodeImapFolderName (reference) + 00202 "\" \"" + KIMAP::encodeImapFolderName (path) + "\"") ); 00203 } 00204 00205 CommandPtr 00206 imapCommand::clientSelect (const QString & path, bool examine) 00207 { 00208 Q_UNUSED(examine); 00212 return CommandPtr( new imapCommand ("SELECT", 00213 QString ("\"") + KIMAP::encodeImapFolderName (path) + "\"") ); 00214 } 00215 00216 CommandPtr 00217 imapCommand::clientClose() 00218 { 00219 return CommandPtr( new imapCommand("CLOSE", "") ); 00220 } 00221 00222 CommandPtr 00223 imapCommand::clientCopy (const QString & box, const QString & sequence, 00224 bool nouid) 00225 { 00226 return CommandPtr( new imapCommand (nouid ? "COPY" : "UID COPY", 00227 sequence + " \"" + KIMAP::encodeImapFolderName (box) + "\"") ); 00228 } 00229 00230 CommandPtr 00231 imapCommand::clientAppend (const QString & box, const QString & flags, 00232 ulong size) 00233 { 00234 QString tmp; 00235 if ( !flags.isEmpty() ) { 00236 tmp = '(' + flags + ") "; 00237 } 00238 tmp += '{' + QString::number( size ) + '}'; 00239 00240 return CommandPtr( new imapCommand ("APPEND", 00241 "\"" + KIMAP::encodeImapFolderName (box) + "\" " + tmp)); 00242 } 00243 00244 CommandPtr 00245 imapCommand::clientStatus (const QString & path, const QString & parameters) 00246 { 00247 return CommandPtr( new imapCommand ("STATUS", 00248 QString ("\"") + KIMAP::encodeImapFolderName (path) + 00249 "\" (" + parameters + ")") ); 00250 } 00251 00252 CommandPtr 00253 imapCommand::clientCreate (const QString & path) 00254 { 00255 return CommandPtr( new imapCommand ("CREATE", 00256 QString ("\"") + KIMAP::encodeImapFolderName (path) + "\"") ); 00257 } 00258 00259 CommandPtr 00260 imapCommand::clientDelete (const QString & path) 00261 { 00262 return CommandPtr( new imapCommand ("DELETE", 00263 QString ("\"") + KIMAP::encodeImapFolderName (path) + "\"") ); 00264 } 00265 00266 CommandPtr 00267 imapCommand::clientSubscribe (const QString & path) 00268 { 00269 return CommandPtr( new imapCommand ("SUBSCRIBE", 00270 QString ("\"") + KIMAP::encodeImapFolderName (path) + "\"") ); 00271 } 00272 00273 CommandPtr 00274 imapCommand::clientUnsubscribe (const QString & path) 00275 { 00276 return CommandPtr( new imapCommand ("UNSUBSCRIBE", 00277 QString ("\"") + KIMAP::encodeImapFolderName (path) + "\"") ); 00278 } 00279 00280 CommandPtr 00281 imapCommand::clientExpunge () 00282 { 00283 return CommandPtr( new imapCommand ("EXPUNGE", QString ("")) ); 00284 } 00285 00286 CommandPtr 00287 imapCommand::clientRename (const QString & src, const QString & dest) 00288 { 00289 return CommandPtr( new imapCommand ("RENAME", 00290 QString ("\"") + KIMAP::encodeImapFolderName (src) + 00291 "\" \"" + KIMAP::encodeImapFolderName (dest) + "\"") ); 00292 } 00293 00294 CommandPtr 00295 imapCommand::clientSearch (const QString & search, bool nouid) 00296 { 00297 return CommandPtr( new imapCommand (nouid ? "SEARCH" : "UID SEARCH", search) ); 00298 } 00299 00300 CommandPtr 00301 imapCommand::clientStore (const QString & set, const QString & item, 00302 const QString & data, bool nouid) 00303 { 00304 return CommandPtr( new imapCommand (nouid ? "STORE" : "UID STORE", 00305 set + ' ' + item + " (" + data + ')') ); 00306 } 00307 00308 CommandPtr 00309 imapCommand::clientLogout () 00310 { 00311 return CommandPtr( new imapCommand ("LOGOUT", "") ); 00312 } 00313 00314 CommandPtr 00315 imapCommand::clientStartTLS () 00316 { 00317 return CommandPtr( new imapCommand ("STARTTLS", "") ); 00318 } 00319 00320 CommandPtr 00321 imapCommand::clientSetACL( const QString& box, const QString& user, const QString& acl ) 00322 { 00323 return CommandPtr( new imapCommand ("SETACL", QString("\"") + KIMAP::encodeImapFolderName (box) 00324 + "\" \"" + KIMAP::encodeImapFolderName (user) 00325 + "\" \"" + KIMAP::encodeImapFolderName (acl) + "\"") ); 00326 } 00327 00328 CommandPtr 00329 imapCommand::clientDeleteACL( const QString& box, const QString& user ) 00330 { 00331 return CommandPtr( new imapCommand ("DELETEACL", QString("\"") + KIMAP::encodeImapFolderName (box) 00332 + "\" \"" + KIMAP::encodeImapFolderName (user) 00333 + "\"") ); 00334 } 00335 00336 CommandPtr 00337 imapCommand::clientGetACL( const QString& box ) 00338 { 00339 return CommandPtr( new imapCommand ("GETACL", QString("\"") + KIMAP::encodeImapFolderName (box) 00340 + "\"") ); 00341 } 00342 00343 CommandPtr 00344 imapCommand::clientListRights( const QString& box, const QString& user ) 00345 { 00346 return CommandPtr( new imapCommand ("LISTRIGHTS", QString("\"") + KIMAP::encodeImapFolderName (box) 00347 + "\" \"" + KIMAP::encodeImapFolderName (user) 00348 + "\"") ); 00349 } 00350 00351 CommandPtr 00352 imapCommand::clientMyRights( const QString& box ) 00353 { 00354 return CommandPtr( new imapCommand ("MYRIGHTS", QString("\"") + KIMAP::encodeImapFolderName (box) 00355 + "\"") ); 00356 } 00357 00358 CommandPtr 00359 imapCommand::clientSetAnnotation( const QString& box, const QString& entry, const QMap<QString, QString>& attributes ) 00360 { 00361 QString parameter = QString("\"") + KIMAP::encodeImapFolderName (box) 00362 + "\" \"" + KIMAP::encodeImapFolderName (entry) 00363 + "\" ("; 00364 for( QMap<QString,QString>::ConstIterator it = attributes.begin(); it != attributes.end(); ++it ) { 00365 parameter += "\""; 00366 parameter += KIMAP::encodeImapFolderName (it.key()); 00367 parameter += "\" \""; 00368 parameter += KIMAP::encodeImapFolderName (it.value()); 00369 parameter += "\" "; 00370 } 00371 // Turn last space into a ')' 00372 parameter[parameter.length()-1] = ')'; 00373 00374 return CommandPtr( new imapCommand ("SETANNOTATION", parameter) ); 00375 } 00376 00377 CommandPtr 00378 imapCommand::clientGetAnnotation( const QString& box, const QString& entry, const QStringList& attributeNames ) 00379 { 00380 QString parameter = QString("\"") + KIMAP::encodeImapFolderName (box) 00381 + "\" \"" + KIMAP::encodeImapFolderName (entry) 00382 + "\" "; 00383 if ( attributeNames.count() == 1 ) 00384 parameter += "\"" + KIMAP::encodeImapFolderName (attributeNames.first()) + '"'; 00385 else { 00386 parameter += '('; 00387 for( QStringList::ConstIterator it = attributeNames.begin(); it != attributeNames.end(); ++it ) { 00388 parameter += "\"" + KIMAP::encodeImapFolderName (*it) + "\" "; 00389 } 00390 // Turn last space into a ')' 00391 parameter[parameter.length()-1] = ')'; 00392 } 00393 return CommandPtr( new imapCommand ("GETANNOTATION", parameter) ); 00394 } 00395 00396 CommandPtr 00397 imapCommand::clientNamespace() 00398 { 00399 return CommandPtr( new imapCommand("NAMESPACE", "") ); 00400 } 00401 00402 CommandPtr 00403 imapCommand::clientGetQuotaroot( const QString& box ) 00404 { 00405 QString parameter = QString("\"") + KIMAP::encodeImapFolderName (box) + '"'; 00406 return CommandPtr( new imapCommand ("GETQUOTAROOT", parameter) ); 00407 } 00408 00409 CommandPtr 00410 imapCommand::clientCustom( const QString& command, const QString& arguments ) 00411 { 00412 return CommandPtr( new imapCommand (command, arguments) ); 00413 } 00414
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 14 2012 04:40:33 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 14 2012 04:40:33 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.