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