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

kioslave/imap4

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

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.6.1
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