• Skip to content
  • Skip to link menu
KDE 4.7 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • KDE Home
  • Contact Us
 

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 = QString(flags.isEmpty() ? QString("") : QString(('(' + flags + ") ")) + '{' + QString::number(size) + '}'); 
00235   return CommandPtr( new imapCommand ("APPEND",
00236                           "\"" + KIMAP::encodeImapFolderName (box) + "\" " + tmp));
00237 }
00238 
00239 CommandPtr
00240 imapCommand::clientStatus (const QString & path, const QString & parameters)
00241 {
00242   return CommandPtr( new imapCommand ("STATUS",
00243                           QString ("\"") + KIMAP::encodeImapFolderName (path) +
00244                           "\" (" + parameters + ")") );
00245 }
00246 
00247 CommandPtr
00248 imapCommand::clientCreate (const QString & path)
00249 {
00250   return CommandPtr( new imapCommand ("CREATE",
00251                           QString ("\"") + KIMAP::encodeImapFolderName (path) + "\"") );
00252 }
00253 
00254 CommandPtr
00255 imapCommand::clientDelete (const QString & path)
00256 {
00257   return CommandPtr( new imapCommand ("DELETE",
00258                           QString ("\"") + KIMAP::encodeImapFolderName (path) + "\"") );
00259 }
00260 
00261 CommandPtr
00262 imapCommand::clientSubscribe (const QString & path)
00263 {
00264   return CommandPtr( new imapCommand ("SUBSCRIBE",
00265                           QString ("\"") + KIMAP::encodeImapFolderName (path) + "\"") );
00266 }
00267 
00268 CommandPtr
00269 imapCommand::clientUnsubscribe (const QString & path)
00270 {
00271   return CommandPtr(  new imapCommand ("UNSUBSCRIBE",
00272                           QString ("\"") + KIMAP::encodeImapFolderName (path) + "\"") );
00273 }
00274 
00275 CommandPtr
00276 imapCommand::clientExpunge ()
00277 {
00278   return CommandPtr( new imapCommand ("EXPUNGE", QString ("")) );
00279 }
00280 
00281 CommandPtr
00282 imapCommand::clientRename (const QString & src, const QString & dest)
00283 {
00284   return CommandPtr( new imapCommand ("RENAME",
00285                           QString ("\"") + KIMAP::encodeImapFolderName (src) +
00286                           "\" \"" + KIMAP::encodeImapFolderName (dest) + "\"") );
00287 }
00288 
00289 CommandPtr
00290 imapCommand::clientSearch (const QString & search, bool nouid)
00291 {
00292   return CommandPtr( new imapCommand (nouid ? "SEARCH" : "UID SEARCH", search) );
00293 }
00294 
00295 CommandPtr
00296 imapCommand::clientStore (const QString & set, const QString & item,
00297                           const QString & data, bool nouid)
00298 {
00299   return CommandPtr( new imapCommand (nouid ? "STORE" : "UID STORE",
00300                           set + ' ' + item + " (" + data + ')') );
00301 }
00302 
00303 CommandPtr
00304 imapCommand::clientLogout ()
00305 {
00306   return CommandPtr( new imapCommand ("LOGOUT", "") );
00307 }
00308 
00309 CommandPtr
00310 imapCommand::clientStartTLS ()
00311 {
00312   return CommandPtr( new imapCommand ("STARTTLS", "") );
00313 }
00314 
00315 CommandPtr
00316 imapCommand::clientSetACL( const QString& box, const QString& user, const QString& acl )
00317 {
00318   return CommandPtr( new imapCommand ("SETACL", QString("\"") + KIMAP::encodeImapFolderName (box)
00319                           + "\" \"" + KIMAP::encodeImapFolderName (user)
00320                           + "\" \"" + KIMAP::encodeImapFolderName (acl) + "\"") );
00321 }
00322 
00323 CommandPtr
00324 imapCommand::clientDeleteACL( const QString& box, const QString& user )
00325 {
00326   return CommandPtr( new imapCommand ("DELETEACL", QString("\"") + KIMAP::encodeImapFolderName (box)
00327                           + "\" \"" + KIMAP::encodeImapFolderName (user)
00328                           + "\"") );
00329 }
00330 
00331 CommandPtr
00332 imapCommand::clientGetACL( const QString& box )
00333 {
00334   return CommandPtr( new imapCommand ("GETACL", QString("\"") + KIMAP::encodeImapFolderName (box)
00335                           + "\"") );
00336 }
00337 
00338 CommandPtr
00339 imapCommand::clientListRights( const QString& box, const QString& user )
00340 {
00341   return CommandPtr( new imapCommand ("LISTRIGHTS", QString("\"") + KIMAP::encodeImapFolderName (box)
00342                           + "\" \"" + KIMAP::encodeImapFolderName (user)
00343                           + "\"") );
00344 }
00345 
00346 CommandPtr
00347 imapCommand::clientMyRights( const QString& box )
00348 {
00349   return CommandPtr( new imapCommand ("MYRIGHTS", QString("\"") + KIMAP::encodeImapFolderName (box)
00350                           + "\"") );
00351 }
00352 
00353 CommandPtr
00354 imapCommand::clientSetAnnotation( const QString& box, const QString& entry, const QMap<QString, QString>& attributes )
00355 {
00356   QString parameter = QString("\"") + KIMAP::encodeImapFolderName (box)
00357                       + "\" \"" + KIMAP::encodeImapFolderName (entry)
00358                       + "\" (";
00359   for( QMap<QString,QString>::ConstIterator it = attributes.begin(); it != attributes.end(); ++it ) {
00360     parameter += "\"";
00361     parameter += KIMAP::encodeImapFolderName (it.key());
00362     parameter += "\" \"";
00363     parameter += KIMAP::encodeImapFolderName (it.value());
00364     parameter += "\" ";
00365   }
00366   // Turn last space into a ')'
00367   parameter[parameter.length()-1] = ')';
00368 
00369   return CommandPtr( new imapCommand ("SETANNOTATION", parameter) );
00370 }
00371 
00372 CommandPtr
00373 imapCommand::clientGetAnnotation( const QString& box, const QString& entry, const QStringList& attributeNames )
00374 {
00375   QString parameter = QString("\"") + KIMAP::encodeImapFolderName (box)
00376                           + "\" \"" + KIMAP::encodeImapFolderName (entry)
00377                           + "\" ";
00378   if ( attributeNames.count() == 1 )
00379     parameter += "\"" + KIMAP::encodeImapFolderName (attributeNames.first()) + '"';
00380   else {
00381     parameter += '(';
00382     for( QStringList::ConstIterator it = attributeNames.begin(); it != attributeNames.end(); ++it ) {
00383       parameter += "\"" + KIMAP::encodeImapFolderName (*it) + "\" ";
00384     }
00385     // Turn last space into a ')'
00386     parameter[parameter.length()-1] = ')';
00387   }
00388   return CommandPtr( new imapCommand ("GETANNOTATION", parameter) );
00389 }
00390 
00391 CommandPtr
00392 imapCommand::clientNamespace()
00393 {
00394   return CommandPtr( new imapCommand("NAMESPACE", "") );
00395 }
00396 
00397 CommandPtr
00398 imapCommand::clientGetQuotaroot( const QString& box )
00399 {
00400   QString parameter = QString("\"") + KIMAP::encodeImapFolderName (box) + '"';
00401   return CommandPtr( new imapCommand ("GETQUOTAROOT", parameter) );
00402 }
00403 
00404 CommandPtr
00405 imapCommand::clientCustom( const QString& command, const QString& arguments )
00406 {
00407   return CommandPtr( new imapCommand (command, arguments) );
00408 }
00409 

kioslave/imap4

Skip menu "kioslave/imap4"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.7.5
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal