author | alwin <alwin> | 2004-01-08 12:26:29 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-01-08 12:26:29 (UTC) |
commit | b85bc4484bcc0a53557b4759c3e9e58dc9059138 (patch) (unidiff) | |
tree | 16fa84076bc8f2e3125db815db3c2628286e62f1 | |
parent | 3cb4363abdb17d2898b4792390672375ffcd2493 (diff) | |
download | opie-b85bc4484bcc0a53557b4759c3e9e58dc9059138.zip opie-b85bc4484bcc0a53557b4759c3e9e58dc9059138.tar.gz opie-b85bc4484bcc0a53557b4759c3e9e58dc9059138.tar.bz2 |
last selected mbox will hold so it will not called so often in outside loops
(it could cause segmentation faults, too - there is another bug in libetpan
I didn't found yet)
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 63 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.h | 4 |
2 files changed, 38 insertions, 29 deletions
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index 23c678b..98634a3 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -6,23 +6,41 @@ | |||
6 | #include "mailtypes.h" | 6 | #include "mailtypes.h" |
7 | #include "logindialog.h" | 7 | #include "logindialog.h" |
8 | 8 | ||
9 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 9 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
10 | : AbstractMail() | 10 | : AbstractMail() |
11 | { | 11 | { |
12 | account = a; | 12 | account = a; |
13 | m_imap = 0; | 13 | m_imap = 0; |
14 | m_Lastmbox = ""; | ||
14 | } | 15 | } |
15 | 16 | ||
16 | IMAPwrapper::~IMAPwrapper() | 17 | IMAPwrapper::~IMAPwrapper() |
17 | { | 18 | { |
18 | logout(); | 19 | logout(); |
19 | } | 20 | } |
20 | 21 | ||
22 | /* to avoid to often select statements in loops etc. | ||
23 | we trust that we are logged in and connection is established!*/ | ||
24 | int IMAPwrapper::selectMbox(const QString&mbox) | ||
25 | { | ||
26 | if (mbox == m_Lastmbox) { | ||
27 | return MAILIMAP_NO_ERROR; | ||
28 | } | ||
29 | int err = mailimap_select( m_imap, (char*)mbox.latin1()); | ||
30 | if ( err != MAILIMAP_NO_ERROR ) { | ||
31 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | ||
32 | m_Lastmbox = ""; | ||
33 | return err; | ||
34 | } | ||
35 | m_Lastmbox = mbox; | ||
36 | return err; | ||
37 | } | ||
38 | |||
21 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 39 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) |
22 | { | 40 | { |
23 | qDebug( "IMAP: %i of %i", current, maximum ); | 41 | qDebug( "IMAP: %i of %i", current, maximum ); |
24 | } | 42 | } |
25 | 43 | ||
26 | void IMAPwrapper::login() | 44 | void IMAPwrapper::login() |
27 | { | 45 | { |
28 | const char *server, *user, *pass; | 46 | const char *server, *user, *pass; |
@@ -97,37 +115,34 @@ void IMAPwrapper::login() | |||
97 | void IMAPwrapper::logout() | 115 | void IMAPwrapper::logout() |
98 | { | 116 | { |
99 | int err = MAILIMAP_NO_ERROR; | 117 | int err = MAILIMAP_NO_ERROR; |
100 | if (!m_imap) return; | 118 | if (!m_imap) return; |
101 | err = mailimap_logout( m_imap ); | 119 | err = mailimap_logout( m_imap ); |
102 | err = mailimap_close( m_imap ); | 120 | err = mailimap_close( m_imap ); |
103 | mailimap_free( m_imap ); | 121 | mailimap_free( m_imap ); |
104 | m_imap = 0; | 122 | m_imap = 0; |
123 | m_Lastmbox = ""; | ||
105 | } | 124 | } |
106 | 125 | ||
107 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) | 126 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) |
108 | { | 127 | { |
109 | const char *mb = 0; | ||
110 | int err = MAILIMAP_NO_ERROR; | 128 | int err = MAILIMAP_NO_ERROR; |
111 | clist *result = 0; | 129 | clist *result = 0; |
112 | clistcell *current; | 130 | clistcell *current; |
113 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; | ||
114 | mailimap_fetch_type *fetchType = 0; | 131 | mailimap_fetch_type *fetchType = 0; |
115 | mailimap_set *set = 0; | 132 | mailimap_set *set = 0; |
116 | 133 | ||
117 | mb = mailbox.latin1(); | ||
118 | login(); | 134 | login(); |
119 | if (!m_imap) { | 135 | if (!m_imap) { |
120 | return; | 136 | return; |
121 | } | 137 | } |
122 | /* select mailbox READONLY for operations */ | 138 | /* select mailbox READONLY for operations */ |
123 | err = mailimap_examine( m_imap, (char*)mb); | 139 | err = selectMbox(mailbox); |
124 | if ( err != MAILIMAP_NO_ERROR ) { | 140 | if ( err != MAILIMAP_NO_ERROR ) { |
125 | Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response)); | ||
126 | return; | 141 | return; |
127 | } | 142 | } |
128 | 143 | ||
129 | int last = m_imap->imap_selection_info->sel_exists; | 144 | int last = m_imap->imap_selection_info->sel_exists; |
130 | 145 | ||
131 | if (last == 0) { | 146 | if (last == 0) { |
132 | Global::statusMessage(tr("Mailbox has no mails")); | 147 | Global::statusMessage(tr("Mailbox has no mails")); |
133 | return; | 148 | return; |
@@ -384,20 +399,18 @@ RecBody IMAPwrapper::fetchBody(const RecMail&mail) | |||
384 | mailimap_body*body_desc = 0; | 399 | mailimap_body*body_desc = 0; |
385 | 400 | ||
386 | mb = mail.getMbox().latin1(); | 401 | mb = mail.getMbox().latin1(); |
387 | 402 | ||
388 | login(); | 403 | login(); |
389 | if (!m_imap) { | 404 | if (!m_imap) { |
390 | return body; | 405 | return body; |
391 | } | 406 | } |
392 | 407 | err = selectMbox(mail.getMbox()); | |
393 | err = mailimap_select( m_imap, (char*)mb); | ||
394 | if ( err != MAILIMAP_NO_ERROR ) { | 408 | if ( err != MAILIMAP_NO_ERROR ) { |
395 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | ||
396 | return body; | 409 | return body; |
397 | } | 410 | } |
398 | 411 | ||
399 | /* the range has to start at 1!!! not with 0!!!! */ | 412 | /* the range has to start at 1!!! not with 0!!!! */ |
400 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 413 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
401 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 414 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
402 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 415 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
403 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 416 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
@@ -457,35 +470,32 @@ QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | |||
457 | } | 470 | } |
458 | } | 471 | } |
459 | return l; | 472 | return l; |
460 | } | 473 | } |
461 | 474 | ||
462 | encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) | 475 | encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) |
463 | { | 476 | { |
464 | encodedString*res=new encodedString; | 477 | encodedString*res=new encodedString; |
465 | const char*mb; | ||
466 | int err; | 478 | int err; |
467 | mailimap_fetch_type *fetchType; | 479 | mailimap_fetch_type *fetchType; |
468 | mailimap_set *set; | 480 | mailimap_set *set; |
469 | clistcell*current,*cur; | 481 | clistcell*current,*cur; |
470 | mailimap_section_part * section_part = 0; | 482 | mailimap_section_part * section_part = 0; |
471 | mailimap_section_spec * section_spec = 0; | 483 | mailimap_section_spec * section_spec = 0; |
472 | mailimap_section * section = 0; | 484 | mailimap_section * section = 0; |
473 | mailimap_fetch_att * fetch_att = 0; | 485 | mailimap_fetch_att * fetch_att = 0; |
474 | 486 | ||
475 | login(); | 487 | login(); |
476 | if (!m_imap) { | 488 | if (!m_imap) { |
477 | return res; | 489 | return res; |
478 | } | 490 | } |
479 | if (!internal_call) { | 491 | if (!internal_call) { |
480 | mb = mail.getMbox().latin1(); | 492 | err = selectMbox(mail.getMbox()); |
481 | err = mailimap_select( m_imap, (char*)mb); | ||
482 | if ( err != MAILIMAP_NO_ERROR ) { | 493 | if ( err != MAILIMAP_NO_ERROR ) { |
483 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | ||
484 | return res; | 494 | return res; |
485 | } | 495 | } |
486 | } | 496 | } |
487 | set = mailimap_set_new_single(mail.getNumber()); | 497 | set = mailimap_set_new_single(mail.getNumber()); |
488 | 498 | ||
489 | clist*id_list = 0; | 499 | clist*id_list = 0; |
490 | 500 | ||
491 | /* if path == empty then its a request for the whole rfc822 mail and generates | 501 | /* if path == empty then its a request for the whole rfc822 mail and generates |
@@ -768,20 +778,18 @@ void IMAPwrapper::deleteMail(const RecMail&mail) | |||
768 | mailimap_flag_list*flist; | 778 | mailimap_flag_list*flist; |
769 | mailimap_set *set; | 779 | mailimap_set *set; |
770 | mailimap_store_att_flags * store_flags; | 780 | mailimap_store_att_flags * store_flags; |
771 | int err; | 781 | int err; |
772 | login(); | 782 | login(); |
773 | if (!m_imap) { | 783 | if (!m_imap) { |
774 | return; | 784 | return; |
775 | } | 785 | } |
776 | const char *mb = mail.getMbox().latin1(); | 786 | err = selectMbox(mail.getMbox()); |
777 | err = mailimap_select( m_imap, (char*)mb); | ||
778 | if ( err != MAILIMAP_NO_ERROR ) { | 787 | if ( err != MAILIMAP_NO_ERROR ) { |
779 | qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); | ||
780 | return; | 788 | return; |
781 | } | 789 | } |
782 | flist = mailimap_flag_list_new_empty(); | 790 | flist = mailimap_flag_list_new_empty(); |
783 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 791 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
784 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 792 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
785 | set = mailimap_set_new_single(mail.getNumber()); | 793 | set = mailimap_set_new_single(mail.getNumber()); |
786 | err = mailimap_store(m_imap,set,store_flags); | 794 | err = mailimap_store(m_imap,set,store_flags); |
787 | mailimap_set_free( set ); | 795 | mailimap_set_free( set ); |
@@ -805,20 +813,18 @@ void IMAPwrapper::answeredMail(const RecMail&mail) | |||
805 | mailimap_flag_list*flist; | 813 | mailimap_flag_list*flist; |
806 | mailimap_set *set; | 814 | mailimap_set *set; |
807 | mailimap_store_att_flags * store_flags; | 815 | mailimap_store_att_flags * store_flags; |
808 | int err; | 816 | int err; |
809 | login(); | 817 | login(); |
810 | if (!m_imap) { | 818 | if (!m_imap) { |
811 | return; | 819 | return; |
812 | } | 820 | } |
813 | const char *mb = mail.getMbox().latin1(); | 821 | err = selectMbox(mail.getMbox()); |
814 | err = mailimap_select( m_imap, (char*)mb); | ||
815 | if ( err != MAILIMAP_NO_ERROR ) { | 822 | if ( err != MAILIMAP_NO_ERROR ) { |
816 | qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); | ||
817 | return; | 823 | return; |
818 | } | 824 | } |
819 | flist = mailimap_flag_list_new_empty(); | 825 | flist = mailimap_flag_list_new_empty(); |
820 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); | 826 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); |
821 | store_flags = mailimap_store_att_flags_new_add_flags(flist); | 827 | store_flags = mailimap_store_att_flags_new_add_flags(flist); |
822 | set = mailimap_set_new_single(mail.getNumber()); | 828 | set = mailimap_set_new_single(mail.getNumber()); |
823 | err = mailimap_store(m_imap,set,store_flags); | 829 | err = mailimap_store(m_imap,set,store_flags); |
824 | mailimap_set_free( set ); | 830 | mailimap_set_free( set ); |
@@ -867,21 +873,21 @@ int IMAPwrapper::deleteAllMail(const Folder*folder) | |||
867 | { | 873 | { |
868 | login(); | 874 | login(); |
869 | if (!m_imap) { | 875 | if (!m_imap) { |
870 | return 0; | 876 | return 0; |
871 | } | 877 | } |
872 | mailimap_flag_list*flist; | 878 | mailimap_flag_list*flist; |
873 | mailimap_set *set; | 879 | mailimap_set *set; |
874 | mailimap_store_att_flags * store_flags; | 880 | mailimap_store_att_flags * store_flags; |
875 | int err = mailimap_select( m_imap, folder->getName().latin1()); | 881 | int err = selectMbox(folder->getName()); |
876 | if ( err != MAILIMAP_NO_ERROR ) { | 882 | if ( err != MAILIMAP_NO_ERROR ) { |
877 | Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response)); | ||
878 | return 0; | 883 | return 0; |
879 | } | 884 | } |
885 | |||
880 | int last = m_imap->imap_selection_info->sel_exists; | 886 | int last = m_imap->imap_selection_info->sel_exists; |
881 | if (last == 0) { | 887 | if (last == 0) { |
882 | Global::statusMessage(tr("Mailbox has no mails!")); | 888 | Global::statusMessage(tr("Mailbox has no mails!")); |
883 | return 0; | 889 | return 0; |
884 | } | 890 | } |
885 | flist = mailimap_flag_list_new_empty(); | 891 | flist = mailimap_flag_list_new_empty(); |
886 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 892 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
887 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 893 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
@@ -1017,35 +1023,36 @@ encodedString* IMAPwrapper::fetchRawBody(const RecMail&mail) | |||
1017 | { | 1023 | { |
1018 | // dummy | 1024 | // dummy |
1019 | QValueList<int> path; | 1025 | QValueList<int> path; |
1020 | return fetchRawPart(mail,path,false); | 1026 | return fetchRawPart(mail,path,false); |
1021 | } | 1027 | } |
1022 | 1028 | ||
1023 | void IMAPwrapper::mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 1029 | void IMAPwrapper::mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
1024 | { | 1030 | { |
1025 | qDebug("mvcp mail imap"); | ||
1026 | if (targetWrapper != this) { | 1031 | if (targetWrapper != this) { |
1027 | AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); | 1032 | AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); |
1028 | qDebug("Using generic"); | 1033 | qDebug("Using generic"); |
1029 | return; | 1034 | return; |
1030 | } | 1035 | } |
1031 | qDebug("Using internal"); | ||
1032 | mailimap_set *set = 0; | 1036 | mailimap_set *set = 0; |
1033 | 1037 | login(); | |
1034 | int err = mailimap_select( m_imap, fromFolder->getName().latin1()); | 1038 | if (!m_imap) { |
1039 | return; | ||
1040 | } | ||
1041 | int err = selectMbox(fromFolder->getName()); | ||
1035 | if ( err != MAILIMAP_NO_ERROR ) { | 1042 | if ( err != MAILIMAP_NO_ERROR ) { |
1036 | Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response)); | ||
1037 | return; | 1043 | return; |
1038 | } | 1044 | } |
1039 | |||
1040 | int last = m_imap->imap_selection_info->sel_exists; | 1045 | int last = m_imap->imap_selection_info->sel_exists; |
1041 | set = mailimap_set_new_interval( 1, last ); | 1046 | set = mailimap_set_new_interval( 1, last ); |
1042 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); | 1047 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); |
1048 | mailimap_set_free( set ); | ||
1043 | if ( err != MAILIMAP_NO_ERROR ) { | 1049 | if ( err != MAILIMAP_NO_ERROR ) { |
1044 | Global::statusMessage(tr("error copy mails: %1").arg(m_imap->imap_response)); | 1050 | QString error_msg = tr("error copy mails: %1").arg(m_imap->imap_response); |
1051 | Global::statusMessage(error_msg); | ||
1052 | qDebug(error_msg); | ||
1045 | return; | 1053 | return; |
1046 | } | 1054 | } |
1047 | mailimap_set_free( set ); | ||
1048 | if (moveit) { | 1055 | if (moveit) { |
1049 | deleteAllMail(fromFolder); | 1056 | deleteAllMail(fromFolder); |
1050 | } | 1057 | } |
1051 | } | 1058 | } |
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h index 07c6210..99986c2 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.h +++ b/noncore/net/mail/libmailwrapper/imapwrapper.h | |||
@@ -49,26 +49,28 @@ public: | |||
49 | virtual const QString&getName()const; | 49 | virtual const QString&getName()const; |
50 | 50 | ||
51 | protected: | 51 | protected: |
52 | RecMail*parse_list_result(mailimap_msg_att*); | 52 | RecMail*parse_list_result(mailimap_msg_att*); |
53 | void login(); | 53 | void login(); |
54 | 54 | ||
55 | virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); | 55 | virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); |
56 | virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call); | 56 | virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call); |
57 | 57 | int selectMbox(const QString&mbox); | |
58 | |||
58 | void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); | 59 | void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); |
59 | void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); | 60 | void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); |
60 | void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); | 61 | void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); |
61 | void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); | 62 | void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); |
62 | void fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which); | 63 | void fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which); |
63 | void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=1); | 64 | void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=1); |
64 | 65 | ||
65 | /* just helpers */ | 66 | /* just helpers */ |
66 | static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); | 67 | static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); |
67 | static QStringList address_list_to_stringlist(clist*list); | 68 | static QStringList address_list_to_stringlist(clist*list); |
68 | 69 | ||
69 | 70 | ||
70 | IMAPaccount *account; | 71 | IMAPaccount *account; |
71 | mailimap *m_imap; | 72 | mailimap *m_imap; |
73 | QString m_Lastmbox; | ||
72 | }; | 74 | }; |
73 | 75 | ||
74 | #endif | 76 | #endif |