Diffstat (limited to 'noncore/unsupported/mail2/libmail/imaphandler.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/unsupported/mail2/libmail/imaphandler.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/noncore/unsupported/mail2/libmail/imaphandler.cpp b/noncore/unsupported/mail2/libmail/imaphandler.cpp index dc97b28..8da0acd 100644 --- a/noncore/unsupported/mail2/libmail/imaphandler.cpp +++ b/noncore/unsupported/mail2/libmail/imaphandler.cpp | |||
@@ -1,110 +1,110 @@ | |||
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 | _ready = false; |
9 | _loggingin = false; | 9 | _loggingin = false; |
10 | _loggedin = false; | 10 | _loggedin = false; |
11 | _tag = 0; | 11 | _tag = 0; |
12 | _ibase = new IMAPBase(account); | 12 | _ibase = new IMAPBase(account); |
13 | 13 | ||
14 | connect(_ibase, SIGNAL(dataReceived(const QString &)), SLOT(slotDataReceived(const QString &))); | 14 | connect(_ibase, SIGNAL(dataReceived(const QString&)), SLOT(slotDataReceived(const QString&))); |
15 | connect(_ibase, SIGNAL(lookingUpHost()), SLOT(slotLookingUpHost())); | 15 | connect(_ibase, SIGNAL(lookingUpHost()), SLOT(slotLookingUpHost())); |
16 | connect(_ibase, SIGNAL(hostFound()), SLOT(slotHostFound())); | 16 | connect(_ibase, SIGNAL(hostFound()), SLOT(slotHostFound())); |
17 | connect(_ibase, SIGNAL(connected()), SLOT(slotConnected())); | 17 | connect(_ibase, SIGNAL(connected()), SLOT(slotConnected())); |
18 | connect(_ibase, SIGNAL(disconnected()), SLOT(slotDisconnected())); | 18 | connect(_ibase, SIGNAL(disconnected()), SLOT(slotDisconnected())); |
19 | connect(_ibase, SIGNAL(error(int)), SLOT(slotError(int))); | 19 | connect(_ibase, SIGNAL(error(int)), SLOT(slotError(int))); |
20 | } | 20 | } |
21 | 21 | ||
22 | void IMAPHandler::doLogin() | 22 | void IMAPHandler::doLogin() |
23 | { | 23 | { |
24 | if (_loggedin) return; | 24 | if (_loggedin) return; |
25 | if (_loggingin) return; | 25 | if (_loggingin) return; |
26 | 26 | ||
27 | _loggingin = true; | 27 | _loggingin = true; |
28 | iLogin(_account.user(), _account.pass()); | 28 | iLogin(_account.user(), _account.pass()); |
29 | } | 29 | } |
30 | 30 | ||
31 | QString IMAPHandler::iCapability() | 31 | QString IMAPHandler::iCapability() |
32 | { | 32 | { |
33 | _ibase->sendCommand(QString("%1 CAPABILITY\r\n") | 33 | _ibase->sendCommand(QString("%1 CAPABILITY\r\n") |
34 | .arg(tag())); | 34 | .arg(tag())); |
35 | return tag(false); | 35 | return tag(false); |
36 | } | 36 | } |
37 | 37 | ||
38 | QString IMAPHandler::iNoop() | 38 | QString IMAPHandler::iNoop() |
39 | { | 39 | { |
40 | _ibase->sendCommand(QString("%1 NOOP\r\n") | 40 | _ibase->sendCommand(QString("%1 NOOP\r\n") |
41 | .arg(tag())); | 41 | .arg(tag())); |
42 | return tag(false); | 42 | return tag(false); |
43 | } | 43 | } |
44 | 44 | ||
45 | QString IMAPHandler::iLogout() | 45 | QString IMAPHandler::iLogout() |
46 | { | 46 | { |
47 | _ibase->sendCommand(QString("%1 LOGOUT\r\n") | 47 | _ibase->sendCommand(QString("%1 LOGOUT\r\n") |
48 | .arg(tag())); | 48 | .arg(tag())); |
49 | return tag(false); | 49 | return tag(false); |
50 | } | 50 | } |
51 | 51 | ||
52 | QString IMAPHandler::iAuthenticate(const QString &mechanism) | 52 | QString IMAPHandler::iAuthenticate(const QString &mechanism) |
53 | { | 53 | { |
54 | _ibase->sendCommand(QString("%1 AUTHENTICATE \"%2\"\r\n") | 54 | _ibase->sendCommand(QString("%1 AUTHENTICATE \"%2\"\r\n") |
55 | .arg(tag()) | 55 | .arg(tag()) |
56 | .arg(escape(mechanism))); | 56 | .arg(escape(mechanism))); |
57 | return tag(false); | 57 | return tag(false); |
58 | } | 58 | } |
59 | 59 | ||
60 | QString IMAPHandler::iLogin(const QString &user, const QString &pass) | 60 | QString IMAPHandler::iLogin(const QString &user, const QString &pass) |
61 | { | 61 | { |
62 | _ibase->sendCommand(QString("%1 LOGIN \"%2\" \"%3\"\r\n") | 62 | _ibase->sendCommand(QString("%1 LOGIN \"%2\" \"%3\"\r\n") |
63 | .arg(tag()) | 63 | .arg(tag()) |
64 | .arg(escape(user)) | 64 | .arg(escape(user)) |
65 | .arg(escape(pass))); | 65 | .arg(escape(pass))); |
66 | return tag(false); | 66 | return tag(false); |
67 | } | 67 | } |
68 | 68 | ||
69 | QString IMAPHandler::iSelect(const QString &mailbox) | 69 | QString IMAPHandler::iSelect(const QString &mailbox) |
70 | { | 70 | { |
71 | doLogin(); | 71 | doLogin(); |
72 | 72 | ||
73 | _ibase->sendCommand(QString("%1 SELECT \"%2\"\r\n") | 73 | _ibase->sendCommand(QString("%1 SELECT \"%2\"\r\n") |
74 | .arg(tag()) | 74 | .arg(tag()) |
75 | .arg(escape(mailbox))); | 75 | .arg(escape(mailbox))); |
76 | return tag(false); | 76 | return tag(false); |
77 | } | 77 | } |
78 | 78 | ||
79 | QString IMAPHandler::iExamine(const QString &mailbox) | 79 | QString IMAPHandler::iExamine(const QString &mailbox) |
80 | { | 80 | { |
81 | doLogin(); | 81 | doLogin(); |
82 | 82 | ||
83 | _ibase->sendCommand(QString("%1 EXAMINE \"%2\"\r\n") | 83 | _ibase->sendCommand(QString("%1 EXAMINE \"%2\"\r\n") |
84 | .arg(tag()) | 84 | .arg(tag()) |
85 | .arg(escape(mailbox))); | 85 | .arg(escape(mailbox))); |
86 | return tag(false); | 86 | return tag(false); |
87 | } | 87 | } |
88 | 88 | ||
89 | QString IMAPHandler::iCreate(const QString &mailbox) | 89 | QString IMAPHandler::iCreate(const QString &mailbox) |
90 | { | 90 | { |
91 | doLogin(); | 91 | doLogin(); |
92 | 92 | ||
93 | _ibase->sendCommand(QString("%1 CREATE \"%2\"\r\n") | 93 | _ibase->sendCommand(QString("%1 CREATE \"%2\"\r\n") |
94 | .arg(tag()) | 94 | .arg(tag()) |
95 | .arg(escape(mailbox))); | 95 | .arg(escape(mailbox))); |
96 | return tag(false); | 96 | return tag(false); |
97 | } | 97 | } |
98 | 98 | ||
99 | QString IMAPHandler::iDelete(const QString &mailbox) | 99 | QString IMAPHandler::iDelete(const QString &mailbox) |
100 | { | 100 | { |
101 | doLogin(); | 101 | doLogin(); |
102 | 102 | ||
103 | _ibase->sendCommand(QString("%1 DELETE \"%2\"\r\n") | 103 | _ibase->sendCommand(QString("%1 DELETE \"%2\"\r\n") |
104 | .arg(tag()) | 104 | .arg(tag()) |
105 | .arg(escape(mailbox))); | 105 | .arg(escape(mailbox))); |
106 | return tag(false); | 106 | return tag(false); |
107 | } | 107 | } |
108 | 108 | ||
109 | QString IMAPHandler::iRename(const QString &mailbox, const QString &newMailbox) | 109 | QString IMAPHandler::iRename(const QString &mailbox, const QString &newMailbox) |
110 | { | 110 | { |
@@ -206,141 +206,141 @@ QString IMAPHandler::iExpunge() | |||
206 | { | 206 | { |
207 | doLogin(); | 207 | doLogin(); |
208 | 208 | ||
209 | _ibase->sendCommand(QString("%1 EXPUNGE\r\n") | 209 | _ibase->sendCommand(QString("%1 EXPUNGE\r\n") |
210 | .arg(tag())); | 210 | .arg(tag())); |
211 | return tag(false); | 211 | return tag(false); |
212 | } | 212 | } |
213 | 213 | ||
214 | QString IMAPHandler::iSearch(const QString &search, const QString &charset) | 214 | QString IMAPHandler::iSearch(const QString &search, const QString &charset) |
215 | { | 215 | { |
216 | doLogin(); | 216 | doLogin(); |
217 | 217 | ||
218 | _ibase->sendCommand(QString("%1 SEARCH %2 %3\r\n") | 218 | _ibase->sendCommand(QString("%1 SEARCH %2 %3\r\n") |
219 | .arg(tag()) | 219 | .arg(tag()) |
220 | .arg(charset.isEmpty() ? QString(0) : escape(charset)) | 220 | .arg(charset.isEmpty() ? QString(0) : escape(charset)) |
221 | .arg(search)); | 221 | .arg(search)); |
222 | return tag(false); | 222 | return tag(false); |
223 | } | 223 | } |
224 | 224 | ||
225 | QString IMAPHandler::iFetch(const QString &message, const QString &items) | 225 | QString IMAPHandler::iFetch(const QString &message, const QString &items) |
226 | { | 226 | { |
227 | doLogin(); | 227 | doLogin(); |
228 | 228 | ||
229 | _ibase->sendCommand(QString("%1 FETCH %2 (%3)\r\n") | 229 | _ibase->sendCommand(QString("%1 FETCH %2 (%3)\r\n") |
230 | .arg(tag()) | 230 | .arg(tag()) |
231 | .arg(message) | 231 | .arg(message) |
232 | .arg(items)); | 232 | .arg(items)); |
233 | return tag(false); | 233 | return tag(false); |
234 | } | 234 | } |
235 | 235 | ||
236 | QString IMAPHandler::iStore(const QString &message, const QString &items) | 236 | QString IMAPHandler::iStore(const QString &message, const QString &items) |
237 | { | 237 | { |
238 | doLogin(); | 238 | doLogin(); |
239 | 239 | ||
240 | _ibase->sendCommand(QString("%1 STORE %2 %3\r\n") | 240 | _ibase->sendCommand(QString("%1 STORE %2 %3\r\n") |
241 | .arg(tag()) | 241 | .arg(tag()) |
242 | .arg(message) | 242 | .arg(message) |
243 | .arg(items)); | 243 | .arg(items)); |
244 | return tag(false); | 244 | return tag(false); |
245 | } | 245 | } |
246 | 246 | ||
247 | QString IMAPHandler::iCopy(const QString &message, const QString &mailbox) | 247 | QString IMAPHandler::iCopy(const QString &message, const QString &mailbox) |
248 | { | 248 | { |
249 | doLogin(); | 249 | doLogin(); |
250 | 250 | ||
251 | _ibase->sendCommand(QString("%1 COPY %2 \"%3\"\r\n") | 251 | _ibase->sendCommand(QString("%1 COPY %2 \"%3\"\r\n") |
252 | .arg(tag()) | 252 | .arg(tag()) |
253 | .arg(message) | 253 | .arg(message) |
254 | .arg(escape(mailbox))); | 254 | .arg(escape(mailbox))); |
255 | return tag(false); | 255 | return tag(false); |
256 | } | 256 | } |
257 | 257 | ||
258 | QString IMAPHandler::iUid(const QString &command, const QString &arguments) | 258 | QString IMAPHandler::iUid(const QString &command, const QString &arguments) |
259 | { | 259 | { |
260 | doLogin(); | 260 | doLogin(); |
261 | 261 | ||
262 | _ibase->sendCommand(QString("%1 UID %2 %3\r\n") | 262 | _ibase->sendCommand(QString("%1 UID %2 %3\r\n") |
263 | .arg(tag()) | 263 | .arg(tag()) |
264 | .arg(command) | 264 | .arg(command) |
265 | .arg(arguments)); | 265 | .arg(arguments)); |
266 | return tag(false); | 266 | return tag(false); |
267 | } | 267 | } |
268 | 268 | ||
269 | QString IMAPHandler::iX(const QString &commandAtom, const QString &arguments) | 269 | QString IMAPHandler::iX(const QString &commandAtom, const QString &arguments) |
270 | { | 270 | { |
271 | doLogin(); | 271 | doLogin(); |
272 | 272 | ||
273 | _ibase->sendCommand(QString("%1 X%2 %3\r\n") | 273 | _ibase->sendCommand(QString("%1 X%2 %3\r\n") |
274 | .arg(tag()) | 274 | .arg(tag()) |
275 | .arg(commandAtom) | 275 | .arg(commandAtom) |
276 | .arg(arguments)); | 276 | .arg(arguments)); |
277 | return tag(false); | 277 | return tag(false); |
278 | } | 278 | } |
279 | 279 | ||
280 | QString IMAPHandler::escape(const QString &in) | 280 | QString IMAPHandler::escape(const QString &in) |
281 | { | 281 | { |
282 | QString in_ = in; | 282 | QString in_ = in; |
283 | return in_.replace(QRegExp("\""), "\\\""); | 283 | return in_.replace(QRegExp("\""), "\\\""); |
284 | } | 284 | } |
285 | 285 | ||
286 | QString IMAPHandler::tag(bool count) | 286 | QString IMAPHandler::tag(bool count) |
287 | { | 287 | { |
288 | return QString("a%1").arg(count ? _tag++ : _tag); | 288 | return QString("a%1").arg(count ? _tag++ : _tag); |
289 | } | 289 | } |
290 | 290 | ||
291 | void IMAPHandler::slotDataReceived(const QString &data) | 291 | void IMAPHandler::slotDataReceived(const QString &data) |
292 | { | 292 | { |
293 | if (!_ready) { | 293 | if (!_ready) { |
294 | // The first data is always the greeting string. | 294 | // The first data is always the greeting string. |
295 | // We can ignore it. | 295 | // We can ignore it. |
296 | _ready = true; | 296 | _ready = true; |
297 | return; | 297 | return; |
298 | } | 298 | } |
299 | 299 | ||
300 | 300 | ||
301 | IMAPResponseParser parser; | 301 | IMAPResponseParser parser; |
302 | //connect ( &parser, SIGNAL( needMoreData ( QString & )), _ibase, SLOT( tryRead ( QString & ))); | 302 | //connect ( &parser, SIGNAL( needMoreData(QString&)), _ibase, SLOT( tryRead(QString&))); |
303 | parser. parse ( data ); | 303 | parser. parse ( data ); |
304 | IMAPResponse response = parser.response(); | 304 | IMAPResponse response = parser.response(); |
305 | //disconnect ( &parser, SIGNAL( needMoreData ( QString & )), _ibase, SLOT( tryRead ( QString & ))); | 305 | //disconnect ( &parser, SIGNAL( needMoreData(QString&)), _ibase, SLOT( tryRead(QString&))); |
306 | response.setImapHandler(this); | 306 | response.setImapHandler(this); |
307 | 307 | ||
308 | if (!_loggingin) { qDebug("Emitting gotResponse!\n" ); emit gotResponse(response); } | 308 | if (!_loggingin) { qDebug("Emitting gotResponse!\n" ); emit gotResponse(response); } |
309 | else { | 309 | else { |
310 | if (response.statusResponse().status() == IMAPResponseEnums::OK) { | 310 | if (response.statusResponse().status() == IMAPResponseEnums::OK) { |
311 | _loggingin = false; | 311 | _loggingin = false; |
312 | _loggedin = true; | 312 | _loggedin = true; |
313 | qWarning("OK. Logged in. Leaving loggingin state."); | 313 | qWarning("OK. Logged in. Leaving loggingin state."); |
314 | } else { | 314 | } else { |
315 | _loggingin = false; | 315 | _loggingin = false; |
316 | emit IMAPError(IMAPBase::IMAPErrLoginFailed); | 316 | emit IMAPError(IMAPBase::IMAPErrLoginFailed); |
317 | } | 317 | } |
318 | } | 318 | } |
319 | } | 319 | } |
320 | 320 | ||
321 | void IMAPHandler::slotLookingUpHost() | 321 | void IMAPHandler::slotLookingUpHost() |
322 | { | 322 | { |
323 | emit IMAPLookingUpHost(); | 323 | emit IMAPLookingUpHost(); |
324 | } | 324 | } |
325 | 325 | ||
326 | void IMAPHandler::slotHostFound() | 326 | void IMAPHandler::slotHostFound() |
327 | { | 327 | { |
328 | emit IMAPHostFound(); | 328 | emit IMAPHostFound(); |
329 | } | 329 | } |
330 | 330 | ||
331 | void IMAPHandler::slotConnected() | 331 | void IMAPHandler::slotConnected() |
332 | { | 332 | { |
333 | emit IMAPConnected(); | 333 | emit IMAPConnected(); |
334 | } | 334 | } |
335 | 335 | ||
336 | void IMAPHandler::slotDisconnected() | 336 | void IMAPHandler::slotDisconnected() |
337 | { | 337 | { |
338 | _loggedin = false; | 338 | _loggedin = false; |
339 | emit IMAPDisconnected(); | 339 | emit IMAPDisconnected(); |
340 | } | 340 | } |
341 | 341 | ||
342 | void IMAPHandler::slotError(int err) | 342 | void IMAPHandler::slotError(int err) |
343 | { | 343 | { |
344 | emit IMAPError(err); | 344 | emit IMAPError(err); |
345 | } | 345 | } |
346 | 346 | ||