-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 18 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.h | 3 |
2 files changed, 5 insertions, 16 deletions
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index fe75a15..56efa0b 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -1,141 +1,141 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <libetpan/libetpan.h> | 2 | #include <libetpan/libetpan.h> |
3 | #include <qpe/global.h> | 3 | #include <qpe/global.h> |
4 | #include <opie2/oapplication.h> | 4 | #include <opie2/oapplication.h> |
5 | #include <opie2/odebug.h> | 5 | #include <opie2/odebug.h> |
6 | 6 | ||
7 | #include "imapwrapper.h" | 7 | #include "imapwrapper.h" |
8 | #include "mailtypes.h" | 8 | #include "mailtypes.h" |
9 | #include "logindialog.h" | 9 | #include "logindialog.h" |
10 | 10 | ||
11 | using namespace Opie::Core; | 11 | using namespace Opie::Core; |
12 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 12 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
13 | : AbstractMail() | 13 | : AbstractMail(),MailStatics() |
14 | { | 14 | { |
15 | account = a; | 15 | account = a; |
16 | m_imap = 0; | 16 | m_imap = 0; |
17 | m_Lastmbox = ""; | 17 | m_Lastmbox = ""; |
18 | } | 18 | } |
19 | 19 | ||
20 | IMAPwrapper::~IMAPwrapper() | 20 | IMAPwrapper::~IMAPwrapper() |
21 | { | 21 | { |
22 | logout(); | 22 | logout(); |
23 | } | 23 | } |
24 | 24 | ||
25 | /* to avoid to often select statements in loops etc. | 25 | /* to avoid to often select statements in loops etc. |
26 | we trust that we are logged in and connection is established!*/ | 26 | we trust that we are logged in and connection is established!*/ |
27 | int IMAPwrapper::selectMbox(const QString&mbox) | 27 | int IMAPwrapper::selectMbox(const QString&mbox) |
28 | { | 28 | { |
29 | if (mbox == m_Lastmbox) { | 29 | if (mbox == m_Lastmbox) { |
30 | return MAILIMAP_NO_ERROR; | 30 | return MAILIMAP_NO_ERROR; |
31 | } | 31 | } |
32 | int err = mailimap_select( m_imap, (char*)mbox.latin1()); | 32 | int err = mailimap_select( m_imap, (char*)mbox.latin1()); |
33 | if ( err != MAILIMAP_NO_ERROR ) { | 33 | if ( err != MAILIMAP_NO_ERROR ) { |
34 | odebug << "error selecting mailbox: " << m_imap->imap_response << "" << oendl; | 34 | odebug << "error selecting mailbox: " << m_imap->imap_response << "" << oendl; |
35 | m_Lastmbox = ""; | 35 | m_Lastmbox = ""; |
36 | return err; | 36 | return err; |
37 | } | 37 | } |
38 | m_Lastmbox = mbox; | 38 | m_Lastmbox = mbox; |
39 | return err; | 39 | return err; |
40 | } | 40 | } |
41 | 41 | ||
42 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 42 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) |
43 | { | 43 | { |
44 | qApp->processEvents(); | 44 | qApp->processEvents(); |
45 | odebug << "IMAP: " << current << " of " << maximum << "" << oendl; | 45 | odebug << "IMAP: " << current << " of " << maximum << "" << oendl; |
46 | } | 46 | } |
47 | 47 | ||
48 | bool IMAPwrapper::start_tls(bool force_tls) | 48 | bool IMAPwrapper::start_tls(bool force_tls) |
49 | { | 49 | { |
50 | int err; | 50 | int err; |
51 | bool try_tls; | 51 | bool try_tls; |
52 | mailimap_capability_data * cap_data = 0; | 52 | mailimap_capability_data * cap_data = 0; |
53 | 53 | ||
54 | err = mailimap_capability(m_imap,&cap_data); | 54 | err = mailimap_capability(m_imap,&cap_data); |
55 | if (err != MAILIMAP_NO_ERROR) { | 55 | if (err != MAILIMAP_NO_ERROR) { |
56 | Global::statusMessage("error getting capabilities!"); | 56 | Global::statusMessage("error getting capabilities!"); |
57 | odebug << "error getting capabilities!" << oendl; | 57 | odebug << "error getting capabilities!" << oendl; |
58 | return false; | 58 | return false; |
59 | } | 59 | } |
60 | clistiter * cur; | 60 | clistiter * cur; |
61 | for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { | 61 | for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { |
62 | struct mailimap_capability * cap; | 62 | struct mailimap_capability * cap; |
63 | cap = (struct mailimap_capability *)clist_content(cur); | 63 | cap = (struct mailimap_capability *)clist_content(cur); |
64 | if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { | 64 | if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { |
65 | if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { | 65 | if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { |
66 | try_tls = true; | 66 | try_tls = true; |
67 | break; | 67 | break; |
68 | } | 68 | } |
69 | } | 69 | } |
70 | } | 70 | } |
71 | if (cap_data) { | 71 | if (cap_data) { |
72 | mailimap_capability_data_free(cap_data); | 72 | mailimap_capability_data_free(cap_data); |
73 | } | 73 | } |
74 | if (try_tls) { | 74 | if (try_tls) { |
75 | err = mailimap_starttls(m_imap); | 75 | err = mailimap_starttls(m_imap); |
76 | if (err != MAILIMAP_NO_ERROR && force_tls) { | 76 | if (err != MAILIMAP_NO_ERROR && force_tls) { |
77 | Global::statusMessage(tr("Server has no TLS support!")); | 77 | Global::statusMessage(tr("Server has no TLS support!")); |
78 | odebug << "Server has no TLS support!" << oendl; | 78 | odebug << "Server has no TLS support!" << oendl; |
79 | try_tls = false; | 79 | try_tls = false; |
80 | } else { | 80 | } else { |
81 | mailstream_low * low; | 81 | mailstream_low * low; |
82 | mailstream_low * new_low; | 82 | mailstream_low * new_low; |
83 | low = mailstream_get_low(m_imap->imap_stream); | 83 | low = mailstream_get_low(m_imap->imap_stream); |
84 | if (!low) { | 84 | if (!low) { |
85 | try_tls = false; | 85 | try_tls = false; |
86 | } else { | 86 | } else { |
87 | int fd = mailstream_low_get_fd(low); | 87 | int fd = mailstream_low_get_fd(low); |
88 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { | 88 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { |
89 | mailstream_low_free(low); | 89 | mailstream_low_free(low); |
90 | mailstream_set_low(m_imap->imap_stream, new_low); | 90 | mailstream_set_low(m_imap->imap_stream, new_low); |
91 | } else { | 91 | } else { |
92 | try_tls = false; | 92 | try_tls = false; |
93 | } | 93 | } |
94 | } | 94 | } |
95 | } | 95 | } |
96 | } | 96 | } |
97 | return try_tls; | 97 | return try_tls; |
98 | } | 98 | } |
99 | 99 | ||
100 | void IMAPwrapper::login() | 100 | void IMAPwrapper::login() |
101 | { | 101 | { |
102 | const char *server, *user, *pass; | 102 | const char *server, *user, *pass; |
103 | uint16_t port; | 103 | uint16_t port; |
104 | int err = MAILIMAP_NO_ERROR; | 104 | int err = MAILIMAP_NO_ERROR; |
105 | 105 | ||
106 | if (account->getOffline()) return; | 106 | if (account->getOffline()) return; |
107 | /* we are connected this moment */ | 107 | /* we are connected this moment */ |
108 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 108 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
109 | if (m_imap) { | 109 | if (m_imap) { |
110 | err = mailimap_noop(m_imap); | 110 | err = mailimap_noop(m_imap); |
111 | if (err!=MAILIMAP_NO_ERROR) { | 111 | if (err!=MAILIMAP_NO_ERROR) { |
112 | logout(); | 112 | logout(); |
113 | } else { | 113 | } else { |
114 | mailstream_flush(m_imap->imap_stream); | 114 | mailstream_flush(m_imap->imap_stream); |
115 | return; | 115 | return; |
116 | } | 116 | } |
117 | } | 117 | } |
118 | server = account->getServer().latin1(); | 118 | server = account->getServer().latin1(); |
119 | port = account->getPort().toUInt(); | 119 | port = account->getPort().toUInt(); |
120 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 120 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
121 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 121 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
122 | login.show(); | 122 | login.show(); |
123 | if ( QDialog::Accepted == login.exec() ) { | 123 | if ( QDialog::Accepted == login.exec() ) { |
124 | // ok | 124 | // ok |
125 | user = login.getUser().latin1(); | 125 | user = login.getUser().latin1(); |
126 | pass = login.getPassword().latin1(); | 126 | pass = login.getPassword().latin1(); |
127 | } else { | 127 | } else { |
128 | // cancel | 128 | // cancel |
129 | odebug << "IMAP: Login canceled" << oendl; | 129 | odebug << "IMAP: Login canceled" << oendl; |
130 | return; | 130 | return; |
131 | } | 131 | } |
132 | } else { | 132 | } else { |
133 | user = account->getUser().latin1(); | 133 | user = account->getUser().latin1(); |
134 | pass = account->getPassword().latin1(); | 134 | pass = account->getPassword().latin1(); |
135 | } | 135 | } |
136 | 136 | ||
137 | m_imap = mailimap_new( 20, &imap_progress ); | 137 | m_imap = mailimap_new( 20, &imap_progress ); |
138 | 138 | ||
139 | /* connect */ | 139 | /* connect */ |
140 | bool ssl = false; | 140 | bool ssl = false; |
141 | bool try_tls = false; | 141 | bool try_tls = false; |
@@ -299,312 +299,300 @@ QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() | |||
299 | mailimap_mailbox_list *list; | 299 | mailimap_mailbox_list *list; |
300 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 300 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
301 | QString del; | 301 | QString del; |
302 | bool selectable = true; | 302 | bool selectable = true; |
303 | bool no_inferiors = false; | 303 | bool no_inferiors = false; |
304 | if ( err == MAILIMAP_NO_ERROR ) { | 304 | if ( err == MAILIMAP_NO_ERROR ) { |
305 | current = result->first; | 305 | current = result->first; |
306 | for ( int i = result->count; i > 0; i-- ) { | 306 | for ( int i = result->count; i > 0; i-- ) { |
307 | list = (mailimap_mailbox_list *) current->data; | 307 | list = (mailimap_mailbox_list *) current->data; |
308 | // it is better use the deep copy mechanism of qt itself | 308 | // it is better use the deep copy mechanism of qt itself |
309 | // instead of using strdup! | 309 | // instead of using strdup! |
310 | temp = list->mb_name; | 310 | temp = list->mb_name; |
311 | del = list->mb_delimiter; | 311 | del = list->mb_delimiter; |
312 | current = current->next; | 312 | current = current->next; |
313 | if ( (bflags = list->mb_flag) ) { | 313 | if ( (bflags = list->mb_flag) ) { |
314 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 314 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
315 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 315 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
316 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { | 316 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { |
317 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { | 317 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { |
318 | no_inferiors = true; | 318 | no_inferiors = true; |
319 | } | 319 | } |
320 | } | 320 | } |
321 | } | 321 | } |
322 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | 322 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); |
323 | } | 323 | } |
324 | } else { | 324 | } else { |
325 | odebug << "error fetching folders: " << m_imap->imap_response << "" << oendl; | 325 | odebug << "error fetching folders: " << m_imap->imap_response << "" << oendl; |
326 | } | 326 | } |
327 | mailimap_list_result_free( result ); | 327 | mailimap_list_result_free( result ); |
328 | 328 | ||
329 | /* | 329 | /* |
330 | * second stage - get the other then inbox folders | 330 | * second stage - get the other then inbox folders |
331 | */ | 331 | */ |
332 | mask = "*" ; | 332 | mask = "*" ; |
333 | path = account->getPrefix().latin1(); | 333 | path = account->getPrefix().latin1(); |
334 | if (!path) path = ""; | 334 | if (!path) path = ""; |
335 | odebug << path << oendl; | 335 | odebug << path << oendl; |
336 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 336 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
337 | if ( err == MAILIMAP_NO_ERROR ) { | 337 | if ( err == MAILIMAP_NO_ERROR ) { |
338 | current = result->first; | 338 | current = result->first; |
339 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | 339 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { |
340 | no_inferiors = false; | 340 | no_inferiors = false; |
341 | list = (mailimap_mailbox_list *) current->data; | 341 | list = (mailimap_mailbox_list *) current->data; |
342 | // it is better use the deep copy mechanism of qt itself | 342 | // it is better use the deep copy mechanism of qt itself |
343 | // instead of using strdup! | 343 | // instead of using strdup! |
344 | temp = list->mb_name; | 344 | temp = list->mb_name; |
345 | if (temp.lower()=="inbox") | 345 | if (temp.lower()=="inbox") |
346 | continue; | 346 | continue; |
347 | if (temp.lower()==account->getPrefix().lower()) | 347 | if (temp.lower()==account->getPrefix().lower()) |
348 | continue; | 348 | continue; |
349 | if ( (bflags = list->mb_flag) ) { | 349 | if ( (bflags = list->mb_flag) ) { |
350 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 350 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
351 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 351 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
352 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { | 352 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { |
353 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { | 353 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { |
354 | no_inferiors = true; | 354 | no_inferiors = true; |
355 | } | 355 | } |
356 | } | 356 | } |
357 | } | 357 | } |
358 | del = list->mb_delimiter; | 358 | del = list->mb_delimiter; |
359 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | 359 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); |
360 | } | 360 | } |
361 | } else { | 361 | } else { |
362 | odebug << "error fetching folders " << m_imap->imap_response << "" << oendl; | 362 | odebug << "error fetching folders " << m_imap->imap_response << "" << oendl; |
363 | } | 363 | } |
364 | if (result) mailimap_list_result_free( result ); | 364 | if (result) mailimap_list_result_free( result ); |
365 | return folders; | 365 | return folders; |
366 | } | 366 | } |
367 | 367 | ||
368 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 368 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
369 | { | 369 | { |
370 | RecMail * m = 0; | 370 | RecMail * m = 0; |
371 | mailimap_msg_att_item *item=0; | 371 | mailimap_msg_att_item *item=0; |
372 | clistcell *current,*c,*cf; | 372 | clistcell *current,*c,*cf; |
373 | mailimap_msg_att_dynamic*flist; | 373 | mailimap_msg_att_dynamic*flist; |
374 | mailimap_flag_fetch*cflag; | 374 | mailimap_flag_fetch*cflag; |
375 | int size; | 375 | int size; |
376 | QBitArray mFlags(7); | 376 | QBitArray mFlags(7); |
377 | QStringList addresslist; | 377 | QStringList addresslist; |
378 | 378 | ||
379 | if (!m_att) { | 379 | if (!m_att) { |
380 | return m; | 380 | return m; |
381 | } | 381 | } |
382 | size = 0; | 382 | size = 0; |
383 | m = new RecMail(); | 383 | m = new RecMail(); |
384 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { | 384 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { |
385 | current = c; | 385 | current = c; |
386 | item = (mailimap_msg_att_item*)current->data; | 386 | item = (mailimap_msg_att_item*)current->data; |
387 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 387 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
388 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; | 388 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; |
389 | if (!flist->att_list) { | 389 | if (!flist->att_list) { |
390 | continue; | 390 | continue; |
391 | } | 391 | } |
392 | cf = flist->att_list->first; | 392 | cf = flist->att_list->first; |
393 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { | 393 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { |
394 | cflag = (mailimap_flag_fetch*)cf->data; | 394 | cflag = (mailimap_flag_fetch*)cf->data; |
395 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { | 395 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { |
396 | switch (cflag->fl_flag->fl_type) { | 396 | switch (cflag->fl_flag->fl_type) { |
397 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 397 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
398 | mFlags.setBit(FLAG_ANSWERED); | 398 | mFlags.setBit(FLAG_ANSWERED); |
399 | break; | 399 | break; |
400 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 400 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
401 | mFlags.setBit(FLAG_FLAGGED); | 401 | mFlags.setBit(FLAG_FLAGGED); |
402 | break; | 402 | break; |
403 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 403 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
404 | mFlags.setBit(FLAG_DELETED); | 404 | mFlags.setBit(FLAG_DELETED); |
405 | break; | 405 | break; |
406 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 406 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
407 | mFlags.setBit(FLAG_SEEN); | 407 | mFlags.setBit(FLAG_SEEN); |
408 | break; | 408 | break; |
409 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 409 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
410 | mFlags.setBit(FLAG_DRAFT); | 410 | mFlags.setBit(FLAG_DRAFT); |
411 | break; | 411 | break; |
412 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 412 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
413 | break; | 413 | break; |
414 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 414 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
415 | break; | 415 | break; |
416 | default: | 416 | default: |
417 | break; | 417 | break; |
418 | } | 418 | } |
419 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | 419 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { |
420 | mFlags.setBit(FLAG_RECENT); | 420 | mFlags.setBit(FLAG_RECENT); |
421 | } | 421 | } |
422 | } | 422 | } |
423 | continue; | 423 | continue; |
424 | } | 424 | } |
425 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { | 425 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { |
426 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; | 426 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; |
427 | m->setDate(head->env_date); | 427 | m->setDate(parseDateTime(head->env_date)); |
428 | m->setSubject(convert_String((const char*)head->env_subject)); | 428 | m->setSubject(convert_String((const char*)head->env_subject)); |
429 | //m->setSubject(head->env_subject); | ||
430 | if (head->env_from!=NULL) { | 429 | if (head->env_from!=NULL) { |
431 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | 430 | addresslist = address_list_to_stringlist(head->env_from->frm_list); |
432 | if (addresslist.count()) { | 431 | if (addresslist.count()) { |
433 | m->setFrom(addresslist.first()); | 432 | m->setFrom(addresslist.first()); |
434 | } | 433 | } |
435 | } | 434 | } |
436 | if (head->env_to!=NULL) { | 435 | if (head->env_to!=NULL) { |
437 | addresslist = address_list_to_stringlist(head->env_to->to_list); | 436 | addresslist = address_list_to_stringlist(head->env_to->to_list); |
438 | m->setTo(addresslist); | 437 | m->setTo(addresslist); |
439 | } | 438 | } |
440 | if (head->env_cc!=NULL) { | 439 | if (head->env_cc!=NULL) { |
441 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); | 440 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); |
442 | m->setCC(addresslist); | 441 | m->setCC(addresslist); |
443 | } | 442 | } |
444 | if (head->env_bcc!=NULL) { | 443 | if (head->env_bcc!=NULL) { |
445 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); | 444 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); |
446 | m->setBcc(addresslist); | 445 | m->setBcc(addresslist); |
447 | } | 446 | } |
448 | /* reply to address, eg. email. */ | 447 | /* reply to address, eg. email. */ |
449 | if (head->env_reply_to!=NULL) { | 448 | if (head->env_reply_to!=NULL) { |
450 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | 449 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); |
451 | if (addresslist.count()) { | 450 | if (addresslist.count()) { |
452 | m->setReplyto(addresslist.first()); | 451 | m->setReplyto(addresslist.first()); |
453 | } | 452 | } |
454 | } | 453 | } |
455 | if (head->env_in_reply_to!=NULL) { | 454 | if (head->env_in_reply_to!=NULL) { |
456 | QString h(head->env_in_reply_to); | 455 | QString h(head->env_in_reply_to); |
457 | while (h.length()>0 && h[0]=='<') { | 456 | while (h.length()>0 && h[0]=='<') { |
458 | h.remove(0,1); | 457 | h.remove(0,1); |
459 | } | 458 | } |
460 | while (h.length()>0 && h[h.length()-1]=='>') { | 459 | while (h.length()>0 && h[h.length()-1]=='>') { |
461 | h.remove(h.length()-1,1); | 460 | h.remove(h.length()-1,1); |
462 | } | 461 | } |
463 | if (h.length()>0) { | 462 | if (h.length()>0) { |
464 | m->setInreply(QStringList(h)); | 463 | m->setInreply(QStringList(h)); |
465 | } | 464 | } |
466 | } | 465 | } |
467 | if (head->env_message_id) { | 466 | if (head->env_message_id) { |
468 | m->setMsgid(QString(head->env_message_id)); | 467 | m->setMsgid(QString(head->env_message_id)); |
469 | } | 468 | } |
470 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 469 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
471 | #if 0 | 470 | // not used this moment |
472 | mailimap_date_time*date = item->att_data.att_static->att_data.att_internal_date; | ||
473 | if (date->dt_sec>60 || date->dt_sec<0) date->dt_sec=0; | ||
474 | //QDateTime da(QDate(d->dt_year,date->dt_month,date->dt_day),QTime(date->dt_hour,date->dt_min,date->dt_sec)); | ||
475 | QString timestring = TimeString::numberDateString(QDate(date->dt_year,date->dt_month,date->dt_day))+" "; | ||
476 | timestring+=TimeString::timeString(QTime(date->dt_hour,date->dt_min,date->dt_sec))+" "; | ||
477 | timestring.sprintf(timestring+" %+05i",date->dt_zone); | ||
478 | m->setDate(timestring); | ||
479 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | ||
480 | odebug << "" << d->dt_year << " " << d->dt_month << " " << d->dt_day << " - " << d->dt_hour << " " << d->dt_min << " " << d->dt_sec << "" << oendl; | ||
481 | odebug << da.toString() << oendl; | ||
482 | #endif | ||
483 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 471 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
484 | //size = item->att_data.att_static->att_data.att_rfc822_size; | 472 | //size = item->att_data.att_static->att_data.att_rfc822_size; |
485 | m->setMsgsize(item->att_data.att_static->att_data.att_rfc822_size); | 473 | m->setMsgsize(item->att_data.att_static->att_data.att_rfc822_size); |
486 | } | 474 | } |
487 | } | 475 | } |
488 | /* msg is already deleted */ | 476 | /* msg is already deleted */ |
489 | if (mFlags.testBit(FLAG_DELETED) && m) { | 477 | if (mFlags.testBit(FLAG_DELETED) && m) { |
490 | delete m; | 478 | delete m; |
491 | m = 0; | 479 | m = 0; |
492 | } | 480 | } |
493 | if (m) { | 481 | if (m) { |
494 | m->setFlags(mFlags); | 482 | m->setFlags(mFlags); |
495 | } | 483 | } |
496 | return m; | 484 | return m; |
497 | } | 485 | } |
498 | 486 | ||
499 | RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail) | 487 | RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail) |
500 | { | 488 | { |
501 | RecBodyP body = new RecBody(); | 489 | RecBodyP body = new RecBody(); |
502 | const char *mb; | 490 | const char *mb; |
503 | int err = MAILIMAP_NO_ERROR; | 491 | int err = MAILIMAP_NO_ERROR; |
504 | clist *result = 0; | 492 | clist *result = 0; |
505 | clistcell *current; | 493 | clistcell *current; |
506 | mailimap_fetch_att *fetchAtt = 0; | 494 | mailimap_fetch_att *fetchAtt = 0; |
507 | mailimap_fetch_type *fetchType = 0; | 495 | mailimap_fetch_type *fetchType = 0; |
508 | mailimap_set *set = 0; | 496 | mailimap_set *set = 0; |
509 | mailimap_body*body_desc = 0; | 497 | mailimap_body*body_desc = 0; |
510 | 498 | ||
511 | mb = mail->getMbox().latin1(); | 499 | mb = mail->getMbox().latin1(); |
512 | 500 | ||
513 | login(); | 501 | login(); |
514 | if (!m_imap) { | 502 | if (!m_imap) { |
515 | return body; | 503 | return body; |
516 | } | 504 | } |
517 | err = selectMbox(mail->getMbox()); | 505 | err = selectMbox(mail->getMbox()); |
518 | if ( err != MAILIMAP_NO_ERROR ) { | 506 | if ( err != MAILIMAP_NO_ERROR ) { |
519 | return body; | 507 | return body; |
520 | } | 508 | } |
521 | 509 | ||
522 | /* the range has to start at 1!!! not with 0!!!! */ | 510 | /* the range has to start at 1!!! not with 0!!!! */ |
523 | set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); | 511 | set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); |
524 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 512 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
525 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 513 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
526 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 514 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
527 | mailimap_set_free( set ); | 515 | mailimap_set_free( set ); |
528 | mailimap_fetch_type_free( fetchType ); | 516 | mailimap_fetch_type_free( fetchType ); |
529 | 517 | ||
530 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 518 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
531 | mailimap_msg_att * msg_att; | 519 | mailimap_msg_att * msg_att; |
532 | msg_att = (mailimap_msg_att*)current->data; | 520 | msg_att = (mailimap_msg_att*)current->data; |
533 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 521 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
534 | QValueList<int> path; | 522 | QValueList<int> path; |
535 | body_desc = item->att_data.att_static->att_data.att_body; | 523 | body_desc = item->att_data.att_static->att_data.att_body; |
536 | traverseBody(mail,body_desc,body,0,path); | 524 | traverseBody(mail,body_desc,body,0,path); |
537 | } else { | 525 | } else { |
538 | odebug << "error fetching body: " << m_imap->imap_response << "" << oendl; | 526 | odebug << "error fetching body: " << m_imap->imap_response << "" << oendl; |
539 | } | 527 | } |
540 | if (result) mailimap_fetch_list_free(result); | 528 | if (result) mailimap_fetch_list_free(result); |
541 | return body; | 529 | return body; |
542 | } | 530 | } |
543 | 531 | ||
544 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 532 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
545 | { | 533 | { |
546 | QStringList l; | 534 | QStringList l; |
547 | QString from; | 535 | QString from; |
548 | bool named_from; | 536 | bool named_from; |
549 | clistcell *current = NULL; | 537 | clistcell *current = NULL; |
550 | mailimap_address * current_address=NULL; | 538 | mailimap_address * current_address=NULL; |
551 | if (!list) { | 539 | if (!list) { |
552 | return l; | 540 | return l; |
553 | } | 541 | } |
554 | unsigned int count = 0; | 542 | unsigned int count = 0; |
555 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | 543 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
556 | from = ""; | 544 | from = ""; |
557 | named_from = false; | 545 | named_from = false; |
558 | current_address=(mailimap_address*)current->data; | 546 | current_address=(mailimap_address*)current->data; |
559 | if (current_address->ad_personal_name){ | 547 | if (current_address->ad_personal_name){ |
560 | from+=convert_String((const char*)current_address->ad_personal_name); | 548 | from+=convert_String((const char*)current_address->ad_personal_name); |
561 | from+=" "; | 549 | from+=" "; |
562 | named_from = true; | 550 | named_from = true; |
563 | } | 551 | } |
564 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 552 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
565 | from+="<"; | 553 | from+="<"; |
566 | } | 554 | } |
567 | if (current_address->ad_mailbox_name) { | 555 | if (current_address->ad_mailbox_name) { |
568 | from+=QString(current_address->ad_mailbox_name); | 556 | from+=QString(current_address->ad_mailbox_name); |
569 | from+="@"; | 557 | from+="@"; |
570 | } | 558 | } |
571 | if (current_address->ad_host_name) { | 559 | if (current_address->ad_host_name) { |
572 | from+=QString(current_address->ad_host_name); | 560 | from+=QString(current_address->ad_host_name); |
573 | } | 561 | } |
574 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 562 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
575 | from+=">"; | 563 | from+=">"; |
576 | } | 564 | } |
577 | l.append(QString(from)); | 565 | l.append(QString(from)); |
578 | if (++count > 99) { | 566 | if (++count > 99) { |
579 | break; | 567 | break; |
580 | } | 568 | } |
581 | } | 569 | } |
582 | return l; | 570 | return l; |
583 | } | 571 | } |
584 | 572 | ||
585 | encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call) | 573 | encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call) |
586 | { | 574 | { |
587 | encodedString*res=new encodedString; | 575 | encodedString*res=new encodedString; |
588 | int err; | 576 | int err; |
589 | mailimap_fetch_type *fetchType; | 577 | mailimap_fetch_type *fetchType; |
590 | mailimap_set *set; | 578 | mailimap_set *set; |
591 | clistcell*current,*cur; | 579 | clistcell*current,*cur; |
592 | mailimap_section_part * section_part = 0; | 580 | mailimap_section_part * section_part = 0; |
593 | mailimap_section_spec * section_spec = 0; | 581 | mailimap_section_spec * section_spec = 0; |
594 | mailimap_section * section = 0; | 582 | mailimap_section * section = 0; |
595 | mailimap_fetch_att * fetch_att = 0; | 583 | mailimap_fetch_att * fetch_att = 0; |
596 | 584 | ||
597 | login(); | 585 | login(); |
598 | if (!m_imap) { | 586 | if (!m_imap) { |
599 | return res; | 587 | return res; |
600 | } | 588 | } |
601 | if (!internal_call) { | 589 | if (!internal_call) { |
602 | err = selectMbox(mail->getMbox()); | 590 | err = selectMbox(mail->getMbox()); |
603 | if ( err != MAILIMAP_NO_ERROR ) { | 591 | if ( err != MAILIMAP_NO_ERROR ) { |
604 | return res; | 592 | return res; |
605 | } | 593 | } |
606 | } | 594 | } |
607 | set = mailimap_set_new_single(mail->getNumber()); | 595 | set = mailimap_set_new_single(mail->getNumber()); |
608 | 596 | ||
609 | clist*id_list = 0; | 597 | clist*id_list = 0; |
610 | 598 | ||
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h index e56605a..5efcfc9 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.h +++ b/noncore/net/mail/libmailwrapper/imapwrapper.h | |||
@@ -1,80 +1,81 @@ | |||
1 | #ifndef __IMAPWRAPPER | 1 | #ifndef __IMAPWRAPPER |
2 | #define __IMAPWRAPPER | 2 | #define __IMAPWRAPPER |
3 | 3 | ||
4 | #include <qlist.h> | 4 | #include <qlist.h> |
5 | #include "mailwrapper.h" | 5 | #include "mailwrapper.h" |
6 | #include "abstractmail.h" | 6 | #include "abstractmail.h" |
7 | #include "mailstatics.h" | ||
7 | #include <libetpan/clist.h> | 8 | #include <libetpan/clist.h> |
8 | 9 | ||
9 | struct mailimap; | 10 | struct mailimap; |
10 | struct mailimap_body; | 11 | struct mailimap_body; |
11 | struct mailimap_body_type_1part; | 12 | struct mailimap_body_type_1part; |
12 | struct mailimap_body_type_text; | 13 | struct mailimap_body_type_text; |
13 | struct mailimap_body_type_basic; | 14 | struct mailimap_body_type_basic; |
14 | struct mailimap_body_type_msg; | 15 | struct mailimap_body_type_msg; |
15 | struct mailimap_body_type_mpart; | 16 | struct mailimap_body_type_mpart; |
16 | struct mailimap_body_fields; | 17 | struct mailimap_body_fields; |
17 | struct mailimap_msg_att; | 18 | struct mailimap_msg_att; |
18 | class encodedString; | 19 | class encodedString; |
19 | 20 | ||
20 | class IMAPwrapper : public AbstractMail | 21 | class IMAPwrapper : public AbstractMail,public MailStatics |
21 | { | 22 | { |
22 | Q_OBJECT | 23 | Q_OBJECT |
23 | public: | 24 | public: |
24 | IMAPwrapper( IMAPaccount *a ); | 25 | IMAPwrapper( IMAPaccount *a ); |
25 | virtual ~IMAPwrapper(); | 26 | virtual ~IMAPwrapper(); |
26 | virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); | 27 | virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); |
27 | virtual void listMessages(const QString & mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> >&target ); | 28 | virtual void listMessages(const QString & mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> >&target ); |
28 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); | 29 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); |
29 | 30 | ||
30 | virtual void deleteMail(const RecMailP&mail); | 31 | virtual void deleteMail(const RecMailP&mail); |
31 | virtual void answeredMail(const RecMailP&mail); | 32 | virtual void answeredMail(const RecMailP&mail); |
32 | virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&folder); | 33 | virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&folder); |
33 | virtual void storeMessage(const char*msg,size_t length, const QString&folder); | 34 | virtual void storeMessage(const char*msg,size_t length, const QString&folder); |
34 | virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder, | 35 | virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder, |
35 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); | 36 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); |
36 | virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); | 37 | virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); |
37 | 38 | ||
38 | virtual RecBodyP fetchBody(const RecMailP&mail); | 39 | virtual RecBodyP fetchBody(const RecMailP&mail); |
39 | virtual QString fetchTextPart(const RecMailP&mail,const RecPartP&part); | 40 | virtual QString fetchTextPart(const RecMailP&mail,const RecPartP&part); |
40 | virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPartP&part); | 41 | virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPartP&part); |
41 | virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPartP&part); | 42 | virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPartP&part); |
42 | virtual encodedString* fetchRawBody(const RecMailP&mail); | 43 | virtual encodedString* fetchRawBody(const RecMailP&mail); |
43 | 44 | ||
44 | virtual int createMbox(const QString&,const Opie::Core::OSmartPointer<Folder>&parentfolder=0, | 45 | virtual int createMbox(const QString&,const Opie::Core::OSmartPointer<Folder>&parentfolder=0, |
45 | const QString& delemiter="/",bool getsubfolder=false); | 46 | const QString& delemiter="/",bool getsubfolder=false); |
46 | virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&folder); | 47 | virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&folder); |
47 | 48 | ||
48 | static void imap_progress( size_t current, size_t maximum ); | 49 | static void imap_progress( size_t current, size_t maximum ); |
49 | 50 | ||
50 | virtual void logout(); | 51 | virtual void logout(); |
51 | virtual MAILLIB::ATYPE getType()const; | 52 | virtual MAILLIB::ATYPE getType()const; |
52 | virtual const QString&getName()const; | 53 | virtual const QString&getName()const; |
53 | 54 | ||
54 | protected: | 55 | protected: |
55 | RecMail*parse_list_result(mailimap_msg_att*); | 56 | RecMail*parse_list_result(mailimap_msg_att*); |
56 | void login(); | 57 | void login(); |
57 | bool start_tls(bool force=true); | 58 | bool start_tls(bool force=true); |
58 | 59 | ||
59 | virtual QString fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); | 60 | virtual QString fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); |
60 | virtual encodedString*fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call); | 61 | virtual encodedString*fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call); |
61 | int selectMbox(const QString&mbox); | 62 | int selectMbox(const QString&mbox); |
62 | 63 | ||
63 | void fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description); | 64 | void fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description); |
64 | void fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which); | 65 | void fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which); |
65 | void fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which); | 66 | void fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which); |
66 | void fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which); | 67 | void fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which); |
67 | void fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which); | 68 | void fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which); |
68 | void traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body,int current_recursion,QValueList<int>recList,int current_count=1); | 69 | void traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body,int current_recursion,QValueList<int>recList,int current_count=1); |
69 | 70 | ||
70 | /* just helpers */ | 71 | /* just helpers */ |
71 | static void fillBodyFields(RecPartP&target_part,mailimap_body_fields*which); | 72 | static void fillBodyFields(RecPartP&target_part,mailimap_body_fields*which); |
72 | static QStringList address_list_to_stringlist(clist*list); | 73 | static QStringList address_list_to_stringlist(clist*list); |
73 | 74 | ||
74 | 75 | ||
75 | IMAPaccount *account; | 76 | IMAPaccount *account; |
76 | mailimap *m_imap; | 77 | mailimap *m_imap; |
77 | QString m_Lastmbox; | 78 | QString m_Lastmbox; |
78 | }; | 79 | }; |
79 | 80 | ||
80 | #endif | 81 | #endif |