summaryrefslogtreecommitdiffabout
path: root/kmicromail/libmailwrapper
Unidiff
Diffstat (limited to 'kmicromail/libmailwrapper') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/abstractmail.cpp58
-rw-r--r--kmicromail/libmailwrapper/imapwrapper.cpp46
-rw-r--r--kmicromail/libmailwrapper/pop3wrapper.cpp47
-rw-r--r--kmicromail/libmailwrapper/pop3wrapper.h2
4 files changed, 136 insertions, 17 deletions
diff --git a/kmicromail/libmailwrapper/abstractmail.cpp b/kmicromail/libmailwrapper/abstractmail.cpp
index 3998abd..3b0ca1f 100644
--- a/kmicromail/libmailwrapper/abstractmail.cpp
+++ b/kmicromail/libmailwrapper/abstractmail.cpp
@@ -1,187 +1,237 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#include "abstractmail.h" 2#include "abstractmail.h"
3#include "imapwrapper.h" 3#include "imapwrapper.h"
4#include "pop3wrapper.h" 4#include "pop3wrapper.h"
5#include "nntpwrapper.h" 5#include "nntpwrapper.h"
6#include "mhwrapper.h" 6#include "mhwrapper.h"
7#include "mailtypes.h" 7#include "mailtypes.h"
8 8
9 9
10#include <qprogressbar.h>
11#include <qapplication.h>
10 12
11#include <kdecore/kstandarddirs.h> 13#include <kdecore/kstandarddirs.h>
12#include <qfile.h> 14#include <qfile.h>
13#include <qtextstream.h> 15#include <qtextstream.h>
14#include <stdlib.h> 16#include <stdlib.h>
15#include <libetpan/mailmime_content.h> 17#include <libetpan/mailmime_content.h>
16#include <libetpan/mailmime.h> 18#include <libetpan/mailmime.h>
17 19
18using namespace Opie::Core; 20using namespace Opie::Core;
19AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) 21AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
20{ 22{
21 return new IMAPwrapper(a); 23 return new IMAPwrapper(a);
22} 24}
23 25
24AbstractMail* AbstractMail::getWrapper(POP3account *a) 26AbstractMail* AbstractMail::getWrapper(POP3account *a)
25{ 27{
26 return new POP3wrapper(a); 28 return new POP3wrapper(a);
27} 29}
28 30
29AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) 31AbstractMail* AbstractMail::getWrapper(NNTPaccount *a)
30{ 32{
31 return new NNTPwrapper(a); 33 return new NNTPwrapper(a);
32} 34}
33 35
34AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) 36AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name)
35{ 37{
36 return new MHwrapper(a,name); 38 return new MHwrapper(a,name);
37} 39}
38 40
39AbstractMail* AbstractMail::getWrapper(Account*a) 41AbstractMail* AbstractMail::getWrapper(Account*a)
40{ 42{
41 if (!a) return 0; 43 if (!a) return 0;
42 switch (a->getType()) { 44 switch (a->getType()) {
43 case MAILLIB::A_IMAP: 45 case MAILLIB::A_IMAP:
44 return new IMAPwrapper((IMAPaccount*)a); 46 return new IMAPwrapper((IMAPaccount*)a);
45 break; 47 break;
46 case MAILLIB::A_POP3: 48 case MAILLIB::A_POP3:
47 return new POP3wrapper((POP3account*)a); 49 return new POP3wrapper((POP3account*)a);
48 break; 50 break;
49 case MAILLIB::A_NNTP: 51 case MAILLIB::A_NNTP:
50 return new NNTPwrapper((NNTPaccount*)a); 52 return new NNTPwrapper((NNTPaccount*)a);
51 break; 53 break;
52 default: 54 default:
53 return 0; 55 return 0;
54 } 56 }
55} 57}
56 58
57encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) 59encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc)
58{ 60{
59 // odebug << "Decode string start" << oendl; 61 // odebug << "Decode string start" << oendl;
60 char*result_text; 62 char*result_text;
61 size_t index = 0; 63 size_t index = 0;
62 /* reset for recursive use! */ 64 /* reset for recursive use! */
63 size_t target_length = 0; 65 size_t target_length = 0;
64 result_text = 0; 66 result_text = 0;
65 int mimetype = MAILMIME_MECHANISM_7BIT; 67 int mimetype = MAILMIME_MECHANISM_7BIT;
66 if (enc.lower()=="quoted-printable") { 68 if (enc.lower()=="quoted-printable") {
67 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 69 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
68 } else if (enc.lower()=="base64") { 70 } else if (enc.lower()=="base64") {
69 mimetype = MAILMIME_MECHANISM_BASE64; 71 mimetype = MAILMIME_MECHANISM_BASE64;
70 } else if (enc.lower()=="8bit") { 72 } else if (enc.lower()=="8bit") {
71 mimetype = MAILMIME_MECHANISM_8BIT; 73 mimetype = MAILMIME_MECHANISM_8BIT;
72 } else if (enc.lower()=="binary") { 74 } else if (enc.lower()=="binary") {
73 mimetype = MAILMIME_MECHANISM_BINARY; 75 mimetype = MAILMIME_MECHANISM_BINARY;
74 } 76 }
75 77
76 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, 78 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype,
77 &result_text,&target_length); 79 &result_text,&target_length);
78 80
79 encodedString* result = new encodedString(); 81 encodedString* result = new encodedString();
80 if (err == MAILIMF_NO_ERROR) { 82 if (err == MAILIMF_NO_ERROR) {
81 result->setContent(result_text,target_length); 83 result->setContent(result_text,target_length);
82 } 84 }
83 //odebug << "Decode string finished" << oendl; 85 //odebug << "Decode string finished" << oendl;
84 return result; 86 return result;
85} 87}
86 88
87QString AbstractMail::convert_String(const char*text) 89QString AbstractMail::convert_String(const char*text)
88{ 90{
89 //size_t index = 0; 91 //size_t index = 0;
90 char*res = 0; 92 char*res = 0;
91 int err = MAILIMF_NO_ERROR; 93 int err = MAILIMF_NO_ERROR;
92 94
93 QString result(text); 95 QString result(text);
94 96
95 /* due a bug in libetpan it isn't usable this moment */ 97 /* due a bug in libetpan it isn't usable this moment */
96/* int err = mailmime_encoded_phrase_parse("iso-8859-1", 98/* int err = mailmime_encoded_phrase_parse("iso-8859-1",
97 text, strlen(text),&index, "iso-8859-1",&res);*/ 99 text, strlen(text),&index, "iso-8859-1",&res);*/
98 //odebug << "Input: " << text << "" << oendl; 100 //odebug << "Input: " << text << "" << oendl;
99 if (err == MAILIMF_NO_ERROR && res && strlen(res)) { 101 if (err == MAILIMF_NO_ERROR && res && strlen(res)) {
100// result = QString(res); 102// result = QString(res);
101// odebug << "Res: " << res << ", length: " << strlen(res) << "" << oendl; 103// odebug << "Res: " << res << ", length: " << strlen(res) << "" << oendl;
102 } 104 }
103 if (res) free(res); 105 if (res) free(res);
104 return result; 106 return result;
105} 107}
106 108
107/* cp & paste from launcher */ 109/* cp & paste from launcher */
108QString AbstractMail::gen_attachment_id() 110QString AbstractMail::gen_attachment_id()
109{ 111{
110 QFile file( "/proc/sys/kernel/random/uuid" ); 112 QFile file( "/proc/sys/kernel/random/uuid" );
111 if (!file.open(IO_ReadOnly ) ) 113 if (!file.open(IO_ReadOnly ) )
112 return QString::null; 114 return QString::null;
113 115
114 QTextStream stream(&file); 116 QTextStream stream(&file);
115 117
116 return "{" + stream.read().stripWhiteSpace() + "}"; 118 return "{" + stream.read().stripWhiteSpace() + "}";
117} 119}
118 120
119int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool) 121int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool)
120{ 122{
121 return 0; 123 return 0;
122} 124}
123 125
124QString AbstractMail::defaultLocalfolder() 126QString AbstractMail::defaultLocalfolder()
125{ 127{
126 // QString f = getenv( "HOME" ); 128 // QString f = getenv( "HOME" );
127 QString f = locateLocal( "data", "kmicromail/localmail"); 129 QString f = locateLocal( "data", "kmicromail/localmail");
128 // f += "/Applications/opiemail/localmail"; 130 // f += "/Applications/opiemail/localmail";
129 return f; 131 return f;
130} 132}
131 133
132QString AbstractMail::draftFolder() 134QString AbstractMail::draftFolder()
133{ 135{
134 return QString("Drafts"); 136 return QString("Drafts");
135} 137}
136 138
137/* temporary - will be removed when implemented in all classes */ 139/* temporary - will be removed when implemented in all classes */
138void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &) 140void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &)
139{ 141{
140} 142}
141void AbstractMail::deleteMailList(const QValueList<RecMailP>&target) 143void AbstractMail::deleteMailList(const QValueList<RecMailP>&target)
142{ 144{
143 qDebug("AbstractMail::deleteMailList:: Please reimplement! "); 145 //qDebug("AbstractMail::deleteMailList:: Please reimplement! ");
144 146 // this is currently re-implemented in pop3wrapper and imapwrapper
147 int iii = 0;
148 int count = target.count();
149 QProgressBar bar( count,0 );
150 bar.setCaption (("Removing mails - close to abort!") );
151 int w = 300;
152 if ( QApplication::desktop()->width() < 320 )
153 w = 220;
154 int h = bar.sizeHint().height() ;
155 int dw = QApplication::desktop()->width();
156 int dh = QApplication::desktop()->height();
157 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
158 bar.show();
159 int modulo = (count/10)+1;
160 int incCounter = 0;
161 while (iii < count ) {
162 if ( ! bar.isVisible() )
163 return ;
164 if ( incCounter % modulo == 0 )
165 bar.setProgress( incCounter );
166 ++incCounter;
167 qApp->processEvents();
168 RecMailP mail = (*target.at( iii ));
169 deleteMail(mail);
170 ++iii;
171 }
145} 172}
146void AbstractMail::mvcpAllMails(const FolderP&fromFolder, 173void AbstractMail::mvcpAllMails(const FolderP&fromFolder,
147 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) 174 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb)
148{ 175{
149 QValueList<RecMailP> t; 176 QValueList<RecMailP> t;
150 listMessages(fromFolder->getName(),t, maxSizeInKb); 177 listMessages(fromFolder->getName(),t, maxSizeInKb);
151 mvcpMailList( t,targetFolder,targetWrapper,moveit); 178 mvcpMailList( t,targetFolder,targetWrapper,moveit);
152 179
153} 180}
154void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t, 181void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t,
155 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 182 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
156{ 183{
157
158 encodedString*st = 0; 184 encodedString*st = 0;
159 int iii = 0; 185 int iii = 0;
160 int count = t.count(); 186 int count = t.count();
187 if ( count == 0 )
188 return;
189
190 QProgressBar bar( count,0 );
191 bar.setCaption (("Copying mails - close to abort!") );
192 int w = 300;
193 if ( QApplication::desktop()->width() < 320 )
194 w = 220;
195 int h = bar.sizeHint().height() ;
196 int dw = QApplication::desktop()->width();
197 int dh = QApplication::desktop()->height();
198 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
199 bar.show();
200 int modulo = (count/10)+1;
201 int incCounter = 0;
161 while (iii < count ) { 202 while (iii < count ) {
203 if ( ! bar.isVisible() )
204 return ;
205 if ( incCounter % modulo == 0 )
206 bar.setProgress( incCounter );
207 ++incCounter;
208 bar.raise();
209 qApp->processEvents();
210 //qDebug("copy ");
162 RecMailP r = (*t.at( iii )); 211 RecMailP r = (*t.at( iii ));
163 st = fetchRawBody(r); 212 st = fetchRawBody(r);
164 if (st) { 213 if (st) {
165 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); 214 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
166 delete st; 215 delete st;
167 } 216 }
168 ++iii; 217 ++iii;
169 } 218 }
219 bar.hide();
170 if (moveit) { 220 if (moveit) {
171 deleteMailList( t ); 221 deleteMailList( t );
172 //deleteAllMail(fromFolder); 222 //deleteAllMail(fromFolder);
173 } 223 }
174} 224}
175 225
176void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 226void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
177{ 227{
178 encodedString*st = 0; 228 encodedString*st = 0;
179 st = fetchRawBody(mail); 229 st = fetchRawBody(mail);
180 if (st) { 230 if (st) {
181 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); 231 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
182 delete st; 232 delete st;
183 } 233 }
184 if (moveit) { 234 if (moveit) {
185 deleteMail(mail); 235 deleteMail(mail);
186 } 236 }
187} 237}
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp
index bb8bbfc..11d3343 100644
--- a/kmicromail/libmailwrapper/imapwrapper.cpp
+++ b/kmicromail/libmailwrapper/imapwrapper.cpp
@@ -1,1230 +1,1260 @@
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#include "imapwrapper.h" 6#include "imapwrapper.h"
7#include "mailtypes.h" 7#include "mailtypes.h"
8#include "logindialog.h" 8#include "logindialog.h"
9#include <qprogressbar.h>
9 10
10using namespace Opie::Core; 11using namespace Opie::Core;
11IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 12IMAPwrapper::IMAPwrapper( IMAPaccount *a )
12 : AbstractMail() 13 : AbstractMail()
13{ 14{
14 account = a; 15 account = a;
15 m_imap = 0; 16 m_imap = 0;
16 m_Lastmbox = ""; 17 m_Lastmbox = "";
17} 18}
18 19
19IMAPwrapper::~IMAPwrapper() 20IMAPwrapper::~IMAPwrapper()
20{ 21{
21 logout(); 22 logout();
22} 23}
23 24
24/* to avoid to often select statements in loops etc. 25/* to avoid to often select statements in loops etc.
25 we trust that we are logged in and connection is established!*/ 26 we trust that we are logged in and connection is established!*/
26int IMAPwrapper::selectMbox(const QString&mbox) 27int IMAPwrapper::selectMbox(const QString&mbox)
27{ 28{
28 if (mbox == m_Lastmbox) { 29 if (mbox == m_Lastmbox) {
29 return MAILIMAP_NO_ERROR; 30 return MAILIMAP_NO_ERROR;
30 } 31 }
31 int err = mailimap_select( m_imap, (char*)mbox.latin1()); 32 int err = mailimap_select( m_imap, (char*)mbox.latin1());
32 if ( err != MAILIMAP_NO_ERROR ) { 33 if ( err != MAILIMAP_NO_ERROR ) {
33 m_Lastmbox = ""; 34 m_Lastmbox = "";
34 return err; 35 return err;
35 } 36 }
36 m_Lastmbox = mbox; 37 m_Lastmbox = mbox;
37 return err; 38 return err;
38} 39}
39 40
40void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 41void IMAPwrapper::imap_progress( size_t current, size_t maximum )
41{ 42{
42 qApp->processEvents(); 43 qApp->processEvents();
43 qDebug("imap progress %d of %d ",current,maximum ); 44 qDebug("imap progress %d of %d ",current,maximum );
44} 45}
45 46
46bool IMAPwrapper::start_tls(bool force_tls) 47bool IMAPwrapper::start_tls(bool force_tls)
47{ 48{
48 int err; 49 int err;
49 bool try_tls; 50 bool try_tls;
50 mailimap_capability_data * cap_data = 0; 51 mailimap_capability_data * cap_data = 0;
51 52
52 err = mailimap_capability(m_imap,&cap_data); 53 err = mailimap_capability(m_imap,&cap_data);
53 if (err != MAILIMAP_NO_ERROR) { 54 if (err != MAILIMAP_NO_ERROR) {
54 Global::statusMessage("error getting capabilities!"); 55 Global::statusMessage("error getting capabilities!");
55 return false; 56 return false;
56 } 57 }
57 clistiter * cur; 58 clistiter * cur;
58 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { 59 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) {
59 struct mailimap_capability * cap; 60 struct mailimap_capability * cap;
60 cap = (struct mailimap_capability *)clist_content(cur); 61 cap = (struct mailimap_capability *)clist_content(cur);
61 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { 62 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) {
62 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { 63 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) {
63 try_tls = true; 64 try_tls = true;
64 break; 65 break;
65 } 66 }
66 } 67 }
67 } 68 }
68 if (cap_data) { 69 if (cap_data) {
69 mailimap_capability_data_free(cap_data); 70 mailimap_capability_data_free(cap_data);
70 } 71 }
71 if (try_tls) { 72 if (try_tls) {
72 err = mailimap_starttls(m_imap); 73 err = mailimap_starttls(m_imap);
73 if (err != MAILIMAP_NO_ERROR && force_tls) { 74 if (err != MAILIMAP_NO_ERROR && force_tls) {
74 Global::statusMessage(tr("Server has no TLS support!")); 75 Global::statusMessage(tr("Server has no TLS support!"));
75 try_tls = false; 76 try_tls = false;
76 } else { 77 } else {
77 mailstream_low * low; 78 mailstream_low * low;
78 mailstream_low * new_low; 79 mailstream_low * new_low;
79 low = mailstream_get_low(m_imap->imap_stream); 80 low = mailstream_get_low(m_imap->imap_stream);
80 if (!low) { 81 if (!low) {
81 try_tls = false; 82 try_tls = false;
82 } else { 83 } else {
83 int fd = mailstream_low_get_fd(low); 84 int fd = mailstream_low_get_fd(low);
84 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { 85 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
85 mailstream_low_free(low); 86 mailstream_low_free(low);
86 mailstream_set_low(m_imap->imap_stream, new_low); 87 mailstream_set_low(m_imap->imap_stream, new_low);
87 } else { 88 } else {
88 try_tls = false; 89 try_tls = false;
89 } 90 }
90 } 91 }
91 } 92 }
92 } 93 }
93 return try_tls; 94 return try_tls;
94} 95}
95 96
96void IMAPwrapper::login() 97void IMAPwrapper::login()
97{ 98{
98 const char *server, *user, *pass; 99 const char *server, *user, *pass;
99 uint16_t port; 100 uint16_t port;
100 int err = MAILIMAP_NO_ERROR; 101 int err = MAILIMAP_NO_ERROR;
101 102
102 if (account->getOffline()) return; 103 if (account->getOffline()) return;
103 /* we are connected this moment */ 104 /* we are connected this moment */
104 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 105 /* TODO: setup a timer holding the line or if connection closed - delete the value */
105 if (m_imap) { 106 if (m_imap) {
106 err = mailimap_noop(m_imap); 107 err = mailimap_noop(m_imap);
107 if (err!=MAILIMAP_NO_ERROR) { 108 if (err!=MAILIMAP_NO_ERROR) {
108 logout(); 109 logout();
109 } else { 110 } else {
110 mailstream_flush(m_imap->imap_stream); 111 mailstream_flush(m_imap->imap_stream);
111 return; 112 return;
112 } 113 }
113 } 114 }
114 server = account->getServer().latin1(); 115 server = account->getServer().latin1();
115 port = account->getPort().toUInt(); 116 port = account->getPort().toUInt();
116 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 117 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
117 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 118 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
118 login.show(); 119 login.show();
119 if ( QDialog::Accepted == login.exec() ) { 120 if ( QDialog::Accepted == login.exec() ) {
120 // ok 121 // ok
121 user = login.getUser().latin1(); 122 user = login.getUser().latin1();
122 pass = login.getPassword().latin1(); 123 pass = login.getPassword().latin1();
123 } else { 124 } else {
124 // cancel 125 // cancel
125 return; 126 return;
126 } 127 }
127 } else { 128 } else {
128 user = account->getUser().latin1(); 129 user = account->getUser().latin1();
129 pass = account->getPassword().latin1(); 130 pass = account->getPassword().latin1();
130 } 131 }
131 132
132 m_imap = mailimap_new( 20, &imap_progress ); 133 m_imap = mailimap_new( 20, &imap_progress );
133 134
134 /* connect */ 135 /* connect */
135 bool ssl = false; 136 bool ssl = false;
136 bool try_tls = false; 137 bool try_tls = false;
137 bool force_tls = false; 138 bool force_tls = false;
138 139
139 if ( account->ConnectionType() == 2 ) { 140 if ( account->ConnectionType() == 2 ) {
140 ssl = true; 141 ssl = true;
141 } 142 }
142 if (account->ConnectionType()==1) { 143 if (account->ConnectionType()==1) {
143 force_tls = true; 144 force_tls = true;
144 } 145 }
145 146
146 if ( ssl ) { 147 if ( ssl ) {
147 qDebug("using ssl "); 148 qDebug("using ssl ");
148 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 149 err = mailimap_ssl_connect( m_imap, (char*)server, port );
149 } else { 150 } else {
150 err = mailimap_socket_connect( m_imap, (char*)server, port ); 151 err = mailimap_socket_connect( m_imap, (char*)server, port );
151 } 152 }
152 153
153 if ( err != MAILIMAP_NO_ERROR && 154 if ( err != MAILIMAP_NO_ERROR &&
154 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 155 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
155 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 156 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
156 QString failure = ""; 157 QString failure = "";
157 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { 158 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) {
158 failure="Connection refused"; 159 failure="Connection refused";
159 } else { 160 } else {
160 failure="Unknown failure"; 161 failure="Unknown failure";
161 } 162 }
162 Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); 163 Global::statusMessage(tr("error connecting imap server: %1").arg(failure));
163 mailimap_free( m_imap ); 164 mailimap_free( m_imap );
164 m_imap = 0; 165 m_imap = 0;
165 return; 166 return;
166 } 167 }
167 168
168 if (!ssl) { 169 if (!ssl) {
169 try_tls = start_tls(force_tls); 170 try_tls = start_tls(force_tls);
170 } 171 }
171 172
172 bool ok = true; 173 bool ok = true;
173 if (force_tls && !try_tls) { 174 if (force_tls && !try_tls) {
174 Global::statusMessage(tr("Server has no TLS support!")); 175 Global::statusMessage(tr("Server has no TLS support!"));
175 ok = false; 176 ok = false;
176 } 177 }
177 178
178 179
179 /* login */ 180 /* login */
180 181
181 if (ok) { 182 if (ok) {
182 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 183 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
183 if ( err != MAILIMAP_NO_ERROR ) { 184 if ( err != MAILIMAP_NO_ERROR ) {
184 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); 185 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response));
185 ok = false; 186 ok = false;
186 } 187 }
187 } 188 }
188 if (!ok) { 189 if (!ok) {
189 err = mailimap_close( m_imap ); 190 err = mailimap_close( m_imap );
190 mailimap_free( m_imap ); 191 mailimap_free( m_imap );
191 m_imap = 0; 192 m_imap = 0;
192 } 193 }
193} 194}
194 195
195void IMAPwrapper::logout() 196void IMAPwrapper::logout()
196{ 197{
197 int err = MAILIMAP_NO_ERROR; 198 int err = MAILIMAP_NO_ERROR;
198 if (!m_imap) return; 199 if (!m_imap) return;
199 err = mailimap_logout( m_imap ); 200 err = mailimap_logout( m_imap );
200 err = mailimap_close( m_imap ); 201 err = mailimap_close( m_imap );
201 mailimap_free( m_imap ); 202 mailimap_free( m_imap );
202 m_imap = 0; 203 m_imap = 0;
203 m_Lastmbox = ""; 204 m_Lastmbox = "";
204} 205}
205 206
206void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb) 207void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb)
207{ 208{
208 int err = MAILIMAP_NO_ERROR; 209 int err = MAILIMAP_NO_ERROR;
209 clist *result = 0; 210 clist *result = 0;
210 clistcell *current; 211 clistcell *current;
211 mailimap_fetch_type *fetchType = 0; 212 mailimap_fetch_type *fetchType = 0;
212 mailimap_set *set = 0; 213 mailimap_set *set = 0;
213 214
214 login(); 215 login();
215 if (!m_imap) { 216 if (!m_imap) {
216 return; 217 return;
217 } 218 }
218 /* select mailbox READONLY for operations */ 219 /* select mailbox READONLY for operations */
219 err = selectMbox(mailbox); 220 err = selectMbox(mailbox);
220 if ( err != MAILIMAP_NO_ERROR ) { 221 if ( err != MAILIMAP_NO_ERROR ) {
221 return; 222 return;
222 } 223 }
223 224
224 int last = m_imap->imap_selection_info->sel_exists; 225 int last = m_imap->imap_selection_info->sel_exists;
225 226
226 if (last == 0) { 227 if (last == 0) {
227 Global::statusMessage(tr("Mailbox has no mails")); 228 Global::statusMessage(tr("Mailbox has no mails"));
228 return; 229 return;
229 } else { 230 } else {
230 } 231 }
231 232
232 /* the range has to start at 1!!! not with 0!!!! */ 233 /* the range has to start at 1!!! not with 0!!!! */
233 set = mailimap_set_new_interval( 1, last ); 234 set = mailimap_set_new_interval( 1, last );
234 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 235 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
235 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 236 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
236 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 237 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
237 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 238 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
238 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 239 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
239 240
240 err = mailimap_fetch( m_imap, set, fetchType, &result ); 241 err = mailimap_fetch( m_imap, set, fetchType, &result );
241 mailimap_set_free( set ); 242 mailimap_set_free( set );
242 mailimap_fetch_type_free( fetchType ); 243 mailimap_fetch_type_free( fetchType );
243 244
244 QString date,subject,from; 245 QString date,subject,from;
245 246
246 if ( err == MAILIMAP_NO_ERROR ) { 247 if ( err == MAILIMAP_NO_ERROR ) {
247 mailimap_msg_att * msg_att; 248 mailimap_msg_att * msg_att;
248 int i = 0; 249 int i = 0;
249 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 250 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
250 ++i; 251 ++i;
251 msg_att = (mailimap_msg_att*)current->data; 252 msg_att = (mailimap_msg_att*)current->data;
252 RecMail*m = parse_list_result(msg_att); 253 RecMail*m = parse_list_result(msg_att);
253 if (m) { 254 if (m) {
254 if ( maxSizeInKb == 0 || m->Msgsize()<=maxSizeInKb*1024 ) { 255 if ( maxSizeInKb == 0 || m->Msgsize()<=maxSizeInKb*1024 ) {
255 m->setNumber(i); 256 m->setNumber(i);
256 m->setMbox(mailbox); 257 m->setMbox(mailbox);
257 m->setWrapper(this); 258 m->setWrapper(this);
258 target.append(m); 259 target.append(m);
259 } 260 }
260 } 261 }
261 } 262 }
262 Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); 263 Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count()));
263 } else { 264 } else {
264 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); 265 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response));
265 } 266 }
266 if (result) mailimap_fetch_list_free(result); 267 if (result) mailimap_fetch_list_free(result);
267} 268}
268 269
269QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() 270QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders()
270{ 271{
271 const char *path, *mask; 272 const char *path, *mask;
272 int err = MAILIMAP_NO_ERROR; 273 int err = MAILIMAP_NO_ERROR;
273 clist *result = 0; 274 clist *result = 0;
274 clistcell *current = 0; 275 clistcell *current = 0;
275 clistcell*cur_flag = 0; 276 clistcell*cur_flag = 0;
276 mailimap_mbx_list_flags*bflags = 0; 277 mailimap_mbx_list_flags*bflags = 0;
277 278
278 QValueList<FolderP>* folders = new QValueList<FolderP>(); 279 QValueList<FolderP>* folders = new QValueList<FolderP>();
279 login(); 280 login();
280 if (!m_imap) { 281 if (!m_imap) {
281 return folders; 282 return folders;
282 } 283 }
283 284
284/* 285/*
285 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 286 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
286 * We must not forget to filter them out in next loop! 287 * We must not forget to filter them out in next loop!
287 * it seems like ugly code. and yes - it is ugly code. but the best way. 288 * it seems like ugly code. and yes - it is ugly code. but the best way.
288 */ 289 */
289 QString temp; 290 QString temp;
290 mask = "INBOX" ; 291 mask = "INBOX" ;
291 mailimap_mailbox_list *list; 292 mailimap_mailbox_list *list;
292 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 293 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
293 QString del; 294 QString del;
294 bool selectable = true; 295 bool selectable = true;
295 bool no_inferiors = false; 296 bool no_inferiors = false;
296 if ( err == MAILIMAP_NO_ERROR ) { 297 if ( err == MAILIMAP_NO_ERROR ) {
297 current = result->first; 298 current = result->first;
298 for ( int i = result->count; i > 0; i-- ) { 299 for ( int i = result->count; i > 0; i-- ) {
299 list = (mailimap_mailbox_list *) current->data; 300 list = (mailimap_mailbox_list *) current->data;
300 // it is better use the deep copy mechanism of qt itself 301 // it is better use the deep copy mechanism of qt itself
301 // instead of using strdup! 302 // instead of using strdup!
302 temp = list->mb_name; 303 temp = list->mb_name;
303 del = list->mb_delimiter; 304 del = list->mb_delimiter;
304 current = current->next; 305 current = current->next;
305 if ( (bflags = list->mb_flag) ) { 306 if ( (bflags = list->mb_flag) ) {
306 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 307 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
307 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 308 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
308 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 309 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
309 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 310 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
310 no_inferiors = true; 311 no_inferiors = true;
311 } 312 }
312 } 313 }
313 } 314 }
314 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 315 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
315 } 316 }
316 } else { 317 } else {
317 qDebug("error fetching folders: "); 318 qDebug("error fetching folders: ");
318 319
319 } 320 }
320 mailimap_list_result_free( result ); 321 mailimap_list_result_free( result );
321 322
322/* 323/*
323 * second stage - get the other then inbox folders 324 * second stage - get the other then inbox folders
324 */ 325 */
325 mask = "*" ; 326 mask = "*" ;
326 path = account->getPrefix().latin1(); 327 path = account->getPrefix().latin1();
327 if (!path) path = ""; 328 if (!path) path = "";
328 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 329 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
329 if ( err == MAILIMAP_NO_ERROR ) { 330 if ( err == MAILIMAP_NO_ERROR ) {
330 current = result->first; 331 current = result->first;
331 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 332 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
332 no_inferiors = false; 333 no_inferiors = false;
333 list = (mailimap_mailbox_list *) current->data; 334 list = (mailimap_mailbox_list *) current->data;
334 // it is better use the deep copy mechanism of qt itself 335 // it is better use the deep copy mechanism of qt itself
335 // instead of using strdup! 336 // instead of using strdup!
336 temp = list->mb_name; 337 temp = list->mb_name;
337 if (temp.lower()=="inbox") 338 if (temp.lower()=="inbox")
338 continue; 339 continue;
339 if (temp.lower()==account->getPrefix().lower()) 340 if (temp.lower()==account->getPrefix().lower())
340 continue; 341 continue;
341 if ( (bflags = list->mb_flag) ) { 342 if ( (bflags = list->mb_flag) ) {
342 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 343 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
343 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 344 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
344 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 345 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
345 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 346 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
346 no_inferiors = true; 347 no_inferiors = true;
347 } 348 }
348 } 349 }
349 } 350 }
350 del = list->mb_delimiter; 351 del = list->mb_delimiter;
351 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 352 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
352 } 353 }
353 } else { 354 } else {
354 qDebug("error fetching folders "); 355 qDebug("error fetching folders ");
355 356
356 } 357 }
357 if (result) mailimap_list_result_free( result ); 358 if (result) mailimap_list_result_free( result );
358 return folders; 359 return folders;
359} 360}
360 361
361RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 362RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
362{ 363{
363 RecMail * m = 0; 364 RecMail * m = 0;
364 mailimap_msg_att_item *item=0; 365 mailimap_msg_att_item *item=0;
365 clistcell *current,*c,*cf; 366 clistcell *current,*c,*cf;
366 mailimap_msg_att_dynamic*flist; 367 mailimap_msg_att_dynamic*flist;
367 mailimap_flag_fetch*cflag; 368 mailimap_flag_fetch*cflag;
368 int size; 369 int size;
369 QBitArray mFlags(7); 370 QBitArray mFlags(7);
370 QStringList addresslist; 371 QStringList addresslist;
371 372
372 if (!m_att) { 373 if (!m_att) {
373 return m; 374 return m;
374 } 375 }
375 m = new RecMail(); 376 m = new RecMail();
376 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 377 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
377 current = c; 378 current = c;
378 size = 0; 379 size = 0;
379 item = (mailimap_msg_att_item*)current->data; 380 item = (mailimap_msg_att_item*)current->data;
380 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 381 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
381 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 382 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
382 if (!flist->att_list) { 383 if (!flist->att_list) {
383 continue; 384 continue;
384 } 385 }
385 cf = flist->att_list->first; 386 cf = flist->att_list->first;
386 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 387 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
387 cflag = (mailimap_flag_fetch*)cf->data; 388 cflag = (mailimap_flag_fetch*)cf->data;
388 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 389 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
389 switch (cflag->fl_flag->fl_type) { 390 switch (cflag->fl_flag->fl_type) {
390 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 391 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
391 mFlags.setBit(FLAG_ANSWERED); 392 mFlags.setBit(FLAG_ANSWERED);
392 break; 393 break;
393 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 394 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
394 mFlags.setBit(FLAG_FLAGGED); 395 mFlags.setBit(FLAG_FLAGGED);
395 break; 396 break;
396 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 397 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
397 mFlags.setBit(FLAG_DELETED); 398 mFlags.setBit(FLAG_DELETED);
398 break; 399 break;
399 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 400 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
400 mFlags.setBit(FLAG_SEEN); 401 mFlags.setBit(FLAG_SEEN);
401 break; 402 break;
402 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 403 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
403 mFlags.setBit(FLAG_DRAFT); 404 mFlags.setBit(FLAG_DRAFT);
404 break; 405 break;
405 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 406 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
406 break; 407 break;
407 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 408 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
408 break; 409 break;
409 default: 410 default:
410 break; 411 break;
411 } 412 }
412 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 413 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
413 mFlags.setBit(FLAG_RECENT); 414 mFlags.setBit(FLAG_RECENT);
414 } 415 }
415 } 416 }
416 continue; 417 continue;
417 } 418 }
418 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 419 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
419 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 420 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
420 m->setDate(head->env_date); 421 m->setDate(head->env_date);
421 m->setSubject(convert_String((const char*)head->env_subject)); 422 m->setSubject(convert_String((const char*)head->env_subject));
422 //m->setSubject(head->env_subject); 423 //m->setSubject(head->env_subject);
423 if (head->env_from!=NULL) { 424 if (head->env_from!=NULL) {
424 addresslist = address_list_to_stringlist(head->env_from->frm_list); 425 addresslist = address_list_to_stringlist(head->env_from->frm_list);
425 if (addresslist.count()) { 426 if (addresslist.count()) {
426 m->setFrom(addresslist.first()); 427 m->setFrom(addresslist.first());
427 } 428 }
428 } 429 }
429 if (head->env_to!=NULL) { 430 if (head->env_to!=NULL) {
430 addresslist = address_list_to_stringlist(head->env_to->to_list); 431 addresslist = address_list_to_stringlist(head->env_to->to_list);
431 m->setTo(addresslist); 432 m->setTo(addresslist);
432 } 433 }
433 if (head->env_cc!=NULL) { 434 if (head->env_cc!=NULL) {
434 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 435 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
435 m->setCC(addresslist); 436 m->setCC(addresslist);
436 } 437 }
437 if (head->env_bcc!=NULL) { 438 if (head->env_bcc!=NULL) {
438 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 439 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
439 m->setBcc(addresslist); 440 m->setBcc(addresslist);
440 } 441 }
441 /* reply to address, eg. email. */ 442 /* reply to address, eg. email. */
442 if (head->env_reply_to!=NULL) { 443 if (head->env_reply_to!=NULL) {
443 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 444 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
444 if (addresslist.count()) { 445 if (addresslist.count()) {
445 m->setReplyto(addresslist.first()); 446 m->setReplyto(addresslist.first());
446 } 447 }
447 } 448 }
448 if (head->env_in_reply_to!=NULL) { 449 if (head->env_in_reply_to!=NULL) {
449 QString h(head->env_in_reply_to); 450 QString h(head->env_in_reply_to);
450 while (h.length()>0 && h[0]=='<') { 451 while (h.length()>0 && h[0]=='<') {
451 h.remove(0,1); 452 h.remove(0,1);
452 } 453 }
453 while (h.length()>0 && h[h.length()-1]=='>') { 454 while (h.length()>0 && h[h.length()-1]=='>') {
454 h.remove(h.length()-1,1); 455 h.remove(h.length()-1,1);
455 } 456 }
456 if (h.length()>0) { 457 if (h.length()>0) {
457 m->setInreply(QStringList(h)); 458 m->setInreply(QStringList(h));
458 } 459 }
459 } 460 }
460 if (head->env_message_id) { 461 if (head->env_message_id) {
461 m->setMsgid(QString(head->env_message_id)); 462 m->setMsgid(QString(head->env_message_id));
462 } 463 }
463 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 464 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
464#if 0 465#if 0
465 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 466 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
466 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 467 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
467 //odebug << "" << d->dt_year << " " << d->dt_month << " " << d->dt_day << " - " << d->dt_hour << " " << d->dt_min << " " << d->dt_sec << "" << oendl; 468 //odebug << "" << d->dt_year << " " << d->dt_month << " " << d->dt_day << " - " << d->dt_hour << " " << d->dt_min << " " << d->dt_sec << "" << oendl;
468 //odebug << da.toString() << oendl; 469 //odebug << da.toString() << oendl;
469#endif 470#endif
470 } 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) {
471 size = item->att_data.att_static->att_data.att_rfc822_size; 472 size = item->att_data.att_static->att_data.att_rfc822_size;
472 } 473 }
473 } 474 }
474 /* msg is already deleted */ 475 /* msg is already deleted */
475 if (mFlags.testBit(FLAG_DELETED) && m) { 476 if (mFlags.testBit(FLAG_DELETED) && m) {
476 delete m; 477 delete m;
477 m = 0; 478 m = 0;
478 } 479 }
479 if (m) { 480 if (m) {
480 m->setFlags(mFlags); 481 m->setFlags(mFlags);
481 m->setMsgsize(size); 482 m->setMsgsize(size);
482 } 483 }
483 return m; 484 return m;
484} 485}
485 486
486RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail) 487RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail)
487{ 488{
488 RecBodyP body = new RecBody(); 489 RecBodyP body = new RecBody();
489 const char *mb; 490 const char *mb;
490 int err = MAILIMAP_NO_ERROR; 491 int err = MAILIMAP_NO_ERROR;
491 clist *result = 0; 492 clist *result = 0;
492 clistcell *current; 493 clistcell *current;
493 mailimap_fetch_att *fetchAtt = 0; 494 mailimap_fetch_att *fetchAtt = 0;
494 mailimap_fetch_type *fetchType = 0; 495 mailimap_fetch_type *fetchType = 0;
495 mailimap_set *set = 0; 496 mailimap_set *set = 0;
496 mailimap_body*body_desc = 0; 497 mailimap_body*body_desc = 0;
497 498
498 mb = mail->getMbox().latin1(); 499 mb = mail->getMbox().latin1();
499 500
500 login(); 501 login();
501 if (!m_imap) { 502 if (!m_imap) {
502 return body; 503 return body;
503 } 504 }
504 err = selectMbox(mail->getMbox()); 505 err = selectMbox(mail->getMbox());
505 if ( err != MAILIMAP_NO_ERROR ) { 506 if ( err != MAILIMAP_NO_ERROR ) {
506 return body; 507 return body;
507 } 508 }
508 509
509 /* the range has to start at 1!!! not with 0!!!! */ 510 /* the range has to start at 1!!! not with 0!!!! */
510 set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); 511 set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() );
511 fetchAtt = mailimap_fetch_att_new_bodystructure(); 512 fetchAtt = mailimap_fetch_att_new_bodystructure();
512 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 513 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
513 err = mailimap_fetch( m_imap, set, fetchType, &result ); 514 err = mailimap_fetch( m_imap, set, fetchType, &result );
514 mailimap_set_free( set ); 515 mailimap_set_free( set );
515 mailimap_fetch_type_free( fetchType ); 516 mailimap_fetch_type_free( fetchType );
516 517
517 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 518 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
518 mailimap_msg_att * msg_att; 519 mailimap_msg_att * msg_att;
519 msg_att = (mailimap_msg_att*)current->data; 520 msg_att = (mailimap_msg_att*)current->data;
520 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;
521 QValueList<int> path; 522 QValueList<int> path;
522 body_desc = item->att_data.att_static->att_data.att_body; 523 body_desc = item->att_data.att_static->att_data.att_body;
523 traverseBody(mail,body_desc,body,0,path); 524 traverseBody(mail,body_desc,body,0,path);
524 } else { 525 } else {
525 //odebug << "error fetching body: " << m_imap->imap_response << "" << oendl; 526 //odebug << "error fetching body: " << m_imap->imap_response << "" << oendl;
526 } 527 }
527 if (result) mailimap_fetch_list_free(result); 528 if (result) mailimap_fetch_list_free(result);
528 return body; 529 return body;
529} 530}
530 531
531QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 532QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
532{ 533{
533 QStringList l; 534 QStringList l;
534 QString from; 535 QString from;
535 bool named_from; 536 bool named_from;
536 clistcell *current = NULL; 537 clistcell *current = NULL;
537 mailimap_address * current_address=NULL; 538 mailimap_address * current_address=NULL;
538 if (!list) { 539 if (!list) {
539 return l; 540 return l;
540 } 541 }
541 unsigned int count = 0; 542 unsigned int count = 0;
542 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 543 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
543 from = ""; 544 from = "";
544 named_from = false; 545 named_from = false;
545 current_address=(mailimap_address*)current->data; 546 current_address=(mailimap_address*)current->data;
546 if (current_address->ad_personal_name){ 547 if (current_address->ad_personal_name){
547 from+=convert_String((const char*)current_address->ad_personal_name); 548 from+=convert_String((const char*)current_address->ad_personal_name);
548 from+=" "; 549 from+=" ";
549 named_from = true; 550 named_from = true;
550 } 551 }
551 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)) {
552 from+="<"; 553 from+="<";
553 } 554 }
554 if (current_address->ad_mailbox_name) { 555 if (current_address->ad_mailbox_name) {
555 from+=QString(current_address->ad_mailbox_name); 556 from+=QString(current_address->ad_mailbox_name);
556 from+="@"; 557 from+="@";
557 } 558 }
558 if (current_address->ad_host_name) { 559 if (current_address->ad_host_name) {
559 from+=QString(current_address->ad_host_name); 560 from+=QString(current_address->ad_host_name);
560 } 561 }
561 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)) {
562 from+=">"; 563 from+=">";
563 } 564 }
564 l.append(QString(from)); 565 l.append(QString(from));
565 if (++count > 99) { 566 if (++count > 99) {
566 break; 567 break;
567 } 568 }
568 } 569 }
569 return l; 570 return l;
570} 571}
571 572
572encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call) 573encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call)
573{ 574{
574 encodedString*res=new encodedString; 575 encodedString*res=new encodedString;
575 int err; 576 int err;
576 mailimap_fetch_type *fetchType; 577 mailimap_fetch_type *fetchType;
577 mailimap_set *set; 578 mailimap_set *set;
578 clistcell*current,*cur; 579 clistcell*current,*cur;
579 mailimap_section_part * section_part = 0; 580 mailimap_section_part * section_part = 0;
580 mailimap_section_spec * section_spec = 0; 581 mailimap_section_spec * section_spec = 0;
581 mailimap_section * section = 0; 582 mailimap_section * section = 0;
582 mailimap_fetch_att * fetch_att = 0; 583 mailimap_fetch_att * fetch_att = 0;
583 584
584 login(); 585 login();
585 if (!m_imap) { 586 if (!m_imap) {
586 return res; 587 return res;
587 } 588 }
588 if (!internal_call) { 589 if (!internal_call) {
589 err = selectMbox(mail->getMbox()); 590 err = selectMbox(mail->getMbox());
590 if ( err != MAILIMAP_NO_ERROR ) { 591 if ( err != MAILIMAP_NO_ERROR ) {
591 return res; 592 return res;
592 } 593 }
593 } 594 }
594 set = mailimap_set_new_single(mail->getNumber()); 595 set = mailimap_set_new_single(mail->getNumber());
595 596
596 clist*id_list = 0; 597 clist*id_list = 0;
597 598
598 /* if path == empty then its a request for the whole rfc822 mail and generates 599 /* if path == empty then its a request for the whole rfc822 mail and generates
599 a "fetch <id> (body[])" statement on imap server */ 600 a "fetch <id> (body[])" statement on imap server */
600 if (path.count()>0 ) { 601 if (path.count()>0 ) {
601 id_list = clist_new(); 602 id_list = clist_new();
602 for (unsigned j=0; j < path.count();++j) { 603 for (unsigned j=0; j < path.count();++j) {
603 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 604 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
604 *p_id = path[j]; 605 *p_id = path[j];
605 clist_append(id_list,p_id); 606 clist_append(id_list,p_id);
606 } 607 }
607 section_part = mailimap_section_part_new(id_list); 608 section_part = mailimap_section_part_new(id_list);
608 section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 609 section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
609 } 610 }
610 611
611 section = mailimap_section_new(section_spec); 612 section = mailimap_section_new(section_spec);
612 fetch_att = mailimap_fetch_att_new_body_section(section); 613 fetch_att = mailimap_fetch_att_new_body_section(section);
613 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 614 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
614 615
615 clist*result = 0; 616 clist*result = 0;
616 617
617 err = mailimap_fetch( m_imap, set, fetchType, &result ); 618 err = mailimap_fetch( m_imap, set, fetchType, &result );
618 mailimap_set_free( set ); 619 mailimap_set_free( set );
619 mailimap_fetch_type_free( fetchType ); 620 mailimap_fetch_type_free( fetchType );
620 621
621 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 622 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
622 mailimap_msg_att * msg_att; 623 mailimap_msg_att * msg_att;
623 msg_att = (mailimap_msg_att*)current->data; 624 msg_att = (mailimap_msg_att*)current->data;
624 mailimap_msg_att_item*msg_att_item; 625 mailimap_msg_att_item*msg_att_item;
625 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 626 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
626 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 627 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
627 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 628 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
628 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 629 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
629 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 630 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
630 /* detach - we take over the content */ 631 /* detach - we take over the content */
631 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 632 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
632 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); 633 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
633 } 634 }
634 } 635 }
635 } 636 }
636 } else { 637 } else {
637 ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl; 638 ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl;
638 } 639 }
639 if (result) mailimap_fetch_list_free(result); 640 if (result) mailimap_fetch_list_free(result);
640 return res; 641 return res;
641} 642}
642 643
643/* current_recursion is for recursive calls. 644/* current_recursion is for recursive calls.
644 current_count means the position inside the internal loop! */ 645 current_count means the position inside the internal loop! */
645void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body, 646void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body,
646 int current_recursion,QValueList<int>recList,int current_count) 647 int current_recursion,QValueList<int>recList,int current_count)
647{ 648{
648 if (!body || current_recursion>=10) { 649 if (!body || current_recursion>=10) {
649 return; 650 return;
650 } 651 }
651 switch (body->bd_type) { 652 switch (body->bd_type) {
652 case MAILIMAP_BODY_1PART: 653 case MAILIMAP_BODY_1PART:
653 { 654 {
654 QValueList<int>countlist = recList; 655 QValueList<int>countlist = recList;
655 countlist.append(current_count); 656 countlist.append(current_count);
656 RecPartP currentPart = new RecPart(); 657 RecPartP currentPart = new RecPart();
657 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; 658 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part;
658 QString id(""); 659 QString id("");
659 currentPart->setPositionlist(countlist); 660 currentPart->setPositionlist(countlist);
660 for (unsigned int j = 0; j < countlist.count();++j) { 661 for (unsigned int j = 0; j < countlist.count();++j) {
661 id+=(j>0?" ":""); 662 id+=(j>0?" ":"");
662 id+=QString("%1").arg(countlist[j]); 663 id+=QString("%1").arg(countlist[j]);
663 } 664 }
664 //odebug << "ID = " << id.latin1() << "" << oendl; 665 //odebug << "ID = " << id.latin1() << "" << oendl;
665 currentPart->setIdentifier(id); 666 currentPart->setIdentifier(id);
666 fillSinglePart(currentPart,part1); 667 fillSinglePart(currentPart,part1);
667 /* important: Check for is NULL 'cause a body can be empty! 668 /* important: Check for is NULL 'cause a body can be empty!
668 And we put it only into the mail if it is the FIRST part */ 669 And we put it only into the mail if it is the FIRST part */
669 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) { 670 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) {
670 QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding()); 671 QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding());
671 target_body->setDescription(currentPart); 672 target_body->setDescription(currentPart);
672 target_body->setBodytext(body_text); 673 target_body->setBodytext(body_text);
673 if (countlist.count()>1) { 674 if (countlist.count()>1) {
674 target_body->addPart(currentPart); 675 target_body->addPart(currentPart);
675 } 676 }
676 } else { 677 } else {
677 target_body->addPart(currentPart); 678 target_body->addPart(currentPart);
678 } 679 }
679 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { 680 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) {
680 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); 681 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist);
681 } 682 }
682 } 683 }
683 break; 684 break;
684 case MAILIMAP_BODY_MPART: 685 case MAILIMAP_BODY_MPART:
685 { 686 {
686 QValueList<int>countlist = recList; 687 QValueList<int>countlist = recList;
687 clistcell*current=0; 688 clistcell*current=0;
688 mailimap_body*current_body=0; 689 mailimap_body*current_body=0;
689 unsigned int ccount = 1; 690 unsigned int ccount = 1;
690 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; 691 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart;
691 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 692 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
692 current_body = (mailimap_body*)current->data; 693 current_body = (mailimap_body*)current->data;
693 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 694 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
694 RecPartP targetPart = new RecPart(); 695 RecPartP targetPart = new RecPart();
695 targetPart->setType("multipart"); 696 targetPart->setType("multipart");
696 fillMultiPart(targetPart,mailDescription); 697 fillMultiPart(targetPart,mailDescription);
697 countlist.append(current_count); 698 countlist.append(current_count);
698 targetPart->setPositionlist(countlist); 699 targetPart->setPositionlist(countlist);
699 target_body->addPart(targetPart); 700 target_body->addPart(targetPart);
700 QString id(""); 701 QString id("");
701 for (unsigned int j = 0; j < countlist.count();++j) { 702 for (unsigned int j = 0; j < countlist.count();++j) {
702 id+=(j>0?" ":""); 703 id+=(j>0?" ":"");
703 id+=QString("%1").arg(countlist[j]); 704 id+=QString("%1").arg(countlist[j]);
704 } 705 }
705 // odebug << "ID(mpart) = " << id.latin1() << "" << oendl; 706 // odebug << "ID(mpart) = " << id.latin1() << "" << oendl;
706 } 707 }
707 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); 708 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount);
708 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 709 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
709 countlist = recList; 710 countlist = recList;
710 } 711 }
711 ++ccount; 712 ++ccount;
712 } 713 }
713 } 714 }
714 break; 715 break;
715 default: 716 default:
716 break; 717 break;
717 } 718 }
718} 719}
719 720
720void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description) 721void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description)
721{ 722{
722 if (!Description) { 723 if (!Description) {
723 return; 724 return;
724 } 725 }
725 switch (Description->bd_type) { 726 switch (Description->bd_type) {
726 case MAILIMAP_BODY_TYPE_1PART_TEXT: 727 case MAILIMAP_BODY_TYPE_1PART_TEXT:
727 target_part->setType("text"); 728 target_part->setType("text");
728 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 729 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
729 break; 730 break;
730 case MAILIMAP_BODY_TYPE_1PART_BASIC: 731 case MAILIMAP_BODY_TYPE_1PART_BASIC:
731 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 732 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
732 break; 733 break;
733 case MAILIMAP_BODY_TYPE_1PART_MSG: 734 case MAILIMAP_BODY_TYPE_1PART_MSG:
734 target_part->setType("message"); 735 target_part->setType("message");
735 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 736 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
736 break; 737 break;
737 default: 738 default:
738 break; 739 break;
739 } 740 }
740} 741}
741 742
742void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which) 743void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which)
743{ 744{
744 if (!which) { 745 if (!which) {
745 return; 746 return;
746 } 747 }
747 QString sub; 748 QString sub;
748 sub = which->bd_media_text; 749 sub = which->bd_media_text;
749 //odebug << "Type= text/" << which->bd_media_text << "" << oendl; 750 //odebug << "Type= text/" << which->bd_media_text << "" << oendl;
750 target_part->setSubtype(sub.lower()); 751 target_part->setSubtype(sub.lower());
751 target_part->setLines(which->bd_lines); 752 target_part->setLines(which->bd_lines);
752 fillBodyFields(target_part,which->bd_fields); 753 fillBodyFields(target_part,which->bd_fields);
753} 754}
754 755
755void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which) 756void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which)
756{ 757{
757 if (!which) { 758 if (!which) {
758 return; 759 return;
759 } 760 }
760 target_part->setSubtype("rfc822"); 761 target_part->setSubtype("rfc822");
761 //odebug << "Message part" << oendl; 762 //odebug << "Message part" << oendl;
762 /* we set this type to text/plain */ 763 /* we set this type to text/plain */
763 target_part->setLines(which->bd_lines); 764 target_part->setLines(which->bd_lines);
764 fillBodyFields(target_part,which->bd_fields); 765 fillBodyFields(target_part,which->bd_fields);
765} 766}
766 767
767void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which) 768void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which)
768{ 769{
769 if (!which) return; 770 if (!which) return;
770 QString sub = which->bd_media_subtype; 771 QString sub = which->bd_media_subtype;
771 target_part->setSubtype(sub.lower()); 772 target_part->setSubtype(sub.lower());
772 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { 773 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) {
773 clistcell*cur = 0; 774 clistcell*cur = 0;
774 mailimap_single_body_fld_param*param=0; 775 mailimap_single_body_fld_param*param=0;
775 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 776 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
776 param = (mailimap_single_body_fld_param*)cur->data; 777 param = (mailimap_single_body_fld_param*)cur->data;
777 if (param) { 778 if (param) {
778 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 779 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
779 } 780 }
780 } 781 }
781 } 782 }
782} 783}
783 784
784void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which) 785void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which)
785{ 786{
786 if (!which) { 787 if (!which) {
787 return; 788 return;
788 } 789 }
789 QString type,sub; 790 QString type,sub;
790 switch (which->bd_media_basic->med_type) { 791 switch (which->bd_media_basic->med_type) {
791 case MAILIMAP_MEDIA_BASIC_APPLICATION: 792 case MAILIMAP_MEDIA_BASIC_APPLICATION:
792 type = "application"; 793 type = "application";
793 break; 794 break;
794 case MAILIMAP_MEDIA_BASIC_AUDIO: 795 case MAILIMAP_MEDIA_BASIC_AUDIO:
795 type = "audio"; 796 type = "audio";
796 break; 797 break;
797 case MAILIMAP_MEDIA_BASIC_IMAGE: 798 case MAILIMAP_MEDIA_BASIC_IMAGE:
798 type = "image"; 799 type = "image";
799 break; 800 break;
800 case MAILIMAP_MEDIA_BASIC_MESSAGE: 801 case MAILIMAP_MEDIA_BASIC_MESSAGE:
801 type = "message"; 802 type = "message";
802 break; 803 break;
803 case MAILIMAP_MEDIA_BASIC_VIDEO: 804 case MAILIMAP_MEDIA_BASIC_VIDEO:
804 type = "video"; 805 type = "video";
805 break; 806 break;
806 case MAILIMAP_MEDIA_BASIC_OTHER: 807 case MAILIMAP_MEDIA_BASIC_OTHER:
807 default: 808 default:
808 if (which->bd_media_basic->med_basic_type) { 809 if (which->bd_media_basic->med_basic_type) {
809 type = which->bd_media_basic->med_basic_type; 810 type = which->bd_media_basic->med_basic_type;
810 } else { 811 } else {
811 type = ""; 812 type = "";
812 } 813 }
813 break; 814 break;
814 } 815 }
815 if (which->bd_media_basic->med_subtype) { 816 if (which->bd_media_basic->med_subtype) {
816 sub = which->bd_media_basic->med_subtype; 817 sub = which->bd_media_basic->med_subtype;
817 } else { 818 } else {
818 sub = ""; 819 sub = "";
819 } 820 }
820 // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl; 821 // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl;
821 target_part->setType(type.lower()); 822 target_part->setType(type.lower());
822 target_part->setSubtype(sub.lower()); 823 target_part->setSubtype(sub.lower());
823 fillBodyFields(target_part,which->bd_fields); 824 fillBodyFields(target_part,which->bd_fields);
824} 825}
825 826
826void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which) 827void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which)
827{ 828{
828 if (!which) return; 829 if (!which) return;
829 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 830 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
830 clistcell*cur; 831 clistcell*cur;
831 mailimap_single_body_fld_param*param=0; 832 mailimap_single_body_fld_param*param=0;
832 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 833 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
833 param = (mailimap_single_body_fld_param*)cur->data; 834 param = (mailimap_single_body_fld_param*)cur->data;
834 if (param) { 835 if (param) {
835 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 836 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
836 } 837 }
837 } 838 }
838 } 839 }
839 mailimap_body_fld_enc*enc = which->bd_encoding; 840 mailimap_body_fld_enc*enc = which->bd_encoding;
840 QString encoding(""); 841 QString encoding("");
841 switch (enc->enc_type) { 842 switch (enc->enc_type) {
842 case MAILIMAP_BODY_FLD_ENC_7BIT: 843 case MAILIMAP_BODY_FLD_ENC_7BIT:
843 encoding = "7bit"; 844 encoding = "7bit";
844 break; 845 break;
845 case MAILIMAP_BODY_FLD_ENC_8BIT: 846 case MAILIMAP_BODY_FLD_ENC_8BIT:
846 encoding = "8bit"; 847 encoding = "8bit";
847 break; 848 break;
848 case MAILIMAP_BODY_FLD_ENC_BINARY: 849 case MAILIMAP_BODY_FLD_ENC_BINARY:
849 encoding="binary"; 850 encoding="binary";
850 break; 851 break;
851 case MAILIMAP_BODY_FLD_ENC_BASE64: 852 case MAILIMAP_BODY_FLD_ENC_BASE64:
852 encoding="base64"; 853 encoding="base64";
853 break; 854 break;
854 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 855 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
855 encoding="quoted-printable"; 856 encoding="quoted-printable";
856 break; 857 break;
857 case MAILIMAP_BODY_FLD_ENC_OTHER: 858 case MAILIMAP_BODY_FLD_ENC_OTHER:
858 default: 859 default:
859 if (enc->enc_value) { 860 if (enc->enc_value) {
860 char*t=enc->enc_value; 861 char*t=enc->enc_value;
861 encoding=QString(enc->enc_value); 862 encoding=QString(enc->enc_value);
862 enc->enc_value=0L; 863 enc->enc_value=0L;
863 free(t); 864 free(t);
864 } 865 }
865 } 866 }
866 if (which->bd_description) { 867 if (which->bd_description) {
867 target_part->setDescription(QString(which->bd_description)); 868 target_part->setDescription(QString(which->bd_description));
868 } 869 }
869 target_part->setEncoding(encoding); 870 target_part->setEncoding(encoding);
870 target_part->setSize(which->bd_size); 871 target_part->setSize(which->bd_size);
871} 872}
872void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target) 873void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target)
873{ 874{
875 //#if 0
874 mailimap_flag_list*flist; 876 mailimap_flag_list*flist;
875 mailimap_set *set; 877 mailimap_set *set;
876 mailimap_store_att_flags * store_flags; 878 mailimap_store_att_flags * store_flags;
877 int err; 879 int err;
878 login(); 880 login();
881 //#endif
879 if (!m_imap) { 882 if (!m_imap) {
880 return; 883 return;
881 } 884 }
882 int iii = 0; 885 int iii = 0;
883 int count = target.count(); 886 int count = target.count();
884 qDebug("imap remove count %d ", count); 887 // qDebug("imap remove count %d ", count);
888
889 QProgressBar bar( count,0 );
890 bar.setCaption (("Removing mails - close to abort!") );
891 int w = 300;
892 if ( QApplication::desktop()->width() < 320 )
893 w = 220;
894 int h = bar.sizeHint().height() ;
895 int dw = QApplication::desktop()->width();
896 int dh = QApplication::desktop()->height();
897 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
898 bar.show();
899 int modulo = (count/10)+1;
900 int incCounter = 0;
901
885 while (iii < count ) { 902 while (iii < count ) {
886 qDebug("IMAP remove %d ", iii); 903 if ( ! bar.isVisible() )
904 return ;
905 if ( incCounter % modulo == 0 )
906 bar.setProgress( incCounter );
907 ++incCounter;
908 qApp->processEvents();
887 RecMailP mail = (*target.at( iii )); 909 RecMailP mail = (*target.at( iii ));
888 910 //#if 0
911 //qDebug("IMAP remove %d %d ", iii, mail->getNumber() );
889 err = selectMbox(mail->getMbox()); 912 err = selectMbox(mail->getMbox());
890 if ( err != MAILIMAP_NO_ERROR ) { 913 if ( err != MAILIMAP_NO_ERROR ) {
891 return; 914 return;
892 } 915 }
893 flist = mailimap_flag_list_new_empty(); 916 flist = mailimap_flag_list_new_empty();
894 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 917 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
895 store_flags = mailimap_store_att_flags_new_set_flags(flist); 918 store_flags = mailimap_store_att_flags_new_set_flags(flist);
896 set = mailimap_set_new_single(mail->getNumber()); 919 set = mailimap_set_new_single(mail->getNumber());
897 err = mailimap_store(m_imap,set,store_flags); 920 err = mailimap_store(m_imap,set,store_flags);
898 mailimap_set_free( set ); 921 mailimap_set_free( set );
899 mailimap_store_att_flags_free(store_flags); 922 mailimap_store_att_flags_free(store_flags);
900 923
901 if (err != MAILIMAP_NO_ERROR) { 924 if (err != MAILIMAP_NO_ERROR) {
902 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; 925 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl;
903 return; 926 return;
904 } 927 }
905 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 928 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
906 /* should we realy do that at this moment? */ 929 /* should we realy do that at this moment? */
907 930
931 // err = mailimap_expunge(m_imap);
932 //if (err != MAILIMAP_NO_ERROR) {
933 // Global::statusMessage(tr("Error deleting mails: %s").arg(m_imap->imap_response));
934 // }
935 //#endif
936 //deleteMail( mail);
937 ++iii;
938 }
939 //qDebug("Deleting imap mails... ");
908 err = mailimap_expunge(m_imap); 940 err = mailimap_expunge(m_imap);
909 if (err != MAILIMAP_NO_ERROR) { 941 if (err != MAILIMAP_NO_ERROR) {
910 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 942 Global::statusMessage(tr("Error deleting mails: %s").arg(m_imap->imap_response));
911 } 943 }
912 ++iii;
913 }
914} 944}
915void IMAPwrapper::deleteMail(const RecMailP&mail) 945void IMAPwrapper::deleteMail(const RecMailP&mail)
916{ 946{
917 mailimap_flag_list*flist; 947 mailimap_flag_list*flist;
918 mailimap_set *set; 948 mailimap_set *set;
919 mailimap_store_att_flags * store_flags; 949 mailimap_store_att_flags * store_flags;
920 int err; 950 int err;
921 login(); 951 login();
922 if (!m_imap) { 952 if (!m_imap) {
923 return; 953 return;
924 } 954 }
925 err = selectMbox(mail->getMbox()); 955 err = selectMbox(mail->getMbox());
926 if ( err != MAILIMAP_NO_ERROR ) { 956 if ( err != MAILIMAP_NO_ERROR ) {
927 return; 957 return;
928 } 958 }
929 flist = mailimap_flag_list_new_empty(); 959 flist = mailimap_flag_list_new_empty();
930 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 960 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
931 store_flags = mailimap_store_att_flags_new_set_flags(flist); 961 store_flags = mailimap_store_att_flags_new_set_flags(flist);
932 set = mailimap_set_new_single(mail->getNumber()); 962 set = mailimap_set_new_single(mail->getNumber());
933 err = mailimap_store(m_imap,set,store_flags); 963 err = mailimap_store(m_imap,set,store_flags);
934 mailimap_set_free( set ); 964 mailimap_set_free( set );
935 mailimap_store_att_flags_free(store_flags); 965 mailimap_store_att_flags_free(store_flags);
936 966
937 if (err != MAILIMAP_NO_ERROR) { 967 if (err != MAILIMAP_NO_ERROR) {
938 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; 968 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl;
939 return; 969 return;
940 } 970 }
941 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 971 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
942 /* should we realy do that at this moment? */ 972 /* should we realy do that at this moment? */
943 973
944 err = mailimap_expunge(m_imap); 974 err = mailimap_expunge(m_imap);
945 if (err != MAILIMAP_NO_ERROR) { 975 if (err != MAILIMAP_NO_ERROR) {
946 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 976 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
947 } 977 }
948 qDebug("IMAPwrapper::deleteMail "); 978 //qDebug("IMAPwrapper::deleteMail 2");
949 979
950} 980}
951 981
952void IMAPwrapper::answeredMail(const RecMailP&mail) 982void IMAPwrapper::answeredMail(const RecMailP&mail)
953{ 983{
954 mailimap_flag_list*flist; 984 mailimap_flag_list*flist;
955 mailimap_set *set; 985 mailimap_set *set;
956 mailimap_store_att_flags * store_flags; 986 mailimap_store_att_flags * store_flags;
957 int err; 987 int err;
958 login(); 988 login();
959 if (!m_imap) { 989 if (!m_imap) {
960 return; 990 return;
961 } 991 }
962 err = selectMbox(mail->getMbox()); 992 err = selectMbox(mail->getMbox());
963 if ( err != MAILIMAP_NO_ERROR ) { 993 if ( err != MAILIMAP_NO_ERROR ) {
964 return; 994 return;
965 } 995 }
966 flist = mailimap_flag_list_new_empty(); 996 flist = mailimap_flag_list_new_empty();
967 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 997 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
968 store_flags = mailimap_store_att_flags_new_add_flags(flist); 998 store_flags = mailimap_store_att_flags_new_add_flags(flist);
969 set = mailimap_set_new_single(mail->getNumber()); 999 set = mailimap_set_new_single(mail->getNumber());
970 err = mailimap_store(m_imap,set,store_flags); 1000 err = mailimap_store(m_imap,set,store_flags);
971 mailimap_set_free( set ); 1001 mailimap_set_free( set );
972 mailimap_store_att_flags_free(store_flags); 1002 mailimap_store_att_flags_free(store_flags);
973 1003
974 if (err != MAILIMAP_NO_ERROR) { 1004 if (err != MAILIMAP_NO_ERROR) {
975 // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl; 1005 // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl;
976 return; 1006 return;
977 } 1007 }
978} 1008}
979 1009
980QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc) 1010QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
981{ 1011{
982 QString body(""); 1012 QString body("");
983 encodedString*res = fetchRawPart(mail,path,internal_call); 1013 encodedString*res = fetchRawPart(mail,path,internal_call);
984 encodedString*r = decode_String(res,enc); 1014 encodedString*r = decode_String(res,enc);
985 delete res; 1015 delete res;
986 if (r) { 1016 if (r) {
987 if (r->Length()>0) { 1017 if (r->Length()>0) {
988 body = r->Content(); 1018 body = r->Content();
989 } 1019 }
990 delete r; 1020 delete r;
991 } 1021 }
992 return body; 1022 return body;
993} 1023}
994 1024
995QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) 1025QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part)
996{ 1026{
997 return fetchTextPart(mail,part->Positionlist(),false,part->Encoding()); 1027 return fetchTextPart(mail,part->Positionlist(),false,part->Encoding());
998} 1028}
999 1029
1000encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part) 1030encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part)
1001{ 1031{
1002 encodedString*res = fetchRawPart(mail,part->Positionlist(),false); 1032 encodedString*res = fetchRawPart(mail,part->Positionlist(),false);
1003 encodedString*r = decode_String(res,part->Encoding()); 1033 encodedString*r = decode_String(res,part->Encoding());
1004 delete res; 1034 delete res;
1005 return r; 1035 return r;
1006} 1036}
1007 1037
1008encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part) 1038encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part)
1009{ 1039{
1010 return fetchRawPart(mail,part->Positionlist(),false); 1040 return fetchRawPart(mail,part->Positionlist(),false);
1011} 1041}
1012 1042
1013int IMAPwrapper::deleteAllMail(const FolderP&folder) 1043int IMAPwrapper::deleteAllMail(const FolderP&folder)
1014{ 1044{
1015 login(); 1045 login();
1016 if (!m_imap) { 1046 if (!m_imap) {
1017 return 0; 1047 return 0;
1018 } 1048 }
1019 mailimap_flag_list*flist; 1049 mailimap_flag_list*flist;
1020 mailimap_set *set; 1050 mailimap_set *set;
1021 mailimap_store_att_flags * store_flags; 1051 mailimap_store_att_flags * store_flags;
1022 int err = selectMbox(folder->getName()); 1052 int err = selectMbox(folder->getName());
1023 if ( err != MAILIMAP_NO_ERROR ) { 1053 if ( err != MAILIMAP_NO_ERROR ) {
1024 return 0; 1054 return 0;
1025 } 1055 }
1026 1056
1027 int last = m_imap->imap_selection_info->sel_exists; 1057 int last = m_imap->imap_selection_info->sel_exists;
1028 if (last == 0) { 1058 if (last == 0) {
1029 Global::statusMessage(tr("Mailbox has no mails!")); 1059 Global::statusMessage(tr("Mailbox has no mails!"));
1030 return 0; 1060 return 0;
1031 } 1061 }
1032 flist = mailimap_flag_list_new_empty(); 1062 flist = mailimap_flag_list_new_empty();
1033 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 1063 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
1034 store_flags = mailimap_store_att_flags_new_set_flags(flist); 1064 store_flags = mailimap_store_att_flags_new_set_flags(flist);
1035 set = mailimap_set_new_interval( 1, last ); 1065 set = mailimap_set_new_interval( 1, last );
1036 err = mailimap_store(m_imap,set,store_flags); 1066 err = mailimap_store(m_imap,set,store_flags);
1037 mailimap_set_free( set ); 1067 mailimap_set_free( set );
1038 mailimap_store_att_flags_free(store_flags); 1068 mailimap_store_att_flags_free(store_flags);
1039 if (err != MAILIMAP_NO_ERROR) { 1069 if (err != MAILIMAP_NO_ERROR) {
1040 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 1070 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
1041 return 0; 1071 return 0;
1042 } 1072 }
1043 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 1073 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
1044 /* should we realy do that at this moment? */ 1074 /* should we realy do that at this moment? */
1045 err = mailimap_expunge(m_imap); 1075 err = mailimap_expunge(m_imap);
1046 if (err != MAILIMAP_NO_ERROR) { 1076 if (err != MAILIMAP_NO_ERROR) {
1047 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 1077 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
1048 return 0; 1078 return 0;
1049 } 1079 }
1050 // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; 1080 // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl;
1051 return 1; 1081 return 1;
1052} 1082}
1053 1083
1054int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder) 1084int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder)
1055{ 1085{
1056 if (folder.length()==0) return 0; 1086 if (folder.length()==0) return 0;
1057 login(); 1087 login();
1058 if (!m_imap) {return 0;} 1088 if (!m_imap) {return 0;}
1059 QString pre = account->getPrefix(); 1089 QString pre = account->getPrefix();
1060 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { 1090 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) {
1061 pre+=delemiter; 1091 pre+=delemiter;
1062 } 1092 }
1063 if (parentfolder) { 1093 if (parentfolder) {
1064 pre += parentfolder->getDisplayName()+delemiter; 1094 pre += parentfolder->getDisplayName()+delemiter;
1065 } 1095 }
1066 pre+=folder; 1096 pre+=folder;
1067 if (getsubfolder) { 1097 if (getsubfolder) {
1068 if (delemiter.length()>0) { 1098 if (delemiter.length()>0) {
1069 pre+=delemiter; 1099 pre+=delemiter;
1070 } else { 1100 } else {
1071 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); 1101 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre));
1072 return 0; 1102 return 0;
1073 } 1103 }
1074 } 1104 }
1075 // odebug << "Creating " << pre.latin1() << "" << oendl; 1105 // odebug << "Creating " << pre.latin1() << "" << oendl;
1076 int res = mailimap_create(m_imap,pre.latin1()); 1106 int res = mailimap_create(m_imap,pre.latin1());
1077 if (res != MAILIMAP_NO_ERROR) { 1107 if (res != MAILIMAP_NO_ERROR) {
1078 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 1108 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
1079 return 0; 1109 return 0;
1080 } 1110 }
1081 return 1; 1111 return 1;
1082} 1112}
1083 1113
1084int IMAPwrapper::deleteMbox(const FolderP&folder) 1114int IMAPwrapper::deleteMbox(const FolderP&folder)
1085{ 1115{
1086 if (!folder) return 0; 1116 if (!folder) return 0;
1087 login(); 1117 login();
1088 if (!m_imap) {return 0;} 1118 if (!m_imap) {return 0;}
1089 int res = mailimap_delete(m_imap,folder->getName()); 1119 int res = mailimap_delete(m_imap,folder->getName());
1090 if (res != MAILIMAP_NO_ERROR) { 1120 if (res != MAILIMAP_NO_ERROR) {
1091 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 1121 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
1092 return 0; 1122 return 0;
1093 } 1123 }
1094 return 1; 1124 return 1;
1095} 1125}
1096 1126
1097void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 1127void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
1098{ 1128{
1099 mailimap_status_att_list * att_list =0; 1129 mailimap_status_att_list * att_list =0;
1100 mailimap_mailbox_data_status * status=0; 1130 mailimap_mailbox_data_status * status=0;
1101 clistiter * cur = 0; 1131 clistiter * cur = 0;
1102 int r = 0; 1132 int r = 0;
1103 target_stat.message_count = 0; 1133 target_stat.message_count = 0;
1104 target_stat.message_unseen = 0; 1134 target_stat.message_unseen = 0;
1105 target_stat.message_recent = 0; 1135 target_stat.message_recent = 0;
1106 login(); 1136 login();
1107 if (!m_imap) { 1137 if (!m_imap) {
1108 return; 1138 return;
1109 } 1139 }
1110 att_list = mailimap_status_att_list_new_empty(); 1140 att_list = mailimap_status_att_list_new_empty();
1111 if (!att_list) return; 1141 if (!att_list) return;
1112 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); 1142 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES);
1113 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); 1143 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT);
1114 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); 1144 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN);
1115 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); 1145 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status);
1116 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { 1146 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) {
1117 for (cur = clist_begin(status->st_info_list); 1147 for (cur = clist_begin(status->st_info_list);
1118 cur != NULL ; cur = clist_next(cur)) { 1148 cur != NULL ; cur = clist_next(cur)) {
1119 mailimap_status_info * status_info; 1149 mailimap_status_info * status_info;
1120 status_info = (mailimap_status_info *)clist_content(cur); 1150 status_info = (mailimap_status_info *)clist_content(cur);
1121 switch (status_info->st_att) { 1151 switch (status_info->st_att) {
1122 case MAILIMAP_STATUS_ATT_MESSAGES: 1152 case MAILIMAP_STATUS_ATT_MESSAGES:
1123 target_stat.message_count = status_info->st_value; 1153 target_stat.message_count = status_info->st_value;
1124 break; 1154 break;
1125 case MAILIMAP_STATUS_ATT_RECENT: 1155 case MAILIMAP_STATUS_ATT_RECENT:
1126 target_stat.message_recent = status_info->st_value; 1156 target_stat.message_recent = status_info->st_value;
1127 break; 1157 break;
1128 case MAILIMAP_STATUS_ATT_UNSEEN: 1158 case MAILIMAP_STATUS_ATT_UNSEEN:
1129 target_stat.message_unseen = status_info->st_value; 1159 target_stat.message_unseen = status_info->st_value;
1130 break; 1160 break;
1131 } 1161 }
1132 } 1162 }
1133 } else { 1163 } else {
1134 // odebug << "Error retrieving status" << oendl; 1164 // odebug << "Error retrieving status" << oendl;
1135 } 1165 }
1136 if (status) mailimap_mailbox_data_status_free(status); 1166 if (status) mailimap_mailbox_data_status_free(status);
1137 if (att_list) mailimap_status_att_list_free(att_list); 1167 if (att_list) mailimap_status_att_list_free(att_list);
1138} 1168}
1139 1169
1140void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) 1170void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
1141{ 1171{
1142 login(); 1172 login();
1143 if (!m_imap) return; 1173 if (!m_imap) return;
1144 if (!msg) return; 1174 if (!msg) return;
1145 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); 1175 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length);
1146 if (r != MAILIMAP_NO_ERROR) { 1176 if (r != MAILIMAP_NO_ERROR) {
1147 Global::statusMessage("Error storing mail!"); 1177 Global::statusMessage("Error storing mail!");
1148 } 1178 }
1149} 1179}
1150 1180
1151MAILLIB::ATYPE IMAPwrapper::getType()const 1181MAILLIB::ATYPE IMAPwrapper::getType()const
1152{ 1182{
1153 return account->getType(); 1183 return account->getType();
1154} 1184}
1155 1185
1156const QString&IMAPwrapper::getName()const 1186const QString&IMAPwrapper::getName()const
1157{ 1187{
1158 // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl; 1188 // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl;
1159 return account->getAccountName(); 1189 return account->getAccountName();
1160} 1190}
1161 1191
1162encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) 1192encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail)
1163{ 1193{
1164 // dummy 1194 // dummy
1165 QValueList<int> path; 1195 QValueList<int> path;
1166 return fetchRawPart(mail,path,false); 1196 return fetchRawPart(mail,path,false);
1167} 1197}
1168 1198
1169void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, 1199void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder,
1170 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) 1200 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb)
1171{ 1201{
1172 if (targetWrapper != this || maxSizeInKb > 0 ) { 1202 if (targetWrapper != this || maxSizeInKb > 0 ) {
1173 AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb); 1203 AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb);
1174 qDebug("IMAPwrapper::mvcpAllMails::Using generic"); 1204 qDebug("IMAPwrapper::mvcpAllMails::Using generic");
1175 // odebug << "Using generic" << oendl; 1205 // odebug << "Using generic" << oendl;
1176 return; 1206 return;
1177 } 1207 }
1178 mailimap_set *set = 0; 1208 mailimap_set *set = 0;
1179 login(); 1209 login();
1180 if (!m_imap) { 1210 if (!m_imap) {
1181 return; 1211 return;
1182 } 1212 }
1183 int err = selectMbox(fromFolder->getName()); 1213 int err = selectMbox(fromFolder->getName());
1184 if ( err != MAILIMAP_NO_ERROR ) { 1214 if ( err != MAILIMAP_NO_ERROR ) {
1185 return; 1215 return;
1186 } 1216 }
1187 int last = m_imap->imap_selection_info->sel_exists; 1217 int last = m_imap->imap_selection_info->sel_exists;
1188 set = mailimap_set_new_interval( 1, last ); 1218 set = mailimap_set_new_interval( 1, last );
1189 err = mailimap_copy(m_imap,set,targetFolder.latin1()); 1219 err = mailimap_copy(m_imap,set,targetFolder.latin1());
1190 mailimap_set_free( set ); 1220 mailimap_set_free( set );
1191 if ( err != MAILIMAP_NO_ERROR ) { 1221 if ( err != MAILIMAP_NO_ERROR ) {
1192 QString error_msg = tr("error copy mails: %1").arg(m_imap->imap_response); 1222 QString error_msg = tr("Error copy mails: %1").arg(m_imap->imap_response);
1193 Global::statusMessage(error_msg); 1223 Global::statusMessage(error_msg);
1194 // odebug << error_msg << oendl; 1224 // odebug << error_msg << oendl;
1195 return; 1225 return;
1196 } 1226 }
1197 if (moveit) { 1227 if (moveit) {
1198 deleteAllMail(fromFolder); 1228 deleteAllMail(fromFolder);
1199 } 1229 }
1200} 1230}
1201 1231
1202void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 1232void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
1203{ 1233{
1204 if (targetWrapper != this) { 1234 if (targetWrapper != this) {
1205 // odebug << "Using generic" << oendl; 1235 // odebug << "Using generic" << oendl;
1206 AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); 1236 AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit);
1207 return; 1237 return;
1208 } 1238 }
1209 mailimap_set *set = 0; 1239 mailimap_set *set = 0;
1210 login(); 1240 login();
1211 if (!m_imap) { 1241 if (!m_imap) {
1212 return; 1242 return;
1213 } 1243 }
1214 int err = selectMbox(mail->getMbox()); 1244 int err = selectMbox(mail->getMbox());
1215 if ( err != MAILIMAP_NO_ERROR ) { 1245 if ( err != MAILIMAP_NO_ERROR ) {
1216 return; 1246 return;
1217 } 1247 }
1218 set = mailimap_set_new_single(mail->getNumber()); 1248 set = mailimap_set_new_single(mail->getNumber());
1219 err = mailimap_copy(m_imap,set,targetFolder.latin1()); 1249 err = mailimap_copy(m_imap,set,targetFolder.latin1());
1220 mailimap_set_free( set ); 1250 mailimap_set_free( set );
1221 if ( err != MAILIMAP_NO_ERROR ) { 1251 if ( err != MAILIMAP_NO_ERROR ) {
1222 QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response); 1252 QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response);
1223 Global::statusMessage(error_msg); 1253 Global::statusMessage(error_msg);
1224 // odebug << error_msg << oendl; 1254 // odebug << error_msg << oendl;
1225 return; 1255 return;
1226 } 1256 }
1227 if (moveit) { 1257 if (moveit) {
1228 deleteMail(mail); 1258 deleteMail(mail);
1229 } 1259 }
1230} 1260}
diff --git a/kmicromail/libmailwrapper/pop3wrapper.cpp b/kmicromail/libmailwrapper/pop3wrapper.cpp
index 7a84b30..0e6612c 100644
--- a/kmicromail/libmailwrapper/pop3wrapper.cpp
+++ b/kmicromail/libmailwrapper/pop3wrapper.cpp
@@ -1,282 +1,321 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#include <stdlib.h> 2#include <stdlib.h>
3#include "pop3wrapper.h" 3#include "pop3wrapper.h"
4#include "mailtypes.h" 4#include "mailtypes.h"
5#include "logindialog.h" 5#include "logindialog.h"
6#include <libetpan/libetpan.h> 6#include <libetpan/libetpan.h>
7 7
8 8
9#include <qpe/global.h> 9#include <qpe/global.h>
10#include <qfile.h> 10#include <qfile.h>
11#include <qprogressbar.h>
12#include <qapplication.h>
11 13
12/* we don't fetch messages larger than 5 MB */ 14/* we don't fetch messages larger than 5 MB */
13#define HARD_MSG_SIZE_LIMIT 5242880 15#define HARD_MSG_SIZE_LIMIT 5242880
14 16
15using namespace Opie::Core; 17using namespace Opie::Core;
16POP3wrapper::POP3wrapper( POP3account *a ) 18POP3wrapper::POP3wrapper( POP3account *a )
17: Genericwrapper() { 19: Genericwrapper() {
18 account = a; 20 account = a;
19 m_pop3 = NULL; 21 m_pop3 = NULL;
20 msgTempName = a->getFileName()+"_msg_cache"; 22 msgTempName = a->getFileName()+"_msg_cache";
21 last_msg_id = 0; 23 last_msg_id = 0;
22} 24}
23 25
24POP3wrapper::~POP3wrapper() { 26POP3wrapper::~POP3wrapper() {
25 logout(); 27 logout();
26 QFile msg_cache(msgTempName); 28 QFile msg_cache(msgTempName);
27 if (msg_cache.exists()) { 29 if (msg_cache.exists()) {
28 msg_cache.remove(); 30 msg_cache.remove();
29 } 31 }
30} 32}
31 33
32void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { 34void POP3wrapper::pop3_progress( size_t current, size_t maximum ) {
33 ; // odebug << "POP3: " << current << " of " << maximum << "" << oendl; 35 ; // odebug << "POP3: " << current << " of " << maximum << "" << oendl;
34} 36}
35 37
36RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) { 38RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) {
37 int err = MAILPOP3_NO_ERROR; 39 int err = MAILPOP3_NO_ERROR;
38 char *message = 0; 40 char *message = 0;
39 size_t length = 0; 41 size_t length = 0;
40 42
41 RecBodyP body = new RecBody(); 43 RecBodyP body = new RecBody();
42 44
43 login(); 45 login();
44 if ( !m_pop3 ) { 46 if ( !m_pop3 ) {
45 return body; 47 return body;
46 } 48 }
47 49
48 mailmessage * mailmsg; 50 mailmessage * mailmsg;
49 if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) { 51 if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) {
50 ; // odebug << "Message to large: " << mail->Msgsize() << "" << oendl; 52 ; // odebug << "Message to large: " << mail->Msgsize() << "" << oendl;
51 return body; 53 return body;
52 } 54 }
53 55
54 QFile msg_cache(msgTempName); 56 QFile msg_cache(msgTempName);
55 57
56 cleanMimeCache(); 58 cleanMimeCache();
57 59
58 if (mail->getNumber()!=last_msg_id) { 60 if (mail->getNumber()!=last_msg_id) {
59 if (msg_cache.exists()) { 61 if (msg_cache.exists()) {
60 msg_cache.remove(); 62 msg_cache.remove();
61 } 63 }
62 msg_cache.open(IO_ReadWrite|IO_Truncate); 64 msg_cache.open(IO_ReadWrite|IO_Truncate);
63 last_msg_id = mail->getNumber(); 65 last_msg_id = mail->getNumber();
64 err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); 66 err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg);
65 err = mailmessage_fetch(mailmsg,&message,&length); 67 err = mailmessage_fetch(mailmsg,&message,&length);
66 msg_cache.writeBlock(message,length); 68 msg_cache.writeBlock(message,length);
67 } else { 69 } else {
68 QString msg=""; 70 QString msg="";
69 msg_cache.open(IO_ReadOnly); 71 msg_cache.open(IO_ReadOnly);
70 message = new char[4096]; 72 message = new char[4096];
71 memset(message,0,4096); 73 memset(message,0,4096);
72 while (msg_cache.readBlock(message,4095)>0) { 74 while (msg_cache.readBlock(message,4095)>0) {
73 msg+=message; 75 msg+=message;
74 memset(message,0,4096); 76 memset(message,0,4096);
75 } 77 }
76 delete message; 78 delete message;
77 message = (char*)malloc(msg.length()+1*sizeof(char)); 79 message = (char*)malloc(msg.length()+1*sizeof(char));
78 memset(message,0,msg.length()+1); 80 memset(message,0,msg.length()+1);
79 memcpy(message,msg.latin1(),msg.length()); 81 memcpy(message,msg.latin1(),msg.length());
80 /* transform to libetpan stuff */ 82 /* transform to libetpan stuff */
81 mailmsg = mailmessage_new(); 83 mailmsg = mailmessage_new();
82 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); 84 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message));
83 generic_message_t * msg_data; 85 generic_message_t * msg_data;
84 msg_data = (generic_message_t *)mailmsg->msg_data; 86 msg_data = (generic_message_t *)mailmsg->msg_data;
85 msg_data->msg_fetched = 1; 87 msg_data->msg_fetched = 1;
86 msg_data->msg_message = message; 88 msg_data->msg_message = message;
87 msg_data->msg_length = strlen(message); 89 msg_data->msg_length = strlen(message);
88 } 90 }
89 body = parseMail(mailmsg); 91 body = parseMail(mailmsg);
90 92
91 /* clean up */ 93 /* clean up */
92 if (mailmsg) 94 if (mailmsg)
93 mailmessage_free(mailmsg); 95 mailmessage_free(mailmsg);
94 if (message) 96 if (message)
95 free(message); 97 free(message);
96 98
97 return body; 99 return body;
98} 100}
99 101
100void POP3wrapper::listMessages(const QString &, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb ) 102void POP3wrapper::listMessages(const QString &, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb )
101{ 103{
102 login(); 104 login();
103 if (!m_pop3) 105 if (!m_pop3)
104 return; 106 return;
105 uint32_t res_messages,res_recent,res_unseen; 107 uint32_t res_messages,res_recent,res_unseen;
106 mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen); 108 mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen);
107 parseList(target,m_pop3->sto_session,"INBOX", false, maxSizeInKb); 109 parseList(target,m_pop3->sto_session,"INBOX", false, maxSizeInKb);
108 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); 110 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages));
109} 111}
110 112
111void POP3wrapper::login() 113void POP3wrapper::login()
112{ 114{
113 if (account->getOffline()) 115 if (account->getOffline())
114 return; 116 return;
115 /* we'll hold the line */ 117 /* we'll hold the line */
116 if ( m_pop3 != NULL ) 118 if ( m_pop3 != NULL )
117 return; 119 return;
118 120
119 const char *server, *user, *pass; 121 const char *server, *user, *pass;
120 uint16_t port; 122 uint16_t port;
121 int err = MAILPOP3_NO_ERROR; 123 int err = MAILPOP3_NO_ERROR;
122 124
123 server = account->getServer().latin1(); 125 server = account->getServer().latin1();
124 port = account->getPort().toUInt(); 126 port = account->getPort().toUInt();
125 127
126 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 128 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
127 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 129 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
128 login.show(); 130 login.show();
129 if ( QDialog::Accepted == login.exec() ) { 131 if ( QDialog::Accepted == login.exec() ) {
130 // ok 132 // ok
131 user = login.getUser().latin1(); 133 user = login.getUser().latin1();
132 pass = login.getPassword().latin1(); 134 pass = login.getPassword().latin1();
133 } else { 135 } else {
134 // cancel 136 // cancel
135 ; // odebug << "POP3: Login canceled" << oendl; 137 ; // odebug << "POP3: Login canceled" << oendl;
136 return; 138 return;
137 } 139 }
138 } else { 140 } else {
139 user = account->getUser().latin1(); 141 user = account->getUser().latin1();
140 pass = account->getPassword().latin1(); 142 pass = account->getPassword().latin1();
141 } 143 }
142 144
143 // bool ssl = account->getSSL(); 145 // bool ssl = account->getSSL();
144 146
145 m_pop3=mailstorage_new(NULL); 147 m_pop3=mailstorage_new(NULL);
146 148
147 int conntypeset = account->ConnectionType(); 149 int conntypeset = account->ConnectionType();
148 int conntype = 0; 150 int conntype = 0;
149 if ( conntypeset == 3 ) { 151 if ( conntypeset == 3 ) {
150 conntype = CONNECTION_TYPE_COMMAND; 152 conntype = CONNECTION_TYPE_COMMAND;
151 } else if ( conntypeset == 2 ) { 153 } else if ( conntypeset == 2 ) {
152 conntype = CONNECTION_TYPE_TLS; 154 conntype = CONNECTION_TYPE_TLS;
153 } else if ( conntypeset == 1 ) { 155 } else if ( conntypeset == 1 ) {
154 conntype = CONNECTION_TYPE_STARTTLS; 156 conntype = CONNECTION_TYPE_STARTTLS;
155 } else if ( conntypeset == 0 ) { 157 } else if ( conntypeset == 0 ) {
156 conntype = CONNECTION_TYPE_TRY_STARTTLS; 158 conntype = CONNECTION_TYPE_TRY_STARTTLS;
157 } 159 }
158 160
159 //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN); 161 //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN);
160 162
161 pop3_mailstorage_init(m_pop3,(char*)server, port, NULL, conntype, POP3_AUTH_TYPE_PLAIN, 163 pop3_mailstorage_init(m_pop3,(char*)server, port, NULL, conntype, POP3_AUTH_TYPE_PLAIN,
162 (char*)user,(char*)pass,0,0,0); 164 (char*)user,(char*)pass,0,0,0);
163 165
164 166
165 err = mailstorage_connect(m_pop3); 167 err = mailstorage_connect(m_pop3);
166 if (err != MAIL_NO_ERROR) { 168 if (err != MAIL_NO_ERROR) {
167 ; // odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; 169 ; // odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl;
168 Global::statusMessage(tr("Error initializing folder")); 170 Global::statusMessage(tr("Error initializing folder"));
169 mailstorage_free(m_pop3); 171 mailstorage_free(m_pop3);
170 m_pop3 = 0; 172 m_pop3 = 0;
171 } else { 173 } else {
172 mailsession * session = m_pop3->sto_session; 174 mailsession * session = m_pop3->sto_session;
173 mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session; 175 mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session;
174 if (mail) { 176 if (mail) {
175 mail->pop3_progr_fun = &pop3_progress; 177 mail->pop3_progr_fun = &pop3_progress;
176 } 178 }
177 } 179 }
178} 180}
179 181
180void POP3wrapper::logout() 182void POP3wrapper::logout()
181{ 183{
182 if ( m_pop3 == NULL ) 184 if ( m_pop3 == NULL )
183 return; 185 return;
184 mailstorage_free(m_pop3); 186 mailstorage_free(m_pop3);
185 m_pop3 = 0; 187 m_pop3 = 0;
186} 188}
187 189
188 190
189QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() { 191QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() {
190 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>(); 192 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>();
191 FolderP inb=new Folder("INBOX","/"); 193 FolderP inb=new Folder("INBOX","/");
192 folders->append(inb); 194 folders->append(inb);
193 return folders; 195 return folders;
194} 196}
195 197
196void POP3wrapper::deleteMailList(QValueList<RecMailP>&target) 198void POP3wrapper::deleteMailList(const QValueList<RecMailP>&target)
197{ 199{
198 login(); 200 login();
199 if (!m_pop3) 201 if (!m_pop3)
200 return; 202 return;
201 int iii = 0; 203 int iii = 0;
202 int count = target.count(); 204 int count = target.count();
203 while (iii < count ) { 205 QProgressBar bar( count,0 );
206 bar.setCaption (("Removing mails - close to abort!") );
207 int w = 300;
208 if ( QApplication::desktop()->width() < 320 )
209 w = 220;
210 int h = bar.sizeHint().height() ;
211 int dw = QApplication::desktop()->width();
212 int dh = QApplication::desktop()->height();
213 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
214 bar.show();
215 int modulo = (count/10)+1;
216 int incCounter = 0;
217 while (iii < count ) {
218 if ( ! bar.isVisible() )
219 return ;
220 if ( incCounter % modulo == 0 )
221 bar.setProgress( incCounter );
222 ++incCounter;
223 qApp->processEvents();
224 //qDebug("delete ");
204 RecMailP mail = (*target.at( iii )); 225 RecMailP mail = (*target.at( iii ));
205 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); 226 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber());
206 if (err != MAIL_NO_ERROR) { 227 if (err != MAIL_NO_ERROR) {
207 Global::statusMessage(tr("error deleting mail")); 228 Global::statusMessage(tr("Error deleting mail"));
208 } 229 }
209 ++iii; 230 ++iii;
210 } 231 }
211} 232}
212void POP3wrapper::deleteMail(const RecMailP&mail) { 233void POP3wrapper::deleteMail(const RecMailP&mail) {
213 login(); 234 login();
214 if (!m_pop3) 235 if (!m_pop3)
215 return; 236 return;
216 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); 237 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber());
217 if (err != MAIL_NO_ERROR) { 238 if (err != MAIL_NO_ERROR) {
218 Global::statusMessage(tr("error deleting mail")); 239 Global::statusMessage(tr("error deleting mail"));
219 } 240 }
220} 241}
221 242
222void POP3wrapper::answeredMail(const RecMailP&) {} 243void POP3wrapper::answeredMail(const RecMailP&) {}
223 244
224int POP3wrapper::deleteAllMail(const FolderP&) { 245int POP3wrapper::deleteAllMail(const FolderP&) {
225 login(); 246 login();
226 if (!m_pop3) 247 if (!m_pop3)
227 return 0; 248 return 0;
228 int res = 1; 249 int res = 1;
229 250
230 uint32_t result = 0; 251 uint32_t result = 0;
231 int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result); 252 int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result);
232 if (err != MAIL_NO_ERROR) { 253 if (err != MAIL_NO_ERROR) {
233 Global::statusMessage(tr("Error getting folder info")); 254 Global::statusMessage(tr("Error getting folder info"));
234 return 0; 255 return 0;
235 } 256 }
257 QProgressBar bar( result,0 );
258 bar.setCaption (("Deleting mails - close to abort!") );
259 int w = 300;
260 if ( QApplication::desktop()->width() < 320 )
261 w = 220;
262 int h = bar.sizeHint().height() ;
263 int dw = QApplication::desktop()->width();
264 int dh = QApplication::desktop()->height();
265 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
266 bar.show();
267 int modulo = (result/10)+1;
268 int incCounter = 0;
236 for (unsigned int i = 0; i < result; ++i) { 269 for (unsigned int i = 0; i < result; ++i) {
270 if ( ! bar.isVisible() )
271 return 0;
272 if ( incCounter % modulo == 0 )
273 bar.setProgress( incCounter );
274 ++incCounter;
275 qApp->processEvents();
237 err = mailsession_remove_message(m_pop3->sto_session,i+1); 276 err = mailsession_remove_message(m_pop3->sto_session,i+1);
238 if (err != MAIL_NO_ERROR) { 277 if (err != MAIL_NO_ERROR) {
239 Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); 278 Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
240 res=0; 279 res=0;
241 } 280 }
242 break; 281 break;
243 } 282 }
244 return res; 283 return res;
245} 284}
246 285
247void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { 286void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) {
248 login(); 287 login();
249 target_stat.message_count = 0; 288 target_stat.message_count = 0;
250 target_stat.message_unseen = 0; 289 target_stat.message_unseen = 0;
251 target_stat.message_recent = 0; 290 target_stat.message_recent = 0;
252 if (!m_pop3) 291 if (!m_pop3)
253 return; 292 return;
254 int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count, 293 int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count,
255 &target_stat.message_recent,&target_stat.message_unseen); 294 &target_stat.message_recent,&target_stat.message_unseen);
256 if (r != MAIL_NO_ERROR) { 295 if (r != MAIL_NO_ERROR) {
257 ; // odebug << "error getting folter status." << oendl; 296 ; // odebug << "error getting folter status." << oendl;
258 } 297 }
259} 298}
260 299
261encodedString* POP3wrapper::fetchRawBody(const RecMailP&mail) { 300encodedString* POP3wrapper::fetchRawBody(const RecMailP&mail) {
262 char*target=0; 301 char*target=0;
263 size_t length=0; 302 size_t length=0;
264 encodedString*res = 0; 303 encodedString*res = 0;
265 mailmessage * mailmsg = 0; 304 mailmessage * mailmsg = 0;
266 int err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); 305 int err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg);
267 err = mailmessage_fetch(mailmsg,&target,&length); 306 err = mailmessage_fetch(mailmsg,&target,&length);
268 if (mailmsg) 307 if (mailmsg)
269 mailmessage_free(mailmsg); 308 mailmessage_free(mailmsg);
270 if (target) { 309 if (target) {
271 res = new encodedString(target,length); 310 res = new encodedString(target,length);
272 } 311 }
273 return res; 312 return res;
274} 313}
275 314
276MAILLIB::ATYPE POP3wrapper::getType()const { 315MAILLIB::ATYPE POP3wrapper::getType()const {
277 return account->getType(); 316 return account->getType();
278} 317}
279 318
280const QString&POP3wrapper::getName()const{ 319const QString&POP3wrapper::getName()const{
281 return account->getAccountName(); 320 return account->getAccountName();
282} 321}
diff --git a/kmicromail/libmailwrapper/pop3wrapper.h b/kmicromail/libmailwrapper/pop3wrapper.h
index ee754a4..7c70942 100644
--- a/kmicromail/libmailwrapper/pop3wrapper.h
+++ b/kmicromail/libmailwrapper/pop3wrapper.h
@@ -1,44 +1,44 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#ifndef __POP3WRAPPER 2#ifndef __POP3WRAPPER
3#define __POP3WRAPPER 3#define __POP3WRAPPER
4 4
5#include "mailwrapper.h" 5#include "mailwrapper.h"
6#include "genericwrapper.h" 6#include "genericwrapper.h"
7#include <qstring.h> 7#include <qstring.h>
8 8
9class encodedString; 9class encodedString;
10struct mailstorage; 10struct mailstorage;
11struct mailfolder; 11struct mailfolder;
12 12
13class POP3wrapper : public Genericwrapper 13class POP3wrapper : public Genericwrapper
14{ 14{
15 Q_OBJECT 15 Q_OBJECT
16 16
17public: 17public:
18 POP3wrapper( POP3account *a ); 18 POP3wrapper( POP3account *a );
19 virtual ~POP3wrapper(); 19 virtual ~POP3wrapper();
20 /* mailbox will be ignored */ 20 /* mailbox will be ignored */
21 virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb = 0 ); 21 virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb = 0 );
22 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); 22 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders();
23 /* mailbox will be ignored */ 23 /* mailbox will be ignored */
24 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 24 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
25 25
26 virtual void deleteMail(const RecMailP&mail); 26 virtual void deleteMail(const RecMailP&mail);
27 virtual void deleteMailList(const QValueList<RecMailP>&target);
27 virtual void answeredMail(const RecMailP&mail); 28 virtual void answeredMail(const RecMailP&mail);
28 virtual void deleteMailList(QValueList<RecMailP>&target);
29 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&); 29 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&);
30 30
31 virtual RecBodyP fetchBody( const RecMailP &mail ); 31 virtual RecBodyP fetchBody( const RecMailP &mail );
32 virtual encodedString* fetchRawBody(const RecMailP&mail); 32 virtual encodedString* fetchRawBody(const RecMailP&mail);
33 virtual void logout(); 33 virtual void logout();
34 virtual MAILLIB::ATYPE getType()const; 34 virtual MAILLIB::ATYPE getType()const;
35 virtual const QString&getName()const; 35 virtual const QString&getName()const;
36 static void pop3_progress( size_t current, size_t maximum ); 36 static void pop3_progress( size_t current, size_t maximum );
37 37
38protected: 38protected:
39 void login(); 39 void login();
40 POP3account *account; 40 POP3account *account;
41 mailstorage*m_pop3; 41 mailstorage*m_pop3;
42}; 42};
43 43
44#endif 44#endif