• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 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 <klocalizedstring.h> */
57
58using namespace KIMAP;
59
60imapCommand::imapCommand ()
61{
62 mComplete = false;
63 mId.clear();
64}
65
66imapCommand::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
77bool
78imapCommand::isComplete ()
79{
80 return mComplete;
81}
82
83const QString &
84imapCommand::result ()
85{
86 return mResult;
87}
88
89const QString &
90imapCommand::resultInfo ()
91{
92 return mResultInfo;
93}
94
95const QString &
96imapCommand::id ()
97{
98 return mId;
99}
100
101const QString &
102imapCommand::parameter ()
103{
104 return aParameter;
105}
106
107const QString &
108imapCommand::command ()
109{
110 return aCommand;
111}
112
113void
114imapCommand::setId (const QString & id)
115{
116 if ( mId.isEmpty() ) {
117 mId = id;
118 }
119}
120
121void
122imapCommand::setComplete ()
123{
124 mComplete = true;
125}
126
127void
128imapCommand::setResult (const QString & result)
129{
130 mResult = result;
131}
132
133void
134imapCommand::setResultInfo (const QString & result)
135{
136 mResultInfo = result;
137}
138
139void
140imapCommand::setCommand (const QString & command)
141{
142 aCommand = command;
143}
144
145void
146imapCommand::setParameter (const QString & parameter)
147{
148 aParameter = parameter;
149}
150
151const QString
152imapCommand::getStr ()
153{
154 if ( parameter().isEmpty() ) {
155 return id() + ' ' + command() + "\r\n";
156 } else {
157 return id() + ' ' + command() + ' ' + parameter() + "\r\n";
158 }
159}
160
161CommandPtr
162imapCommand::clientNoop ()
163{
164 return CommandPtr( new imapCommand( "NOOP", "" ) );
165}
166
167CommandPtr
168imapCommand::clientFetch (ulong uid, const QString & fields, bool nouid)
169{
170 return CommandPtr( clientFetch( uid, uid, fields, nouid ) );
171}
172
173CommandPtr
174imapCommand::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
190CommandPtr
191imapCommand::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
198CommandPtr
199imapCommand::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
207CommandPtr
208imapCommand::clientSelect (const QString & path, bool examine)
209{
210 Q_UNUSED( examine );
214 return CommandPtr( new imapCommand( "SELECT",
215 QString( "\"" ) + KIMAP::encodeImapFolderName( path ) + "\"" ) );
216}
217
218CommandPtr
219imapCommand::clientClose()
220{
221 return CommandPtr( new imapCommand( "CLOSE", "" ) );
222}
223
224CommandPtr
225imapCommand::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
232CommandPtr
233imapCommand::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
246CommandPtr
247imapCommand::clientStatus (const QString & path, const QString & parameters)
248{
249 return CommandPtr( new imapCommand( "STATUS",
250 QString( "\"" ) + KIMAP::encodeImapFolderName( path ) +
251 "\" (" + parameters + ")" ) );
252}
253
254CommandPtr
255imapCommand::clientCreate (const QString & path)
256{
257 return CommandPtr( new imapCommand( "CREATE",
258 QString( "\"" ) + KIMAP::encodeImapFolderName( path ) + "\"" ) );
259}
260
261CommandPtr
262imapCommand::clientDelete (const QString & path)
263{
264 return CommandPtr( new imapCommand( "DELETE",
265 QString( "\"" ) + KIMAP::encodeImapFolderName( path ) + "\"" ) );
266}
267
268CommandPtr
269imapCommand::clientSubscribe (const QString & path)
270{
271 return CommandPtr( new imapCommand( "SUBSCRIBE",
272 QString( "\"" ) + KIMAP::encodeImapFolderName( path ) + "\"" ) );
273}
274
275CommandPtr
276imapCommand::clientUnsubscribe (const QString & path)
277{
278 return CommandPtr( new imapCommand( "UNSUBSCRIBE",
279 QString( "\"" ) + KIMAP::encodeImapFolderName( path ) + "\"" ) );
280}
281
282CommandPtr
283imapCommand::clientExpunge ()
284{
285 return CommandPtr( new imapCommand( "EXPUNGE", QString( "" ) ) );
286}
287
288CommandPtr
289imapCommand::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
296CommandPtr
297imapCommand::clientSearch (const QString & search, bool nouid)
298{
299 return CommandPtr( new imapCommand( nouid ? "SEARCH" : "UID SEARCH", search ) );
300}
301
302CommandPtr
303imapCommand::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
310CommandPtr
311imapCommand::clientLogout ()
312{
313 return CommandPtr( new imapCommand( "LOGOUT", "" ) );
314}
315
316CommandPtr
317imapCommand::clientStartTLS ()
318{
319 return CommandPtr( new imapCommand( "STARTTLS", "" ) );
320}
321
322CommandPtr
323imapCommand::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
330CommandPtr
331imapCommand::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
338CommandPtr
339imapCommand::clientGetACL( const QString& box )
340{
341 return CommandPtr( new imapCommand( "GETACL", QString( "\"" ) + KIMAP::encodeImapFolderName( box )
342 + "\"" ) );
343}
344
345CommandPtr
346imapCommand::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
353CommandPtr
354imapCommand::clientMyRights( const QString& box )
355{
356 return CommandPtr( new imapCommand( "MYRIGHTS", QString( "\"" ) + KIMAP::encodeImapFolderName( box )
357 + "\"" ) );
358}
359
360CommandPtr
361imapCommand::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
379CommandPtr
380imapCommand::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
398CommandPtr
399imapCommand::clientNamespace()
400{
401 return CommandPtr( new imapCommand( "NAMESPACE", "" ) );
402}
403
404CommandPtr
405imapCommand::clientGetQuotaroot( const QString& box )
406{
407 QString parameter = QString( "\"" ) + KIMAP::encodeImapFolderName( box ) + '"';
408 return CommandPtr( new imapCommand( "GETQUOTAROOT", parameter ) );
409}
410
411CommandPtr
412imapCommand::clientCustom( const QString& command, const QString& arguments )
413{
414 return CommandPtr( new imapCommand( command, arguments ) );
415}
imapCommand::setId
void setId(const QString &)
set the id
Definition: imapcommand.cpp:114
imapCommand::clientGetAnnotation
static CommandPtr clientGetAnnotation(const QString &box, const QString &entry, const QStringList &attributeNames)
Create a GETANNOTATION command.
Definition: imapcommand.cpp:380
imapCommand::command
const QString & command()
get the command
Definition: imapcommand.cpp:108
imapCommand::setParameter
void setParameter(const QString &)
set the command parameter(s)
Definition: imapcommand.cpp:146
imapCommand::clientLogout
static CommandPtr clientLogout()
Create a LOGOUT command.
Definition: imapcommand.cpp:311
imapCommand::clientSearch
static CommandPtr clientSearch(const QString &search, bool nouid=false)
Create a SEARCH command.
Definition: imapcommand.cpp:297
imapCommand::clientSelect
static CommandPtr clientSelect(const QString &path, bool examine=false)
Create a SELECT command.
Definition: imapcommand.cpp:208
imapCommand::clientNoop
static CommandPtr clientNoop()
Create a NOOP command.
Definition: imapcommand.cpp:162
imapCommand::resultInfo
const QString & resultInfo()
get information about the result
Definition: imapcommand.cpp:90
imapCommand::clientAppend
static CommandPtr clientAppend(const QString &box, const QString &flags, ulong size)
Create a APPEND command.
Definition: imapcommand.cpp:233
imapCommand::clientMyRights
static CommandPtr clientMyRights(const QString &box)
Create a MYRIGHTS command.
Definition: imapcommand.cpp:354
imapCommand::clientSetAnnotation
static CommandPtr clientSetAnnotation(const QString &box, const QString &entry, const QMap< QString, QString > &attributes)
Create a SETANNOTATION command.
Definition: imapcommand.cpp:361
imapCommand::id
const QString & id()
get the id
Definition: imapcommand.cpp:96
imapCommand::setCommand
void setCommand(const QString &)
set the command
Definition: imapcommand.cpp:140
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
imapCommand::clientSubscribe
static CommandPtr clientSubscribe(const QString &path)
Create a SUBSCRIBE command.
Definition: imapcommand.cpp:269
imapCommand::setComplete
void setComplete()
set the completed state
Definition: imapcommand.cpp:122
imapCommand::clientList
static CommandPtr clientList(const QString &reference, const QString &path, bool lsub=false)
Create a LIST command.
Definition: imapcommand.cpp:199
imapCommand::clientCustom
static CommandPtr clientCustom(const QString &command, const QString &arguments)
Create a custom command.
Definition: imapcommand.cpp:412
imapCommand::clientFetch
static CommandPtr clientFetch(ulong uid, const QString &fields, bool nouid=false)
Create a FETCH command.
Definition: imapcommand.cpp:168
imapCommand::result
const QString & result()
get the result of the command
Definition: imapcommand.cpp:84
imapCommand::isComplete
bool isComplete()
is it complete?
Definition: imapcommand.cpp:78
imapCommand::clientListRights
static CommandPtr clientListRights(const QString &box, const QString &user)
Create a LISTRIGHTS command.
Definition: imapcommand.cpp:346
imapCommand::clientNamespace
static CommandPtr clientNamespace()
Create a NAMESPACE command.
Definition: imapcommand.cpp:399
imapCommand::clientStartTLS
static CommandPtr clientStartTLS()
Create a STARTTLS command.
Definition: imapcommand.cpp:317
imapCommand::clientDeleteACL
static CommandPtr clientDeleteACL(const QString &box, const QString &user)
Create a DELETEACL command.
Definition: imapcommand.cpp:331
imapCommand::clientGetQuotaroot
static CommandPtr clientGetQuotaroot(const QString &box)
Create a GETQUOTAROOT command.
Definition: imapcommand.cpp:405
imapCommand::clientUnsubscribe
static CommandPtr clientUnsubscribe(const QString &path)
Create a UNSUBSCRIBE command.
Definition: imapcommand.cpp:276
imapCommand::setResult
void setResult(const QString &)
set the completed state
Definition: imapcommand.cpp:128
imapCommand::clientStatus
static CommandPtr clientStatus(const QString &path, const QString &parameters)
Create a STATUS command.
Definition: imapcommand.cpp:247
imapCommand::clientCreate
static CommandPtr clientCreate(const QString &path)
Create a CREATE command.
Definition: imapcommand.cpp:255
imapCommand::parameter
const QString & parameter()
get the parameter
Definition: imapcommand.cpp:102
imapCommand::clientClose
static CommandPtr clientClose()
Create a CLOSE command.
Definition: imapcommand.cpp:219
imapCommand::clientGetACL
static CommandPtr clientGetACL(const QString &box)
Create a GETACL command.
Definition: imapcommand.cpp:339
imapCommand::clientRename
static CommandPtr clientRename(const QString &src, const QString &dest)
Create a RENAME command.
Definition: imapcommand.cpp:289
imapCommand::clientExpunge
static CommandPtr clientExpunge()
Create a EXPUNGE command.
Definition: imapcommand.cpp:283
imapCommand::clientCopy
static CommandPtr clientCopy(const QString &box, const QString &sequence, bool nouid=false)
Create a COPY command.
Definition: imapcommand.cpp:225
imapCommand::clientDelete
static CommandPtr clientDelete(const QString &path)
Create a DELETE command.
Definition: imapcommand.cpp:262
imapCommand::clientSetACL
static CommandPtr clientSetACL(const QString &box, const QString &user, const QString &acl)
Create a SETACL command.
Definition: imapcommand.cpp:323
imapCommand::imapCommand
imapCommand()
Constructor.
Definition: imapcommand.cpp:60
imapCommand::setResultInfo
void setResultInfo(const QString &)
set the completed state
Definition: imapcommand.cpp:134
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
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jul 21 2022 00:00:00 by doxygen 1.9.5 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.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 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
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