summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/mail2/libmail/imaphandler.cpp9
-rw-r--r--noncore/unsupported/mail2/libmail/imaphandler.h2
2 files changed, 10 insertions, 1 deletions
diff --git a/noncore/unsupported/mail2/libmail/imaphandler.cpp b/noncore/unsupported/mail2/libmail/imaphandler.cpp
index 66c92c5..730a004 100644
--- a/noncore/unsupported/mail2/libmail/imaphandler.cpp
+++ b/noncore/unsupported/mail2/libmail/imaphandler.cpp
@@ -1,55 +1,56 @@
1#include "imapresponse.h" 1#include "imapresponse.h"
2#include "imaphandler.h" 2#include "imaphandler.h"
3#include "imapbase.h" 3#include "imapbase.h"
4 4
5IMAPHandler::IMAPHandler(const Account &account) 5IMAPHandler::IMAPHandler(const Account &account)
6 : QObject(), _account(account) 6 : QObject(), _account(account)
7{ 7{
8 _ready = false;
8 _loggingin = false; 9 _loggingin = false;
9 _loggedin = false; 10 _loggedin = false;
10 _tag = 0; 11 _tag = 0;
11 _ibase = new IMAPBase(account); 12 _ibase = new IMAPBase(account);
12 13
13 connect(_ibase, SIGNAL(dataReceived(const QString &)), SLOT(slotDataReceived(const QString &))); 14 connect(_ibase, SIGNAL(dataReceived(const QString &)), SLOT(slotDataReceived(const QString &)));
14 connect(_ibase, SIGNAL(lookingUpHost()), SLOT(slotLookingUpHost())); 15 connect(_ibase, SIGNAL(lookingUpHost()), SLOT(slotLookingUpHost()));
15 connect(_ibase, SIGNAL(hostFound()), SLOT(slotHostFound())); 16 connect(_ibase, SIGNAL(hostFound()), SLOT(slotHostFound()));
16 connect(_ibase, SIGNAL(connected()), SLOT(slotConnected())); 17 connect(_ibase, SIGNAL(connected()), SLOT(slotConnected()));
17 connect(_ibase, SIGNAL(disconnected()), SLOT(slotDisconnected())); 18 connect(_ibase, SIGNAL(disconnected()), SLOT(slotDisconnected()));
18 connect(_ibase, SIGNAL(error(int)), SLOT(slotError(int))); 19 connect(_ibase, SIGNAL(error(int)), SLOT(slotError(int)));
19} 20}
20 21
21void IMAPHandler::doLogin() 22void IMAPHandler::doLogin()
22{ 23{
23 if (_loggedin) return; 24 if (_loggedin) return;
24 if (_loggingin) return; 25 if (_loggingin) return;
25 26
26 _loggingin = true; 27 _loggingin = true;
27 iLogin(_account.user(), _account.pass()); 28 iLogin(_account.user(), _account.pass());
28} 29}
29 30
30QString IMAPHandler::iCapability() 31QString IMAPHandler::iCapability()
31{ 32{
32 _ibase->sendCommand(QString("%1 CAPABILITY\r\n") 33 _ibase->sendCommand(QString("%1 CAPABILITY\r\n")
33 .arg(tag())); 34 .arg(tag()));
34 return tag(false); 35 return tag(false);
35} 36}
36 37
37QString IMAPHandler::iNoop() 38QString IMAPHandler::iNoop()
38{ 39{
39 _ibase->sendCommand(QString("%1 NOOP\r\n") 40 _ibase->sendCommand(QString("%1 NOOP\r\n")
40 .arg(tag())); 41 .arg(tag()));
41 return tag(false); 42 return tag(false);
42} 43}
43 44
44QString IMAPHandler::iLogout() 45QString IMAPHandler::iLogout()
45{ 46{
46 _ibase->sendCommand(QString("%1 LOGOUT\r\n") 47 _ibase->sendCommand(QString("%1 LOGOUT\r\n")
47 .arg(tag())); 48 .arg(tag()));
48 return tag(false); 49 return tag(false);
49} 50}
50 51
51QString IMAPHandler::iAuthenticate(const QString &mechanism) 52QString IMAPHandler::iAuthenticate(const QString &mechanism)
52{ 53{
53 _ibase->sendCommand(QString("%1 AUTHENTICATE \"%2\"\r\n") 54 _ibase->sendCommand(QString("%1 AUTHENTICATE \"%2\"\r\n")
54 .arg(tag()) 55 .arg(tag())
55 .arg(escape(mechanism))); 56 .arg(escape(mechanism)));
@@ -244,91 +245,99 @@ QString IMAPHandler::iStore(const QString &message, const QString &items)
244} 245}
245 246
246QString IMAPHandler::iCopy(const QString &message, const QString &mailbox) 247QString IMAPHandler::iCopy(const QString &message, const QString &mailbox)
247{ 248{
248 doLogin(); 249 doLogin();
249 250
250 _ibase->sendCommand(QString("%1 COPY %2 \"%3\"\r\n") 251 _ibase->sendCommand(QString("%1 COPY %2 \"%3\"\r\n")
251 .arg(tag()) 252 .arg(tag())
252 .arg(message) 253 .arg(message)
253 .arg(escape(mailbox))); 254 .arg(escape(mailbox)));
254 return tag(false); 255 return tag(false);
255} 256}
256 257
257QString IMAPHandler::iUid(const QString &command, const QString &arguments) 258QString IMAPHandler::iUid(const QString &command, const QString &arguments)
258{ 259{
259 doLogin(); 260 doLogin();
260 261
261 _ibase->sendCommand(QString("%1 UID %2 %3\r\n") 262 _ibase->sendCommand(QString("%1 UID %2 %3\r\n")
262 .arg(tag()) 263 .arg(tag())
263 .arg(command) 264 .arg(command)
264 .arg(arguments)); 265 .arg(arguments));
265 return tag(false); 266 return tag(false);
266} 267}
267 268
268QString IMAPHandler::iX(const QString &commandAtom, const QString &arguments) 269QString IMAPHandler::iX(const QString &commandAtom, const QString &arguments)
269{ 270{
270 doLogin(); 271 doLogin();
271 272
272 _ibase->sendCommand(QString("%1 X%2 %3\r\n") 273 _ibase->sendCommand(QString("%1 X%2 %3\r\n")
273 .arg(tag()) 274 .arg(tag())
274 .arg(commandAtom) 275 .arg(commandAtom)
275 .arg(arguments)); 276 .arg(arguments));
276 return tag(false); 277 return tag(false);
277} 278}
278 279
279QString IMAPHandler::escape(const QString &in) 280QString IMAPHandler::escape(const QString &in)
280{ 281{
281 QString in_ = in; 282 QString in_ = in;
282 return in_.replace(QRegExp("\""), "\\\""); 283 return in_.replace(QRegExp("\""), "\\\"");
283} 284}
284 285
285QString IMAPHandler::tag(bool count) 286QString IMAPHandler::tag(bool count)
286{ 287{
287 return QString("a%1").arg(count ? _tag++ : _tag); 288 return QString("a%1").arg(count ? _tag++ : _tag);
288} 289}
289 290
290void IMAPHandler::slotDataReceived(const QString &data) 291void IMAPHandler::slotDataReceived(const QString &data)
291{ 292{
293 if (!_ready) {
294 // The first data is always the greeting string.
295 // We can ignore it.
296 _ready = true;
297 return;
298 }
299
300
292 IMAPResponseParser parser(data); 301 IMAPResponseParser parser(data);
293 IMAPResponse response = parser.response(); 302 IMAPResponse response = parser.response();
294 response.setImapHandler(this); 303 response.setImapHandler(this);
295 304
296 if (!_loggingin) emit gotResponse(response); 305 if (!_loggingin) emit gotResponse(response);
297 else { 306 else {
298 if (response.statusResponse().status() == IMAPResponseEnums::OK) { 307 if (response.statusResponse().status() == IMAPResponseEnums::OK) {
299 _loggingin = false; 308 _loggingin = false;
300 _loggedin = true; 309 _loggedin = true;
301 qWarning("OK. Logged in. Leaving loggingin state."); 310 qWarning("OK. Logged in. Leaving loggingin state.");
302 } else { 311 } else {
303 _loggingin = false; 312 _loggingin = false;
304 emit IMAPError(IMAPBase::IMAPErrLoginFailed); 313 emit IMAPError(IMAPBase::IMAPErrLoginFailed);
305 } 314 }
306 } 315 }
307} 316}
308 317
309void IMAPHandler::slotLookingUpHost() 318void IMAPHandler::slotLookingUpHost()
310{ 319{
311 emit IMAPLookingUpHost(); 320 emit IMAPLookingUpHost();
312} 321}
313 322
314void IMAPHandler::slotHostFound() 323void IMAPHandler::slotHostFound()
315{ 324{
316 emit IMAPHostFound(); 325 emit IMAPHostFound();
317} 326}
318 327
319void IMAPHandler::slotConnected() 328void IMAPHandler::slotConnected()
320{ 329{
321 emit IMAPConnected(); 330 emit IMAPConnected();
322} 331}
323 332
324void IMAPHandler::slotDisconnected() 333void IMAPHandler::slotDisconnected()
325{ 334{
326 _loggedin = false; 335 _loggedin = false;
327 emit IMAPDisconnected(); 336 emit IMAPDisconnected();
328} 337}
329 338
330void IMAPHandler::slotError(int err) 339void IMAPHandler::slotError(int err)
331{ 340{
332 emit IMAPError(err); 341 emit IMAPError(err);
333} 342}
334 343
diff --git a/noncore/unsupported/mail2/libmail/imaphandler.h b/noncore/unsupported/mail2/libmail/imaphandler.h
index 8cb42db..cc47a85 100644
--- a/noncore/unsupported/mail2/libmail/imaphandler.h
+++ b/noncore/unsupported/mail2/libmail/imaphandler.h
@@ -34,53 +34,53 @@ public:
34 QString iList(const QString &reference, const QString &mailbox); 34 QString iList(const QString &reference, const QString &mailbox);
35 QString iLsub(const QString &reference, const QString &mailbox); 35 QString iLsub(const QString &reference, const QString &mailbox);
36 36
37 QString iStatus(const QString &mailbox, const QString &items); 37 QString iStatus(const QString &mailbox, const QString &items);
38 38
39 QString iAppend(const QString &mailbox, const QString &literal, const QString &flags = 0, const QString &datetime = 0); 39 QString iAppend(const QString &mailbox, const QString &literal, const QString &flags = 0, const QString &datetime = 0);
40 40
41 QString iCheck(); 41 QString iCheck();
42 QString iClose(); 42 QString iClose();
43 QString iExpunge(); 43 QString iExpunge();
44 44
45 QString iSearch(const QString &search, const QString &charset = 0); 45 QString iSearch(const QString &search, const QString &charset = 0);
46 46
47 QString iFetch(const QString &message, const QString &items); 47 QString iFetch(const QString &message, const QString &items);
48 48
49 QString iStore(const QString &message, const QString &items); 49 QString iStore(const QString &message, const QString &items);
50 QString iCopy(const QString &message, const QString &mailbox); 50 QString iCopy(const QString &message, const QString &mailbox);
51 51
52 QString iUid(const QString &command, const QString &arguments); 52 QString iUid(const QString &command, const QString &arguments);
53 53
54 QString iX(const QString &commandAtom, const QString &arguments); 54 QString iX(const QString &commandAtom, const QString &arguments);
55 55
56signals: 56signals:
57 void gotResponse(IMAPResponse &response); 57 void gotResponse(IMAPResponse &response);
58 58
59 void IMAPLookingUpHost(); 59 void IMAPLookingUpHost();
60 void IMAPHostFound(); 60 void IMAPHostFound();
61 void IMAPConnected(); 61 void IMAPConnected();
62 void IMAPDisconnected(); 62 void IMAPDisconnected();
63 void IMAPError(int err); 63 void IMAPError(int err);
64 64
65protected: 65protected:
66 void doLogin(); 66 void doLogin();
67 QString escape(const QString &in); 67 QString escape(const QString &in);
68 QString tag(bool count = true); 68 QString tag(bool count = true);
69 69
70protected slots: 70protected slots:
71 void slotDataReceived(const QString &data); 71 void slotDataReceived(const QString &data);
72 void slotLookingUpHost(); 72 void slotLookingUpHost();
73 void slotHostFound(); 73 void slotHostFound();
74 void slotConnected(); 74 void slotConnected();
75 void slotDisconnected(); 75 void slotDisconnected();
76 void slotError(int err); 76 void slotError(int err);
77 77
78private: 78private:
79 Account _account; 79 Account _account;
80 IMAPBase *_ibase; 80 IMAPBase *_ibase;
81 unsigned int _tag; 81 unsigned int _tag;
82 bool _loggingin, _loggedin; 82 bool _ready, _loggingin, _loggedin;
83 83
84}; 84};
85 85
86#endif 86#endif