• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

kioslave/imap4

  • sources
  • kde-4.14
  • kdepimlibs
  • kioslave
  • imap4
imapcommand.cpp
1 /**********************************************************************
2  *
3  * imapcommand.cc - IMAP4rev1 command handler
4  * Copyright (C) 2000 Sven Carstens <s.carstens@gmx.de>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * Send comments and bug fixes to s.carstens@gmx.de
21  *
22  *********************************************************************/
23 
24 #include "imapcommand.h"
25 #include <kimap/rfccodecs.h>
26 
27 /*#include <stdlib.h>
28 
29 #include <sys/types.h>
30 #include <sys/socket.h>
31 #include <sys/wait.h>
32 #include <sys/stat.h>
33 
34 #include <fcntl.h>
35 
36 #include <netinet/in.h>
37 #include <arpa/inet.h>
38 
39 #include <errno.h>
40 #include <signal.h>
41 #include <stdio.h>
42 #include <netdb.h>
43 #include <unistd.h>
44 #include <stdlib.h>
45 
46 #include <QRegExp>
47 #include <QBuffer>
48 
49 #include <kprotocolmanager.h>
50 #include <ksock.h>
51 #include <kdebug.h>
52 #include <kcomponentdata.h>
53 #include <kio/connection.h>
54 #include <kio/slaveinterface.h>
55 #include <kio/passdlg.h>
56 #include <klocalizedstring.h> */
57 
58 using namespace KIMAP;
59 
60 imapCommand::imapCommand ()
61 {
62  mComplete = false;
63  mId.clear();
64 }
65 
66 imapCommand::imapCommand (const QString & command, const QString & parameter)
67 // aCommand(NULL),
68 // mResult(NULL),
69 // mParameter(NULL)
70 {
71  mComplete = false;
72  aCommand = command;
73  aParameter = parameter;
74  mId.clear();
75 }
76 
77 bool
78 imapCommand::isComplete ()
79 {
80  return mComplete;
81 }
82 
83 const QString &
84 imapCommand::result ()
85 {
86  return mResult;
87 }
88 
89 const QString &
90 imapCommand::resultInfo ()
91 {
92  return mResultInfo;
93 }
94 
95 const QString &
96 imapCommand::id ()
97 {
98  return mId;
99 }
100 
101 const QString &
102 imapCommand::parameter ()
103 {
104  return aParameter;
105 }
106 
107 const QString &
108 imapCommand::command ()
109 {
110  return aCommand;
111 }
112 
113 void
114 imapCommand::setId (const QString & id)
115 {
116  if ( mId.isEmpty() ) {
117  mId = id;
118  }
119 }
120 
121 void
122 imapCommand::setComplete ()
123 {
124  mComplete = true;
125 }
126 
127 void
128 imapCommand::setResult (const QString & result)
129 {
130  mResult = result;
131 }
132 
133 void
134 imapCommand::setResultInfo (const QString & result)
135 {
136  mResultInfo = result;
137 }
138 
139 void
140 imapCommand::setCommand (const QString & command)
141 {
142  aCommand = command;
143 }
144 
145 void
146 imapCommand::setParameter (const QString & parameter)
147 {
148  aParameter = parameter;
149 }
150 
151 const QString
152 imapCommand::getStr ()
153 {
154  if ( parameter().isEmpty() ) {
155  return id() + ' ' + command() + "\r\n";
156  } else {
157  return id() + ' ' + command() + ' ' + parameter() + "\r\n";
158  }
159 }
160 
161 CommandPtr
162 imapCommand::clientNoop ()
163 {
164  return CommandPtr( new imapCommand( "NOOP", "" ) );
165 }
166 
167 CommandPtr
168 imapCommand::clientFetch (ulong uid, const QString & fields, bool nouid)
169 {
170  return CommandPtr( clientFetch( uid, uid, fields, nouid ) );
171 }
172 
173 CommandPtr
174 imapCommand::clientFetch (ulong fromUid, ulong toUid, const QString & fields,
175  bool nouid)
176 {
177  QString uid = QString::number( fromUid );
178 
179  if ( fromUid != toUid ) {
180  uid += ':';
181  if ( toUid < fromUid ) {
182  uid += '*';
183  } else {
184  uid += QString::number( toUid );
185  }
186  }
187  return clientFetch( uid, fields, nouid );
188 }
189 
190 CommandPtr
191 imapCommand::clientFetch (const QString & sequence, const QString & fields,
192  bool nouid)
193 {
194  return CommandPtr( new imapCommand( nouid ? "FETCH" : "UID FETCH",
195  sequence + " (" + fields + ')' ) );
196 }
197 
198 CommandPtr
199 imapCommand::clientList (const QString & reference, const QString & path,
200  bool lsub)
201 {
202  return CommandPtr( new imapCommand( lsub ? "LSUB" : "LIST",
203  QString( "\"" ) + KIMAP::encodeImapFolderName( reference ) +
204  "\" \"" + KIMAP::encodeImapFolderName( path ) + "\"" ) );
205 }
206 
207 CommandPtr
208 imapCommand::clientSelect (const QString & path, bool examine)
209 {
210  Q_UNUSED( examine );
214  return CommandPtr( new imapCommand( "SELECT",
215  QString( "\"" ) + KIMAP::encodeImapFolderName( path ) + "\"" ) );
216 }
217 
218 CommandPtr
219 imapCommand::clientClose()
220 {
221  return CommandPtr( new imapCommand( "CLOSE", "" ) );
222 }
223 
224 CommandPtr
225 imapCommand::clientCopy (const QString & box, const QString & sequence,
226  bool nouid)
227 {
228  return CommandPtr( new imapCommand( nouid ? "COPY" : "UID COPY",
229  sequence + " \"" + KIMAP::encodeImapFolderName( box ) + "\"" ) );
230 }
231 
232 CommandPtr
233 imapCommand::clientAppend (const QString & box, const QString & flags,
234  ulong size)
235 {
236  QString tmp;
237  if ( !flags.isEmpty() ) {
238  tmp = '(' + flags + ") ";
239  }
240  tmp += '{' + QString::number( size ) + '}';
241 
242  return CommandPtr( new imapCommand( "APPEND",
243  "\"" + KIMAP::encodeImapFolderName( box ) + "\" " + tmp ) );
244 }
245 
246 CommandPtr
247 imapCommand::clientStatus (const QString & path, const QString & parameters)
248 {
249  return CommandPtr( new imapCommand( "STATUS",
250  QString( "\"" ) + KIMAP::encodeImapFolderName( path ) +
251  "\" (" + parameters + ")" ) );
252 }
253 
254 CommandPtr
255 imapCommand::clientCreate (const QString & path)
256 {
257  return CommandPtr( new imapCommand( "CREATE",
258  QString( "\"" ) + KIMAP::encodeImapFolderName( path ) + "\"" ) );
259 }
260 
261 CommandPtr
262 imapCommand::clientDelete (const QString & path)
263 {
264  return CommandPtr( new imapCommand( "DELETE",
265  QString( "\"" ) + KIMAP::encodeImapFolderName( path ) + "\"" ) );
266 }
267 
268 CommandPtr
269 imapCommand::clientSubscribe (const QString & path)
270 {
271  return CommandPtr( new imapCommand( "SUBSCRIBE",
272  QString( "\"" ) + KIMAP::encodeImapFolderName( path ) + "\"" ) );
273 }
274 
275 CommandPtr
276 imapCommand::clientUnsubscribe (const QString & path)
277 {
278  return CommandPtr( new imapCommand( "UNSUBSCRIBE",
279  QString( "\"" ) + KIMAP::encodeImapFolderName( path ) + "\"" ) );
280 }
281 
282 CommandPtr
283 imapCommand::clientExpunge ()
284 {
285  return CommandPtr( new imapCommand( "EXPUNGE", QString( "" ) ) );
286 }
287 
288 CommandPtr
289 imapCommand::clientRename (const QString & src, const QString & dest)
290 {
291  return CommandPtr( new imapCommand( "RENAME",
292  QString( "\"" ) + KIMAP::encodeImapFolderName( src ) +
293  "\" \"" + KIMAP::encodeImapFolderName( dest ) + "\"" ) );
294 }
295 
296 CommandPtr
297 imapCommand::clientSearch (const QString & search, bool nouid)
298 {
299  return CommandPtr( new imapCommand( nouid ? "SEARCH" : "UID SEARCH", search ) );
300 }
301 
302 CommandPtr
303 imapCommand::clientStore (const QString & set, const QString & item,
304  const QString & data, bool nouid)
305 {
306  return CommandPtr( new imapCommand( nouid ? "STORE" : "UID STORE",
307  set + ' ' + item + " (" + data + ')' ) );
308 }
309 
310 CommandPtr
311 imapCommand::clientLogout ()
312 {
313  return CommandPtr( new imapCommand( "LOGOUT", "" ) );
314 }
315 
316 CommandPtr
317 imapCommand::clientStartTLS ()
318 {
319  return CommandPtr( new imapCommand( "STARTTLS", "" ) );
320 }
321 
322 CommandPtr
323 imapCommand::clientSetACL( const QString& box, const QString& user, const QString& acl )
324 {
325  return CommandPtr( new imapCommand( "SETACL", QString( "\"" ) + KIMAP::encodeImapFolderName( box )
326  + "\" \"" + KIMAP::encodeImapFolderName( user )
327  + "\" \"" + KIMAP::encodeImapFolderName( acl ) + "\"" ) );
328 }
329 
330 CommandPtr
331 imapCommand::clientDeleteACL( const QString& box, const QString& user )
332 {
333  return CommandPtr( new imapCommand( "DELETEACL", QString( "\"" ) + KIMAP::encodeImapFolderName( box )
334  + "\" \"" + KIMAP::encodeImapFolderName( user )
335  + "\"" ) );
336 }
337 
338 CommandPtr
339 imapCommand::clientGetACL( const QString& box )
340 {
341  return CommandPtr( new imapCommand( "GETACL", QString( "\"" ) + KIMAP::encodeImapFolderName( box )
342  + "\"" ) );
343 }
344 
345 CommandPtr
346 imapCommand::clientListRights( const QString& box, const QString& user )
347 {
348  return CommandPtr( new imapCommand( "LISTRIGHTS", QString( "\"" ) + KIMAP::encodeImapFolderName( box )
349  + "\" \"" + KIMAP::encodeImapFolderName( user )
350  + "\"" ) );
351 }
352 
353 CommandPtr
354 imapCommand::clientMyRights( const QString& box )
355 {
356  return CommandPtr( new imapCommand( "MYRIGHTS", QString( "\"" ) + KIMAP::encodeImapFolderName( box )
357  + "\"" ) );
358 }
359 
360 CommandPtr
361 imapCommand::clientSetAnnotation( const QString& box, const QString& entry, const QMap<QString, QString>& attributes )
362 {
363  QString parameter = QString( "\"" ) + KIMAP::encodeImapFolderName( box )
364  + "\" \"" + KIMAP::encodeImapFolderName( entry )
365  + "\" (";
366  for ( QMap<QString, QString>::ConstIterator it = attributes.begin(); it != attributes.end(); ++it ) {
367  parameter += "\"";
368  parameter += KIMAP::encodeImapFolderName( it.key() );
369  parameter += "\" \"";
370  parameter += KIMAP::encodeImapFolderName( it.value() );
371  parameter += "\" ";
372  }
373  // Turn last space into a ')'
374  parameter[parameter.length() - 1] = ')';
375 
376  return CommandPtr( new imapCommand( "SETANNOTATION", parameter ) );
377 }
378 
379 CommandPtr
380 imapCommand::clientGetAnnotation( const QString& box, const QString& entry, const QStringList& attributeNames )
381 {
382  QString parameter = QString( "\"" ) + KIMAP::encodeImapFolderName( box )
383  + "\" \"" + KIMAP::encodeImapFolderName( entry )
384  + "\" ";
385  if ( attributeNames.count() == 1 ) {
386  parameter += "\"" + KIMAP::encodeImapFolderName( attributeNames.first() ) + '"';
387  } else {
388  parameter += '(';
389  for ( QStringList::ConstIterator it = attributeNames.begin(); it != attributeNames.end(); ++it ) {
390  parameter += "\"" + KIMAP::encodeImapFolderName( *it ) + "\" ";
391  }
392  // Turn last space into a ')'
393  parameter[parameter.length() - 1] = ')';
394  }
395  return CommandPtr( new imapCommand( "GETANNOTATION", parameter ) );
396 }
397 
398 CommandPtr
399 imapCommand::clientNamespace()
400 {
401  return CommandPtr( new imapCommand( "NAMESPACE", "" ) );
402 }
403 
404 CommandPtr
405 imapCommand::clientGetQuotaroot( const QString& box )
406 {
407  QString parameter = QString( "\"" ) + KIMAP::encodeImapFolderName( box ) + '"';
408  return CommandPtr( new imapCommand( "GETQUOTAROOT", parameter ) );
409 }
410 
411 CommandPtr
412 imapCommand::clientCustom( const QString& command, const QString& arguments )
413 {
414  return CommandPtr( new imapCommand( command, arguments ) );
415 }
QMap< QString, QString >
imapCommand::clientGetQuotaroot
static CommandPtr clientGetQuotaroot(const QString &box)
Create a GETQUOTAROOT command.
Definition: imapcommand.cpp:405
imapCommand::setCommand
void setCommand(const QString &)
set the command
Definition: imapcommand.cpp:140
imapCommand::clientUnsubscribe
static CommandPtr clientUnsubscribe(const QString &path)
Create a UNSUBSCRIBE command.
Definition: imapcommand.cpp:276
imapCommand::clientList
static CommandPtr clientList(const QString &reference, const QString &path, bool lsub=false)
Create a LIST command.
Definition: imapcommand.cpp:199
imapCommand::clientRename
static CommandPtr clientRename(const QString &src, const QString &dest)
Create a RENAME command.
Definition: imapcommand.cpp:289
imapCommand::imapCommand
imapCommand()
Constructor.
Definition: imapcommand.cpp:60
imapCommand::isComplete
bool isComplete()
is it complete?
Definition: imapcommand.cpp:78
imapCommand::command
const QString & command()
get the command
Definition: imapcommand.cpp:108
imapCommand::getStr
const QString getStr()
returns the data to send to the server The function returns the complete data to be sent to the serve...
Definition: imapcommand.cpp:152
imapCommand::clientDelete
static CommandPtr clientDelete(const QString &path)
Create a DELETE command.
Definition: imapcommand.cpp:262
imapCommand::setParameter
void setParameter(const QString &)
set the command parameter(s)
Definition: imapcommand.cpp:146
imapCommand::clientSetACL
static CommandPtr clientSetACL(const QString &box, const QString &user, const QString &acl)
Create a SETACL command.
Definition: imapcommand.cpp:323
imapCommand::clientNamespace
static CommandPtr clientNamespace()
Create a NAMESPACE command.
Definition: imapcommand.cpp:399
QString::clear
void clear()
imapCommand::clientListRights
static CommandPtr clientListRights(const QString &box, const QString &user)
Create a LISTRIGHTS command.
Definition: imapcommand.cpp:346
imapCommand::clientStore
static CommandPtr clientStore(const QString &set, const QString &item, const QString &data, bool nouid=false)
Create a STORE command.
Definition: imapcommand.cpp:303
QString::number
QString number(int n, int base)
QList::count
int count(const T &value) const
imapCommand::setResult
void setResult(const QString &)
set the completed state
Definition: imapcommand.cpp:128
imapCommand::clientLogout
static CommandPtr clientLogout()
Create a LOGOUT command.
Definition: imapcommand.cpp:311
QString::isEmpty
bool isEmpty() const
imapCommand::clientCreate
static CommandPtr clientCreate(const QString &path)
Create a CREATE command.
Definition: imapcommand.cpp:255
imapCommand::clientSubscribe
static CommandPtr clientSubscribe(const QString &path)
Create a SUBSCRIBE command.
Definition: imapcommand.cpp:269
imapCommand::setResultInfo
void setResultInfo(const QString &)
set the completed state
Definition: imapcommand.cpp:134
imapCommand::resultInfo
const QString & resultInfo()
get information about the result
Definition: imapcommand.cpp:90
QList::first
T & first()
imapCommand::clientMyRights
static CommandPtr clientMyRights(const QString &box)
Create a MYRIGHTS command.
Definition: imapcommand.cpp:354
QString
imapCommand::clientDeleteACL
static CommandPtr clientDeleteACL(const QString &box, const QString &user)
Create a DELETEACL command.
Definition: imapcommand.cpp:331
QMap::end
iterator end()
QMap::begin
iterator begin()
QStringList
imapCommand::clientGetACL
static CommandPtr clientGetACL(const QString &box)
Create a GETACL command.
Definition: imapcommand.cpp:339
QList::end
iterator end()
imapCommand::clientFetch
static CommandPtr clientFetch(ulong uid, const QString &fields, bool nouid=false)
Create a FETCH command.
Definition: imapcommand.cpp:168
imapCommand::clientClose
static CommandPtr clientClose()
Create a CLOSE command.
Definition: imapcommand.cpp:219
imapCommand::clientSearch
static CommandPtr clientSearch(const QString &search, bool nouid=false)
Create a SEARCH command.
Definition: imapcommand.cpp:297
imapCommand::clientExpunge
static CommandPtr clientExpunge()
Create a EXPUNGE command.
Definition: imapcommand.cpp:283
imapCommand::result
const QString & result()
get the result of the command
Definition: imapcommand.cpp:84
imapCommand::clientStartTLS
static CommandPtr clientStartTLS()
Create a STARTTLS command.
Definition: imapcommand.cpp:317
imapCommand::clientCustom
static CommandPtr clientCustom(const QString &command, const QString &arguments)
Create a custom command.
Definition: imapcommand.cpp:412
QList::ConstIterator
typedef ConstIterator
QString::length
int length() const
imapCommand::setComplete
void setComplete()
set the completed state
Definition: imapcommand.cpp:122
imapCommand
encapulate a IMAP command
Definition: imapcommand.h:42
imapCommand::clientNoop
static CommandPtr clientNoop()
Create a NOOP command.
Definition: imapcommand.cpp:162
imapCommand::clientSelect
static CommandPtr clientSelect(const QString &path, bool examine=false)
Create a SELECT command.
Definition: imapcommand.cpp:208
imapCommand::parameter
const QString & parameter()
get the parameter
Definition: imapcommand.cpp:102
imapCommand::clientAppend
static CommandPtr clientAppend(const QString &box, const QString &flags, ulong size)
Create a APPEND command.
Definition: imapcommand.cpp:233
imapCommand::clientCopy
static CommandPtr clientCopy(const QString &box, const QString &sequence, bool nouid=false)
Create a COPY command.
Definition: imapcommand.cpp:225
imapCommand::clientGetAnnotation
static CommandPtr clientGetAnnotation(const QString &box, const QString &entry, const QStringList &attributeNames)
Create a GETANNOTATION command.
Definition: imapcommand.cpp:380
imapCommand::setId
void setId(const QString &)
set the id
Definition: imapcommand.cpp:114
imapCommand::clientStatus
static CommandPtr clientStatus(const QString &path, const QString &parameters)
Create a STATUS command.
Definition: imapcommand.cpp:247
QList::begin
iterator begin()
imapCommand::id
const QString & id()
get the id
Definition: imapcommand.cpp:96
imapCommand::clientSetAnnotation
static CommandPtr clientSetAnnotation(const QString &box, const QString &entry, const QMap< QString, QString > &attributes)
Create a SETANNOTATION command.
Definition: imapcommand.cpp:361
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:37:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kioslave/imap4

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

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal