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

kioslave/imap4

  • 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 <klocale.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 void
121 imapCommand::setComplete ()
122 {
123  mComplete = true;
124 }
125 
126 void
127 imapCommand::setResult (const QString & result)
128 {
129  mResult = result;
130 }
131 
132 void
133 imapCommand::setResultInfo (const QString & result)
134 {
135  mResultInfo = result;
136 }
137 
138 void
139 imapCommand::setCommand (const QString & command)
140 {
141  aCommand = command;
142 }
143 
144 void
145 imapCommand::setParameter (const QString & parameter)
146 {
147  aParameter = parameter;
148 }
149 
150 const QString
151 imapCommand::getStr ()
152 {
153  if (parameter().isEmpty())
154  return id() + ' ' + command() + "\r\n";
155  else
156  return id() + ' ' + command() + ' ' + parameter() + "\r\n";
157 }
158 
159 CommandPtr
160 imapCommand::clientNoop ()
161 {
162  return CommandPtr( new imapCommand ("NOOP", "") );
163 }
164 
165 CommandPtr
166 imapCommand::clientFetch (ulong uid, const QString & fields, bool nouid)
167 {
168  return CommandPtr( clientFetch (uid, uid, fields, nouid) );
169 }
170 
171 CommandPtr
172 imapCommand::clientFetch (ulong fromUid, ulong toUid, const QString & fields,
173  bool nouid)
174 {
175  QString uid = QString::number(fromUid);
176 
177  if (fromUid != toUid)
178  {
179  uid += ':';
180  if (toUid < fromUid)
181  uid += '*';
182  else
183  uid += QString::number(toUid);
184  }
185  return clientFetch (uid, fields, nouid);
186 }
187 
188 CommandPtr
189 imapCommand::clientFetch (const QString & sequence, const QString & fields,
190  bool nouid)
191 {
192  return CommandPtr( new imapCommand (nouid ? "FETCH" : "UID FETCH",
193  sequence + " (" + fields + ')') );
194 }
195 
196 CommandPtr
197 imapCommand::clientList (const QString & reference, const QString & path,
198  bool lsub)
199 {
200  return CommandPtr( new imapCommand (lsub ? "LSUB" : "LIST",
201  QString ("\"") + KIMAP::encodeImapFolderName (reference) +
202  "\" \"" + KIMAP::encodeImapFolderName (path) + "\"") );
203 }
204 
205 CommandPtr
206 imapCommand::clientSelect (const QString & path, bool examine)
207 {
208  Q_UNUSED(examine);
212  return CommandPtr( new imapCommand ("SELECT",
213  QString ("\"") + KIMAP::encodeImapFolderName (path) + "\"") );
214 }
215 
216 CommandPtr
217 imapCommand::clientClose()
218 {
219  return CommandPtr( new imapCommand("CLOSE", "") );
220 }
221 
222 CommandPtr
223 imapCommand::clientCopy (const QString & box, const QString & sequence,
224  bool nouid)
225 {
226  return CommandPtr( new imapCommand (nouid ? "COPY" : "UID COPY",
227  sequence + " \"" + KIMAP::encodeImapFolderName (box) + "\"") );
228 }
229 
230 CommandPtr
231 imapCommand::clientAppend (const QString & box, const QString & flags,
232  ulong size)
233 {
234  QString tmp;
235  if ( !flags.isEmpty() ) {
236  tmp = '(' + flags + ") ";
237  }
238  tmp += '{' + QString::number( size ) + '}';
239 
240  return CommandPtr( new imapCommand ("APPEND",
241  "\"" + KIMAP::encodeImapFolderName (box) + "\" " + tmp));
242 }
243 
244 CommandPtr
245 imapCommand::clientStatus (const QString & path, const QString & parameters)
246 {
247  return CommandPtr( new imapCommand ("STATUS",
248  QString ("\"") + KIMAP::encodeImapFolderName (path) +
249  "\" (" + parameters + ")") );
250 }
251 
252 CommandPtr
253 imapCommand::clientCreate (const QString & path)
254 {
255  return CommandPtr( new imapCommand ("CREATE",
256  QString ("\"") + KIMAP::encodeImapFolderName (path) + "\"") );
257 }
258 
259 CommandPtr
260 imapCommand::clientDelete (const QString & path)
261 {
262  return CommandPtr( new imapCommand ("DELETE",
263  QString ("\"") + KIMAP::encodeImapFolderName (path) + "\"") );
264 }
265 
266 CommandPtr
267 imapCommand::clientSubscribe (const QString & path)
268 {
269  return CommandPtr( new imapCommand ("SUBSCRIBE",
270  QString ("\"") + KIMAP::encodeImapFolderName (path) + "\"") );
271 }
272 
273 CommandPtr
274 imapCommand::clientUnsubscribe (const QString & path)
275 {
276  return CommandPtr( new imapCommand ("UNSUBSCRIBE",
277  QString ("\"") + KIMAP::encodeImapFolderName (path) + "\"") );
278 }
279 
280 CommandPtr
281 imapCommand::clientExpunge ()
282 {
283  return CommandPtr( new imapCommand ("EXPUNGE", QString ("")) );
284 }
285 
286 CommandPtr
287 imapCommand::clientRename (const QString & src, const QString & dest)
288 {
289  return CommandPtr( new imapCommand ("RENAME",
290  QString ("\"") + KIMAP::encodeImapFolderName (src) +
291  "\" \"" + KIMAP::encodeImapFolderName (dest) + "\"") );
292 }
293 
294 CommandPtr
295 imapCommand::clientSearch (const QString & search, bool nouid)
296 {
297  return CommandPtr( new imapCommand (nouid ? "SEARCH" : "UID SEARCH", search) );
298 }
299 
300 CommandPtr
301 imapCommand::clientStore (const QString & set, const QString & item,
302  const QString & data, bool nouid)
303 {
304  return CommandPtr( new imapCommand (nouid ? "STORE" : "UID STORE",
305  set + ' ' + item + " (" + data + ')') );
306 }
307 
308 CommandPtr
309 imapCommand::clientLogout ()
310 {
311  return CommandPtr( new imapCommand ("LOGOUT", "") );
312 }
313 
314 CommandPtr
315 imapCommand::clientStartTLS ()
316 {
317  return CommandPtr( new imapCommand ("STARTTLS", "") );
318 }
319 
320 CommandPtr
321 imapCommand::clientSetACL( const QString& box, const QString& user, const QString& acl )
322 {
323  return CommandPtr( new imapCommand ("SETACL", QString("\"") + KIMAP::encodeImapFolderName (box)
324  + "\" \"" + KIMAP::encodeImapFolderName (user)
325  + "\" \"" + KIMAP::encodeImapFolderName (acl) + "\"") );
326 }
327 
328 CommandPtr
329 imapCommand::clientDeleteACL( const QString& box, const QString& user )
330 {
331  return CommandPtr( new imapCommand ("DELETEACL", QString("\"") + KIMAP::encodeImapFolderName (box)
332  + "\" \"" + KIMAP::encodeImapFolderName (user)
333  + "\"") );
334 }
335 
336 CommandPtr
337 imapCommand::clientGetACL( const QString& box )
338 {
339  return CommandPtr( new imapCommand ("GETACL", QString("\"") + KIMAP::encodeImapFolderName (box)
340  + "\"") );
341 }
342 
343 CommandPtr
344 imapCommand::clientListRights( const QString& box, const QString& user )
345 {
346  return CommandPtr( new imapCommand ("LISTRIGHTS", QString("\"") + KIMAP::encodeImapFolderName (box)
347  + "\" \"" + KIMAP::encodeImapFolderName (user)
348  + "\"") );
349 }
350 
351 CommandPtr
352 imapCommand::clientMyRights( const QString& box )
353 {
354  return CommandPtr( new imapCommand ("MYRIGHTS", QString("\"") + KIMAP::encodeImapFolderName (box)
355  + "\"") );
356 }
357 
358 CommandPtr
359 imapCommand::clientSetAnnotation( const QString& box, const QString& entry, const QMap<QString, QString>& attributes )
360 {
361  QString parameter = QString("\"") + KIMAP::encodeImapFolderName (box)
362  + "\" \"" + KIMAP::encodeImapFolderName (entry)
363  + "\" (";
364  for( QMap<QString,QString>::ConstIterator it = attributes.begin(); it != attributes.end(); ++it ) {
365  parameter += "\"";
366  parameter += KIMAP::encodeImapFolderName (it.key());
367  parameter += "\" \"";
368  parameter += KIMAP::encodeImapFolderName (it.value());
369  parameter += "\" ";
370  }
371  // Turn last space into a ')'
372  parameter[parameter.length()-1] = ')';
373 
374  return CommandPtr( new imapCommand ("SETANNOTATION", parameter) );
375 }
376 
377 CommandPtr
378 imapCommand::clientGetAnnotation( const QString& box, const QString& entry, const QStringList& attributeNames )
379 {
380  QString parameter = QString("\"") + KIMAP::encodeImapFolderName (box)
381  + "\" \"" + KIMAP::encodeImapFolderName (entry)
382  + "\" ";
383  if ( attributeNames.count() == 1 )
384  parameter += "\"" + KIMAP::encodeImapFolderName (attributeNames.first()) + '"';
385  else {
386  parameter += '(';
387  for( QStringList::ConstIterator it = attributeNames.begin(); it != attributeNames.end(); ++it ) {
388  parameter += "\"" + KIMAP::encodeImapFolderName (*it) + "\" ";
389  }
390  // Turn last space into a ')'
391  parameter[parameter.length()-1] = ')';
392  }
393  return CommandPtr( new imapCommand ("GETANNOTATION", parameter) );
394 }
395 
396 CommandPtr
397 imapCommand::clientNamespace()
398 {
399  return CommandPtr( new imapCommand("NAMESPACE", "") );
400 }
401 
402 CommandPtr
403 imapCommand::clientGetQuotaroot( const QString& box )
404 {
405  QString parameter = QString("\"") + KIMAP::encodeImapFolderName (box) + '"';
406  return CommandPtr( new imapCommand ("GETQUOTAROOT", parameter) );
407 }
408 
409 CommandPtr
410 imapCommand::clientCustom( const QString& command, const QString& arguments )
411 {
412  return CommandPtr( new imapCommand (command, arguments) );
413 }
414 
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Tue Dec 4 2012 14:35:11 by doxygen 1.8.1.2 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-4.9.4 API Reference

Skip menu "kdepimlibs-4.9.4 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • 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
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