author | conber <conber> | 2002-06-15 18:26:36 (UTC) |
---|---|---|
committer | conber <conber> | 2002-06-15 18:26:36 (UTC) |
commit | f797160d879c74652b27bca3df8a74243465d65c (patch) (unidiff) | |
tree | eb6a376174ba1e532127d099df6a02d201e2e34f | |
parent | ff47b17768607d8819ef5cd3316a1cab0abdcf3a (diff) | |
download | opie-f797160d879c74652b27bca3df8a74243465d65c.zip opie-f797160d879c74652b27bca3df8a74243465d65c.tar.gz opie-f797160d879c74652b27bca3df8a74243465d65c.tar.bz2 |
fixed bug. you should be able to browse and search in an imap account now.
-rw-r--r-- | noncore/unsupported/mail2/libmail/imaphandler.cpp | 9 | ||||
-rw-r--r-- | noncore/unsupported/mail2/libmail/imaphandler.h | 2 |
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,39 +1,40 @@ | |||
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 | ||
5 | IMAPHandler::IMAPHandler(const Account &account) | 5 | IMAPHandler::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 | ||
21 | void IMAPHandler::doLogin() | 22 | void 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 | ||
30 | QString IMAPHandler::iCapability() | 31 | QString 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 | ||
37 | QString IMAPHandler::iNoop() | 38 | QString IMAPHandler::iNoop() |
38 | { | 39 | { |
39 | _ibase->sendCommand(QString("%1 NOOP\r\n") | 40 | _ibase->sendCommand(QString("%1 NOOP\r\n") |
@@ -260,64 +261,72 @@ QString IMAPHandler::iUid(const QString &command, const QString &arguments) | |||
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 | ||
268 | QString IMAPHandler::iX(const QString &commandAtom, const QString &arguments) | 269 | QString 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 | ||
279 | QString IMAPHandler::escape(const QString &in) | 280 | QString 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 | ||
285 | QString IMAPHandler::tag(bool count) | 286 | QString 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 | ||
290 | void IMAPHandler::slotDataReceived(const QString &data) | 291 | void 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 | ||
309 | void IMAPHandler::slotLookingUpHost() | 318 | void IMAPHandler::slotLookingUpHost() |
310 | { | 319 | { |
311 | emit IMAPLookingUpHost(); | 320 | emit IMAPLookingUpHost(); |
312 | } | 321 | } |
313 | 322 | ||
314 | void IMAPHandler::slotHostFound() | 323 | void IMAPHandler::slotHostFound() |
315 | { | 324 | { |
316 | emit IMAPHostFound(); | 325 | emit IMAPHostFound(); |
317 | } | 326 | } |
318 | 327 | ||
319 | void IMAPHandler::slotConnected() | 328 | void IMAPHandler::slotConnected() |
320 | { | 329 | { |
321 | emit IMAPConnected(); | 330 | emit IMAPConnected(); |
322 | } | 331 | } |
323 | 332 | ||
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 | |||
@@ -50,37 +50,37 @@ public: | |||
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 | ||
56 | signals: | 56 | signals: |
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 | ||
65 | protected: | 65 | protected: |
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 | ||
70 | protected slots: | 70 | protected 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 | ||
78 | private: | 78 | private: |
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 |