Diffstat (limited to 'kmicromail/libmailwrapper/imapwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kmicromail/libmailwrapper/imapwrapper.cpp | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp index 4f0c849..f73f4cc 100644 --- a/kmicromail/libmailwrapper/imapwrapper.cpp +++ b/kmicromail/libmailwrapper/imapwrapper.cpp | |||
@@ -1,33 +1,35 @@ | |||
1 | // CHANGED 2004-09-31 Lutz Rogowski | 1 | // CHANGED 2004-09-31 Lutz Rogowski |
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include <libetpan/libetpan.h> | 3 | #include <libetpan/libetpan.h> |
4 | #include <qpe/global.h> | 4 | #include <qpe/global.h> |
5 | #include <qapplication.h> | 5 | #include <qapplication.h> |
6 | //Added by qt3to4: | ||
7 | #include <Q3ValueList> | ||
6 | #include "imapwrapper.h" | 8 | #include "imapwrapper.h" |
7 | #include "mailtypes.h" | 9 | #include "mailtypes.h" |
8 | #include "logindialog.h" | 10 | #include "logindialog.h" |
9 | #include <qprogressbar.h> | 11 | #include <q3progressbar.h> |
10 | #include "genericwrapper.h" | 12 | #include "genericwrapper.h" |
11 | #include <kglobal.h> | 13 | #include <kglobal.h> |
12 | 14 | ||
13 | using namespace Opie::Core; | 15 | using namespace Opie::Core; |
14 | int IMAPwrapper::mMax = 0; | 16 | int IMAPwrapper::mMax = 0; |
15 | int IMAPwrapper::mCurrent = 0; | 17 | int IMAPwrapper::mCurrent = 0; |
16 | 18 | ||
17 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 19 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
18 | : AbstractMail() | 20 | : AbstractMail() |
19 | { | 21 | { |
20 | account = a; | 22 | account = a; |
21 | m_imap = 0; | 23 | m_imap = 0; |
22 | m_Lastmbox = ""; | 24 | m_Lastmbox = ""; |
23 | mCurrent = 0; | 25 | mCurrent = 0; |
24 | mMax = 0; | 26 | mMax = 0; |
25 | } | 27 | } |
26 | 28 | ||
27 | IMAPwrapper::~IMAPwrapper() | 29 | IMAPwrapper::~IMAPwrapper() |
28 | { | 30 | { |
29 | logout(); | 31 | logout(); |
30 | } | 32 | } |
31 | 33 | ||
32 | /* to avoid to often select statements in loops etc. | 34 | /* to avoid to often select statements in loops etc. |
33 | we trust that we are logged in and connection is established!*/ | 35 | we trust that we are logged in and connection is established!*/ |
@@ -218,49 +220,49 @@ void IMAPwrapper::login(bool tryTLS) // = true) | |||
218 | return; | 220 | return; |
219 | } | 221 | } |
220 | Global::statusMessage(i18n("error logging in imap server: %1").arg(m_imap->imap_response)); | 222 | Global::statusMessage(i18n("error logging in imap server: %1").arg(m_imap->imap_response)); |
221 | ok = false; | 223 | ok = false; |
222 | } | 224 | } |
223 | } | 225 | } |
224 | if (!ok) { | 226 | if (!ok) { |
225 | err = mailimap_close( m_imap ); | 227 | err = mailimap_close( m_imap ); |
226 | mailimap_free( m_imap ); | 228 | mailimap_free( m_imap ); |
227 | m_imap = 0; | 229 | m_imap = 0; |
228 | } | 230 | } |
229 | } | 231 | } |
230 | 232 | ||
231 | void IMAPwrapper::logout() | 233 | void IMAPwrapper::logout() |
232 | { | 234 | { |
233 | int err = MAILIMAP_NO_ERROR; | 235 | int err = MAILIMAP_NO_ERROR; |
234 | if (!m_imap) return; | 236 | if (!m_imap) return; |
235 | err = mailimap_logout( m_imap ); | 237 | err = mailimap_logout( m_imap ); |
236 | err = mailimap_close( m_imap ); | 238 | err = mailimap_close( m_imap ); |
237 | mailimap_free( m_imap ); | 239 | mailimap_free( m_imap ); |
238 | m_imap = 0; | 240 | m_imap = 0; |
239 | m_Lastmbox = ""; | 241 | m_Lastmbox = ""; |
240 | } | 242 | } |
241 | 243 | ||
242 | void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb) | 244 | void IMAPwrapper::listMessages(const QString&mailbox,Q3ValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb) |
243 | { | 245 | { |
244 | 246 | ||
245 | int tryAgain = 1; | 247 | int tryAgain = 1; |
246 | while ( tryAgain >= 0 ) { | 248 | while ( tryAgain >= 0 ) { |
247 | int err = MAILIMAP_NO_ERROR; | 249 | int err = MAILIMAP_NO_ERROR; |
248 | clist *result = 0; | 250 | clist *result = 0; |
249 | clistcell *current; | 251 | clistcell *current; |
250 | mailimap_fetch_type *fetchType = 0; | 252 | mailimap_fetch_type *fetchType = 0; |
251 | mailimap_set *set = 0; | 253 | mailimap_set *set = 0; |
252 | 254 | ||
253 | login(); | 255 | login(); |
254 | if (!m_imap) { | 256 | if (!m_imap) { |
255 | return; | 257 | return; |
256 | } | 258 | } |
257 | /* select mailbox READONLY for operations */ | 259 | /* select mailbox READONLY for operations */ |
258 | err = selectMbox(mailbox); | 260 | err = selectMbox(mailbox); |
259 | if ( err != MAILIMAP_NO_ERROR ) { | 261 | if ( err != MAILIMAP_NO_ERROR ) { |
260 | return; | 262 | return; |
261 | } | 263 | } |
262 | 264 | ||
263 | int last = m_imap->imap_selection_info->sel_exists; | 265 | int last = m_imap->imap_selection_info->sel_exists; |
264 | 266 | ||
265 | if (last == 0) { | 267 | if (last == 0) { |
266 | Global::statusMessage(i18n("Mailbox has no mails")); | 268 | Global::statusMessage(i18n("Mailbox has no mails")); |
@@ -299,58 +301,58 @@ void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSma | |||
299 | RecMail*m = parse_list_result(msg_att); | 301 | RecMail*m = parse_list_result(msg_att); |
300 | if (m) { | 302 | if (m) { |
301 | if ( maxSizeInKb == 0 || m->Msgsize()<=(unsigned int ) maxSizeInKb*1024 ) { | 303 | if ( maxSizeInKb == 0 || m->Msgsize()<=(unsigned int ) maxSizeInKb*1024 ) { |
302 | m->setNumber(i); | 304 | m->setNumber(i); |
303 | m->setMbox(mailbox); | 305 | m->setMbox(mailbox); |
304 | m->setWrapper(this); | 306 | m->setWrapper(this); |
305 | target.append(m); | 307 | target.append(m); |
306 | } | 308 | } |
307 | } | 309 | } |
308 | } | 310 | } |
309 | Global::statusMessage(i18n("Mailbox has %1 mails").arg(target.count())); | 311 | Global::statusMessage(i18n("Mailbox has %1 mails").arg(target.count())); |
310 | } else { | 312 | } else { |
311 | --tryAgain; | 313 | --tryAgain; |
312 | --tryAgain;//disabled tryagain by adding this line | 314 | --tryAgain;//disabled tryagain by adding this line |
313 | if ( tryAgain < 0 ) | 315 | if ( tryAgain < 0 ) |
314 | Global::statusMessage(i18n("Error fetching headers: %1").arg(m_imap->imap_response)); | 316 | Global::statusMessage(i18n("Error fetching headers: %1").arg(m_imap->imap_response)); |
315 | else | 317 | else |
316 | qDebug("try again... "); | 318 | qDebug("try again... "); |
317 | } | 319 | } |
318 | 320 | ||
319 | if (result) mailimap_fetch_list_free(result); | 321 | if (result) mailimap_fetch_list_free(result); |
320 | } | 322 | } |
321 | } | 323 | } |
322 | 324 | ||
323 | QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() | 325 | Q3ValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() |
324 | { | 326 | { |
325 | const char *path, *mask; | 327 | const char *path, *mask; |
326 | int err = MAILIMAP_NO_ERROR; | 328 | int err = MAILIMAP_NO_ERROR; |
327 | clist *result = 0; | 329 | clist *result = 0; |
328 | clistcell *current = 0; | 330 | clistcell *current = 0; |
329 | clistcell*cur_flag = 0; | 331 | clistcell*cur_flag = 0; |
330 | mailimap_mbx_list_flags*bflags = 0; | 332 | mailimap_mbx_list_flags*bflags = 0; |
331 | 333 | ||
332 | QValueList<FolderP>* folders = new QValueList<FolderP>(); | 334 | Q3ValueList<FolderP>* folders = new Q3ValueList<FolderP>(); |
333 | login(); | 335 | login(); |
334 | if (!m_imap) { | 336 | if (!m_imap) { |
335 | return folders; | 337 | return folders; |
336 | } | 338 | } |
337 | 339 | ||
338 | /* | 340 | /* |
339 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 341 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
340 | * We must not forget to filter them out in next loop! | 342 | * We must not forget to filter them out in next loop! |
341 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 343 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
342 | */ | 344 | */ |
343 | Global::statusMessage(i18n("Fetching folder list")); | 345 | Global::statusMessage(i18n("Fetching folder list")); |
344 | qApp->processEvents(); | 346 | qApp->processEvents(); |
345 | QString temp; | 347 | QString temp; |
346 | mask = "INBOX" ; | 348 | mask = "INBOX" ; |
347 | mailimap_mailbox_list *list; | 349 | mailimap_mailbox_list *list; |
348 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 350 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
349 | QString del; | 351 | QString del; |
350 | bool selectable = true; | 352 | bool selectable = true; |
351 | bool no_inferiors = false; | 353 | bool no_inferiors = false; |
352 | if ( err == MAILIMAP_NO_ERROR ) { | 354 | if ( err == MAILIMAP_NO_ERROR ) { |
353 | current = result->first; | 355 | current = result->first; |
354 | for ( int i = result->count; i > 0; i-- ) { | 356 | for ( int i = result->count; i > 0; i-- ) { |
355 | list = (mailimap_mailbox_list *) current->data; | 357 | list = (mailimap_mailbox_list *) current->data; |
356 | // it is better use the deep copy mechanism of qt itself | 358 | // it is better use the deep copy mechanism of qt itself |
@@ -592,49 +594,49 @@ RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail) | |||
592 | 594 | ||
593 | mb = mail->getMbox().latin1(); | 595 | mb = mail->getMbox().latin1(); |
594 | 596 | ||
595 | login(); | 597 | login(); |
596 | if (!m_imap) { | 598 | if (!m_imap) { |
597 | return body; | 599 | return body; |
598 | } | 600 | } |
599 | err = selectMbox(mail->getMbox()); | 601 | err = selectMbox(mail->getMbox()); |
600 | if ( err != MAILIMAP_NO_ERROR ) { | 602 | if ( err != MAILIMAP_NO_ERROR ) { |
601 | return body; | 603 | return body; |
602 | } | 604 | } |
603 | 605 | ||
604 | /* the range has to start at 1!!! not with 0!!!! */ | 606 | /* the range has to start at 1!!! not with 0!!!! */ |
605 | set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); | 607 | set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); |
606 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 608 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
607 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 609 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
608 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 610 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
609 | mailimap_set_free( set ); | 611 | mailimap_set_free( set ); |
610 | mailimap_fetch_type_free( fetchType ); | 612 | mailimap_fetch_type_free( fetchType ); |
611 | 613 | ||
612 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 614 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
613 | mailimap_msg_att * msg_att; | 615 | mailimap_msg_att * msg_att; |
614 | msg_att = (mailimap_msg_att*)current->data; | 616 | msg_att = (mailimap_msg_att*)current->data; |
615 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 617 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
616 | QValueList<int> path; | 618 | Q3ValueList<int> path; |
617 | body_desc = item->att_data.att_static->att_data.att_body; | 619 | body_desc = item->att_data.att_static->att_data.att_body; |
618 | traverseBody(mail,body_desc,body,0,path); | 620 | traverseBody(mail,body_desc,body,0,path); |
619 | } else { | 621 | } else { |
620 | qDebug("error fetching body %d (%d): %s", err, MAILIMAP_NO_ERROR, m_imap->imap_response ); | 622 | qDebug("error fetching body %d (%d): %s", err, MAILIMAP_NO_ERROR, m_imap->imap_response ); |
621 | } | 623 | } |
622 | if (result) mailimap_fetch_list_free(result); | 624 | if (result) mailimap_fetch_list_free(result); |
623 | return body; | 625 | return body; |
624 | } | 626 | } |
625 | 627 | ||
626 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 628 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
627 | { | 629 | { |
628 | QStringList l; | 630 | QStringList l; |
629 | QString from; | 631 | QString from; |
630 | bool named_from; | 632 | bool named_from; |
631 | clistcell *current = NULL; | 633 | clistcell *current = NULL; |
632 | mailimap_address * current_address=NULL; | 634 | mailimap_address * current_address=NULL; |
633 | if (!list) { | 635 | if (!list) { |
634 | return l; | 636 | return l; |
635 | } | 637 | } |
636 | unsigned int count = 0; | 638 | unsigned int count = 0; |
637 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | 639 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
638 | from = ""; | 640 | from = ""; |
639 | named_from = false; | 641 | named_from = false; |
640 | current_address=(mailimap_address*)current->data; | 642 | current_address=(mailimap_address*)current->data; |
@@ -643,49 +645,49 @@ QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | |||
643 | from+=" "; | 645 | from+=" "; |
644 | named_from = true; | 646 | named_from = true; |
645 | } | 647 | } |
646 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 648 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
647 | from+="<"; | 649 | from+="<"; |
648 | } | 650 | } |
649 | if (current_address->ad_mailbox_name) { | 651 | if (current_address->ad_mailbox_name) { |
650 | from+=QString(current_address->ad_mailbox_name); | 652 | from+=QString(current_address->ad_mailbox_name); |
651 | from+="@"; | 653 | from+="@"; |
652 | } | 654 | } |
653 | if (current_address->ad_host_name) { | 655 | if (current_address->ad_host_name) { |
654 | from+=QString(current_address->ad_host_name); | 656 | from+=QString(current_address->ad_host_name); |
655 | } | 657 | } |
656 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 658 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
657 | from+=">"; | 659 | from+=">"; |
658 | } | 660 | } |
659 | l.append(QString(from)); | 661 | l.append(QString(from)); |
660 | if (++count > 99) { | 662 | if (++count > 99) { |
661 | break; | 663 | break; |
662 | } | 664 | } |
663 | } | 665 | } |
664 | return l; | 666 | return l; |
665 | } | 667 | } |
666 | 668 | ||
667 | encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call) | 669 | encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const Q3ValueList<int>&path,bool internal_call) |
668 | { | 670 | { |
669 | encodedString*res=new encodedString; | 671 | encodedString*res=new encodedString; |
670 | int err; | 672 | int err; |
671 | mailimap_fetch_type *fetchType; | 673 | mailimap_fetch_type *fetchType; |
672 | mailimap_set *set; | 674 | mailimap_set *set; |
673 | clistcell*current,*cur; | 675 | clistcell*current,*cur; |
674 | mailimap_section_part * section_part = 0; | 676 | mailimap_section_part * section_part = 0; |
675 | mailimap_section_spec * section_spec = 0; | 677 | mailimap_section_spec * section_spec = 0; |
676 | mailimap_section * section = 0; | 678 | mailimap_section * section = 0; |
677 | mailimap_fetch_att * fetch_att = 0; | 679 | mailimap_fetch_att * fetch_att = 0; |
678 | 680 | ||
679 | login(); | 681 | login(); |
680 | if (!m_imap) { | 682 | if (!m_imap) { |
681 | return res; | 683 | return res; |
682 | } | 684 | } |
683 | if (!internal_call) { | 685 | if (!internal_call) { |
684 | err = selectMbox(mail->getMbox()); | 686 | err = selectMbox(mail->getMbox()); |
685 | if ( err != MAILIMAP_NO_ERROR ) { | 687 | if ( err != MAILIMAP_NO_ERROR ) { |
686 | return res; | 688 | return res; |
687 | } | 689 | } |
688 | } | 690 | } |
689 | set = mailimap_set_new_single(mail->getNumber()); | 691 | set = mailimap_set_new_single(mail->getNumber()); |
690 | 692 | ||
691 | clist*id_list = 0; | 693 | clist*id_list = 0; |
@@ -717,57 +719,57 @@ encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int | |||
717 | mailimap_msg_att * msg_att; | 719 | mailimap_msg_att * msg_att; |
718 | msg_att = (mailimap_msg_att*)current->data; | 720 | msg_att = (mailimap_msg_att*)current->data; |
719 | mailimap_msg_att_item*msg_att_item; | 721 | mailimap_msg_att_item*msg_att_item; |
720 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 722 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
721 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 723 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
722 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 724 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
723 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 725 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
724 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 726 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
725 | /* detach - we take over the content */ | 727 | /* detach - we take over the content */ |
726 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 728 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
727 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); | 729 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); |
728 | } | 730 | } |
729 | } | 731 | } |
730 | } | 732 | } |
731 | } else { | 733 | } else { |
732 | ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl; | 734 | ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl; |
733 | } | 735 | } |
734 | if (result) mailimap_fetch_list_free(result); | 736 | if (result) mailimap_fetch_list_free(result); |
735 | return res; | 737 | return res; |
736 | } | 738 | } |
737 | 739 | ||
738 | /* current_recursion is for recursive calls. | 740 | /* current_recursion is for recursive calls. |
739 | current_count means the position inside the internal loop! */ | 741 | current_count means the position inside the internal loop! */ |
740 | void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body, | 742 | void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body, |
741 | int current_recursion,QValueList<int>recList,int current_count) | 743 | int current_recursion,Q3ValueList<int>recList,int current_count) |
742 | { | 744 | { |
743 | if (!body || current_recursion>=10) { | 745 | if (!body || current_recursion>=10) { |
744 | return; | 746 | return; |
745 | } | 747 | } |
746 | switch (body->bd_type) { | 748 | switch (body->bd_type) { |
747 | case MAILIMAP_BODY_1PART: | 749 | case MAILIMAP_BODY_1PART: |
748 | { | 750 | { |
749 | QValueList<int>countlist = recList; | 751 | Q3ValueList<int>countlist = recList; |
750 | countlist.append(current_count); | 752 | countlist.append(current_count); |
751 | RecPartP currentPart = new RecPart(); | 753 | RecPartP currentPart = new RecPart(); |
752 | mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; | 754 | mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; |
753 | QString id(""); | 755 | QString id(""); |
754 | currentPart->setPositionlist(countlist); | 756 | currentPart->setPositionlist(countlist); |
755 | for (unsigned int j = 0; j < countlist.count();++j) { | 757 | for (unsigned int j = 0; j < countlist.count();++j) { |
756 | id+=(j>0?" ":""); | 758 | id+=(j>0?" ":""); |
757 | id+=QString("%1").arg(countlist[j]); | 759 | id+=QString("%1").arg(countlist[j]); |
758 | } | 760 | } |
759 | //odebug << "ID = " << id.latin1() << "" << oendl; | 761 | //odebug << "ID = " << id.latin1() << "" << oendl; |
760 | currentPart->setIdentifier(id); | 762 | currentPart->setIdentifier(id); |
761 | fillSinglePart(currentPart,part1); | 763 | fillSinglePart(currentPart,part1); |
762 | /* important: Check for is NULL 'cause a body can be empty! | 764 | /* important: Check for is NULL 'cause a body can be empty! |
763 | And we put it only into the mail if it is the FIRST part */ | 765 | And we put it only into the mail if it is the FIRST part */ |
764 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) { | 766 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) { |
765 | QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding()); | 767 | QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding()); |
766 | 768 | ||
767 | size_t index = 0; | 769 | size_t index = 0; |
768 | char*res = 0; | 770 | char*res = 0; |
769 | int err = MAILIMF_NO_ERROR; | 771 | int err = MAILIMF_NO_ERROR; |
770 | 772 | ||
771 | QString charset = currentPart->searchParamter( "charset"); | 773 | QString charset = currentPart->searchParamter( "charset"); |
772 | qDebug("CHARSET %s ",charset.latin1() ); | 774 | qDebug("CHARSET %s ",charset.latin1() ); |
773 | if ( false ) { | 775 | if ( false ) { |
@@ -778,49 +780,49 @@ void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&t | |||
778 | err = mailmime_encoded_phrase_parse(charset.latin1(), | 780 | err = mailmime_encoded_phrase_parse(charset.latin1(), |
779 | body_text.latin1(), body_text.length(),&index, "utf-8",&res); | 781 | body_text.latin1(), body_text.length(),&index, "utf-8",&res); |
780 | if (err == MAILIMF_NO_ERROR && res && strlen(res)) { | 782 | if (err == MAILIMF_NO_ERROR && res && strlen(res)) { |
781 | //qDebug("res %d %s ", index, res); | 783 | //qDebug("res %d %s ", index, res); |
782 | body_text = QString::fromUtf8(res); | 784 | body_text = QString::fromUtf8(res); |
783 | } | 785 | } |
784 | if (res) free(res); | 786 | if (res) free(res); |
785 | } | 787 | } |
786 | //qDebug("encoding %d text %s ",currentPart->Encoding().latin1(), body_text.latin1() ); | 788 | //qDebug("encoding %d text %s ",currentPart->Encoding().latin1(), body_text.latin1() ); |
787 | target_body->setDescription(currentPart); | 789 | target_body->setDescription(currentPart); |
788 | target_body->setBodytext(body_text); | 790 | target_body->setBodytext(body_text); |
789 | if (countlist.count()>1) { | 791 | if (countlist.count()>1) { |
790 | target_body->addPart(currentPart); | 792 | target_body->addPart(currentPart); |
791 | } | 793 | } |
792 | } else { | 794 | } else { |
793 | target_body->addPart(currentPart); | 795 | target_body->addPart(currentPart); |
794 | } | 796 | } |
795 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { | 797 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { |
796 | traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); | 798 | traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); |
797 | } | 799 | } |
798 | } | 800 | } |
799 | break; | 801 | break; |
800 | case MAILIMAP_BODY_MPART: | 802 | case MAILIMAP_BODY_MPART: |
801 | { | 803 | { |
802 | QValueList<int>countlist = recList; | 804 | Q3ValueList<int>countlist = recList; |
803 | clistcell*current=0; | 805 | clistcell*current=0; |
804 | mailimap_body*current_body=0; | 806 | mailimap_body*current_body=0; |
805 | unsigned int ccount = 1; | 807 | unsigned int ccount = 1; |
806 | mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; | 808 | mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; |
807 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 809 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { |
808 | current_body = (mailimap_body*)current->data; | 810 | current_body = (mailimap_body*)current->data; |
809 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 811 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
810 | RecPartP targetPart = new RecPart(); | 812 | RecPartP targetPart = new RecPart(); |
811 | targetPart->setType("multipart"); | 813 | targetPart->setType("multipart"); |
812 | fillMultiPart(targetPart,mailDescription); | 814 | fillMultiPart(targetPart,mailDescription); |
813 | countlist.append(current_count); | 815 | countlist.append(current_count); |
814 | targetPart->setPositionlist(countlist); | 816 | targetPart->setPositionlist(countlist); |
815 | target_body->addPart(targetPart); | 817 | target_body->addPart(targetPart); |
816 | QString id(""); | 818 | QString id(""); |
817 | for (unsigned int j = 0; j < countlist.count();++j) { | 819 | for (unsigned int j = 0; j < countlist.count();++j) { |
818 | id+=(j>0?" ":""); | 820 | id+=(j>0?" ":""); |
819 | id+=QString("%1").arg(countlist[j]); | 821 | id+=QString("%1").arg(countlist[j]); |
820 | } | 822 | } |
821 | // odebug << "ID(mpart) = " << id.latin1() << "" << oendl; | 823 | // odebug << "ID(mpart) = " << id.latin1() << "" << oendl; |
822 | } | 824 | } |
823 | traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); | 825 | traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); |
824 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 826 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
825 | countlist = recList; | 827 | countlist = recList; |
826 | } | 828 | } |
@@ -964,69 +966,69 @@ void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which | |||
964 | case MAILIMAP_BODY_FLD_ENC_BINARY: | 966 | case MAILIMAP_BODY_FLD_ENC_BINARY: |
965 | encoding="binary"; | 967 | encoding="binary"; |
966 | break; | 968 | break; |
967 | case MAILIMAP_BODY_FLD_ENC_BASE64: | 969 | case MAILIMAP_BODY_FLD_ENC_BASE64: |
968 | encoding="base64"; | 970 | encoding="base64"; |
969 | break; | 971 | break; |
970 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: | 972 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: |
971 | encoding="quoted-printable"; | 973 | encoding="quoted-printable"; |
972 | break; | 974 | break; |
973 | case MAILIMAP_BODY_FLD_ENC_OTHER: | 975 | case MAILIMAP_BODY_FLD_ENC_OTHER: |
974 | default: | 976 | default: |
975 | if (enc->enc_value) { | 977 | if (enc->enc_value) { |
976 | char*t=enc->enc_value; | 978 | char*t=enc->enc_value; |
977 | encoding=QString(enc->enc_value); | 979 | encoding=QString(enc->enc_value); |
978 | enc->enc_value=0L; | 980 | enc->enc_value=0L; |
979 | free(t); | 981 | free(t); |
980 | } | 982 | } |
981 | } | 983 | } |
982 | if (which->bd_description) { | 984 | if (which->bd_description) { |
983 | target_part->setDescription(QString(which->bd_description)); | 985 | target_part->setDescription(QString(which->bd_description)); |
984 | } | 986 | } |
985 | target_part->setEncoding(encoding); | 987 | target_part->setEncoding(encoding); |
986 | target_part->setSize(which->bd_size); | 988 | target_part->setSize(which->bd_size); |
987 | } | 989 | } |
988 | void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target) | 990 | void IMAPwrapper::deleteMailList(const Q3ValueList<RecMailP>&target) |
989 | { | 991 | { |
990 | //#if 0 | 992 | //#if 0 |
991 | mailimap_flag_list*flist; | 993 | mailimap_flag_list*flist; |
992 | mailimap_set *set; | 994 | mailimap_set *set; |
993 | mailimap_store_att_flags * store_flags; | 995 | mailimap_store_att_flags * store_flags; |
994 | int err; | 996 | int err; |
995 | login(); | 997 | login(); |
996 | //#endif | 998 | //#endif |
997 | if (!m_imap) { | 999 | if (!m_imap) { |
998 | return; | 1000 | return; |
999 | } | 1001 | } |
1000 | int iii = 0; | 1002 | int iii = 0; |
1001 | int count = target.count(); | 1003 | int count = target.count(); |
1002 | // qDebug("imap remove count %d ", count); | 1004 | // qDebug("imap remove count %d ", count); |
1003 | 1005 | ||
1004 | 1006 | ||
1005 | mMax = count; | 1007 | mMax = count; |
1006 | progress( i18n("Delete")); | 1008 | progress( i18n("Delete")); |
1007 | 1009 | ||
1008 | QProgressBar wid ( count ); | 1010 | Q3ProgressBar wid ( count ); |
1009 | wid.setCaption( i18n("Deleting ...")); | 1011 | wid.setCaption( i18n("Deleting ...")); |
1010 | wid.show(); | 1012 | wid.show(); |
1011 | while (iii < count ) { | 1013 | while (iii < count ) { |
1012 | Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count)); | 1014 | Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count)); |
1013 | wid.setProgress( iii ); | 1015 | wid.setProgress( iii ); |
1014 | wid.raise(); | 1016 | wid.raise(); |
1015 | qApp->processEvents(); | 1017 | qApp->processEvents(); |
1016 | RecMailP mail = (*target.at( iii )); | 1018 | RecMailP mail = (*target.at( iii )); |
1017 | //#if 0 | 1019 | //#if 0 |
1018 | //qDebug("IMAP remove %d %d ", iii, mail->getNumber() ); | 1020 | //qDebug("IMAP remove %d %d ", iii, mail->getNumber() ); |
1019 | err = selectMbox(mail->getMbox()); | 1021 | err = selectMbox(mail->getMbox()); |
1020 | if ( err != MAILIMAP_NO_ERROR ) { | 1022 | if ( err != MAILIMAP_NO_ERROR ) { |
1021 | return; | 1023 | return; |
1022 | } | 1024 | } |
1023 | flist = mailimap_flag_list_new_empty(); | 1025 | flist = mailimap_flag_list_new_empty(); |
1024 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 1026 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
1025 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 1027 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
1026 | set = mailimap_set_new_single(mail->getNumber()); | 1028 | set = mailimap_set_new_single(mail->getNumber()); |
1027 | err = mailimap_store(m_imap,set,store_flags); | 1029 | err = mailimap_store(m_imap,set,store_flags); |
1028 | mailimap_set_free( set ); | 1030 | mailimap_set_free( set ); |
1029 | mailimap_store_att_flags_free(store_flags); | 1031 | mailimap_store_att_flags_free(store_flags); |
1030 | 1032 | ||
1031 | if (err != MAILIMAP_NO_ERROR) { | 1033 | if (err != MAILIMAP_NO_ERROR) { |
1032 | // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; | 1034 | // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; |
@@ -1093,49 +1095,49 @@ void IMAPwrapper::answeredMail(const RecMailP&mail) | |||
1093 | mailimap_store_att_flags * store_flags; | 1095 | mailimap_store_att_flags * store_flags; |
1094 | int err; | 1096 | int err; |
1095 | login(); | 1097 | login(); |
1096 | if (!m_imap) { | 1098 | if (!m_imap) { |
1097 | return; | 1099 | return; |
1098 | } | 1100 | } |
1099 | err = selectMbox(mail->getMbox()); | 1101 | err = selectMbox(mail->getMbox()); |
1100 | if ( err != MAILIMAP_NO_ERROR ) { | 1102 | if ( err != MAILIMAP_NO_ERROR ) { |
1101 | return; | 1103 | return; |
1102 | } | 1104 | } |
1103 | flist = mailimap_flag_list_new_empty(); | 1105 | flist = mailimap_flag_list_new_empty(); |
1104 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); | 1106 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); |
1105 | store_flags = mailimap_store_att_flags_new_add_flags(flist); | 1107 | store_flags = mailimap_store_att_flags_new_add_flags(flist); |
1106 | set = mailimap_set_new_single(mail->getNumber()); | 1108 | set = mailimap_set_new_single(mail->getNumber()); |
1107 | err = mailimap_store(m_imap,set,store_flags); | 1109 | err = mailimap_store(m_imap,set,store_flags); |
1108 | mailimap_set_free( set ); | 1110 | mailimap_set_free( set ); |
1109 | mailimap_store_att_flags_free(store_flags); | 1111 | mailimap_store_att_flags_free(store_flags); |
1110 | 1112 | ||
1111 | if (err != MAILIMAP_NO_ERROR) { | 1113 | if (err != MAILIMAP_NO_ERROR) { |
1112 | // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl; | 1114 | // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl; |
1113 | return; | 1115 | return; |
1114 | } | 1116 | } |
1115 | } | 1117 | } |
1116 | 1118 | ||
1117 | QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc) | 1119 | QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const Q3ValueList<int>&path,bool internal_call,const QString&enc) |
1118 | { | 1120 | { |
1119 | QString body(""); | 1121 | QString body(""); |
1120 | encodedString*res = fetchRawPart(mail,path,internal_call); | 1122 | encodedString*res = fetchRawPart(mail,path,internal_call); |
1121 | encodedString*r = decode_String(res,enc); | 1123 | encodedString*r = decode_String(res,enc); |
1122 | delete res; | 1124 | delete res; |
1123 | if (r) { | 1125 | if (r) { |
1124 | if (r->Length()>0) { | 1126 | if (r->Length()>0) { |
1125 | body = r->Content(); | 1127 | body = r->Content(); |
1126 | } | 1128 | } |
1127 | delete r; | 1129 | delete r; |
1128 | } | 1130 | } |
1129 | return body; | 1131 | return body; |
1130 | } | 1132 | } |
1131 | 1133 | ||
1132 | QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) | 1134 | QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) |
1133 | { | 1135 | { |
1134 | return fetchTextPart(mail,part->Positionlist(),false,part->Encoding()); | 1136 | return fetchTextPart(mail,part->Positionlist(),false,part->Encoding()); |
1135 | } | 1137 | } |
1136 | 1138 | ||
1137 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part) | 1139 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part) |
1138 | { | 1140 | { |
1139 | encodedString*res = fetchRawPart(mail,part->Positionlist(),false); | 1141 | encodedString*res = fetchRawPart(mail,part->Positionlist(),false); |
1140 | encodedString*r = decode_String(res,part->Encoding()); | 1142 | encodedString*r = decode_String(res,part->Encoding()); |
1141 | delete res; | 1143 | delete res; |
@@ -1278,49 +1280,49 @@ void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folde | |||
1278 | { | 1280 | { |
1279 | login(); | 1281 | login(); |
1280 | if (!m_imap) return; | 1282 | if (!m_imap) return; |
1281 | if (!msg) return; | 1283 | if (!msg) return; |
1282 | int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); | 1284 | int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); |
1283 | if (r != MAILIMAP_NO_ERROR) { | 1285 | if (r != MAILIMAP_NO_ERROR) { |
1284 | Global::statusMessage("Error storing mail!"); | 1286 | Global::statusMessage("Error storing mail!"); |
1285 | } | 1287 | } |
1286 | } | 1288 | } |
1287 | 1289 | ||
1288 | MAILLIB::ATYPE IMAPwrapper::getType()const | 1290 | MAILLIB::ATYPE IMAPwrapper::getType()const |
1289 | { | 1291 | { |
1290 | return account->getType(); | 1292 | return account->getType(); |
1291 | } | 1293 | } |
1292 | 1294 | ||
1293 | const QString&IMAPwrapper::getName()const | 1295 | const QString&IMAPwrapper::getName()const |
1294 | { | 1296 | { |
1295 | // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl; | 1297 | // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl; |
1296 | return account->getAccountName(); | 1298 | return account->getAccountName(); |
1297 | } | 1299 | } |
1298 | 1300 | ||
1299 | encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) | 1301 | encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) |
1300 | { | 1302 | { |
1301 | // dummy | 1303 | // dummy |
1302 | QValueList<int> path; | 1304 | Q3ValueList<int> path; |
1303 | return fetchRawPart(mail,path,false); | 1305 | return fetchRawPart(mail,path,false); |
1304 | } | 1306 | } |
1305 | 1307 | ||
1306 | void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, | 1308 | void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, |
1307 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) | 1309 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) |
1308 | { | 1310 | { |
1309 | if (targetWrapper != this || maxSizeInKb > 0 ) { | 1311 | if (targetWrapper != this || maxSizeInKb > 0 ) { |
1310 | mMax = 0; | 1312 | mMax = 0; |
1311 | progress( i18n("Copy")); | 1313 | progress( i18n("Copy")); |
1312 | AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb); | 1314 | AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb); |
1313 | //qDebug("IMAPwrapper::mvcpAllMails::Using generic"); | 1315 | //qDebug("IMAPwrapper::mvcpAllMails::Using generic"); |
1314 | // odebug << "Using generic" << oendl; | 1316 | // odebug << "Using generic" << oendl; |
1315 | return; | 1317 | return; |
1316 | } | 1318 | } |
1317 | mailimap_set *set = 0; | 1319 | mailimap_set *set = 0; |
1318 | login(); | 1320 | login(); |
1319 | if (!m_imap) { | 1321 | if (!m_imap) { |
1320 | return; | 1322 | return; |
1321 | } | 1323 | } |
1322 | int err = selectMbox(fromFolder->getName()); | 1324 | int err = selectMbox(fromFolder->getName()); |
1323 | if ( err != MAILIMAP_NO_ERROR ) { | 1325 | if ( err != MAILIMAP_NO_ERROR ) { |
1324 | return; | 1326 | return; |
1325 | } | 1327 | } |
1326 | Global::statusMessage( i18n("Copying mails on server...") ); | 1328 | Global::statusMessage( i18n("Copying mails on server...") ); |