summaryrefslogtreecommitdiffabout
path: root/kmicromail/libmailwrapper
authorzautrix <zautrix>2004-10-18 11:01:02 (UTC)
committer zautrix <zautrix>2004-10-18 11:01:02 (UTC)
commitc613ac44ea26c66305252feb4ed4ad17f79b5cc6 (patch) (unidiff)
tree3dbdfc228c6103025781a20292f8855b24b55dd1 /kmicromail/libmailwrapper
parenta83b6694d2f80ec58f6eb88684897052c69276a0 (diff)
downloadkdepimpi-c613ac44ea26c66305252feb4ed4ad17f79b5cc6.zip
kdepimpi-c613ac44ea26c66305252feb4ed4ad17f79b5cc6.tar.gz
kdepimpi-c613ac44ea26c66305252feb4ed4ad17f79b5cc6.tar.bz2
some mail imap changes
Diffstat (limited to 'kmicromail/libmailwrapper') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/imapwrapper.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp
index a6688ed..8150453 100644
--- a/kmicromail/libmailwrapper/imapwrapper.cpp
+++ b/kmicromail/libmailwrapper/imapwrapper.cpp
@@ -1,433 +1,433 @@
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#include <qprogressbar.h>
10#include "genericwrapper.h" 10#include "genericwrapper.h"
11#include <kglobal.h> 11#include <kglobal.h>
12 12
13using namespace Opie::Core; 13using namespace Opie::Core;
14int IMAPwrapper::mMax = 0; 14int IMAPwrapper::mMax = 0;
15int IMAPwrapper::mCurrent = 0; 15int IMAPwrapper::mCurrent = 0;
16 16
17IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 17IMAPwrapper::IMAPwrapper( IMAPaccount *a )
18 : AbstractMail() 18 : AbstractMail()
19{ 19{
20 account = a; 20 account = a;
21 m_imap = 0; 21 m_imap = 0;
22 m_Lastmbox = ""; 22 m_Lastmbox = "";
23 mCurrent = 0; 23 mCurrent = 0;
24 mMax = 0; 24 mMax = 0;
25} 25}
26 26
27IMAPwrapper::~IMAPwrapper() 27IMAPwrapper::~IMAPwrapper()
28{ 28{
29 logout(); 29 logout();
30} 30}
31 31
32/* to avoid to often select statements in loops etc. 32/* to avoid to often select statements in loops etc.
33 we trust that we are logged in and connection is established!*/ 33 we trust that we are logged in and connection is established!*/
34int IMAPwrapper::selectMbox(const QString&mbox) 34int IMAPwrapper::selectMbox(const QString&mbox)
35{ 35{
36 if (mbox == m_Lastmbox) { 36 if (mbox == m_Lastmbox) {
37 return MAILIMAP_NO_ERROR; 37 return MAILIMAP_NO_ERROR;
38 } 38 }
39 int err = mailimap_select( m_imap, (char*)mbox.latin1()); 39 int err = mailimap_select( m_imap, (char*)mbox.latin1());
40 if ( err != MAILIMAP_NO_ERROR ) { 40 if ( err != MAILIMAP_NO_ERROR ) {
41 m_Lastmbox = ""; 41 m_Lastmbox = "";
42 return err; 42 return err;
43 } 43 }
44 m_Lastmbox = mbox; 44 m_Lastmbox = mbox;
45 return err; 45 return err;
46} 46}
47 47
48void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 48void IMAPwrapper::imap_progress( size_t current, size_t maximum )
49{ 49{
50 //qDebug("imap progress %d of %d ",current,maximum ); 50 //qDebug("imap progress %d of %d ",current,maximum );
51 //Global::statusMessage(tr("Downloading message %1 of %2").arg( current).arg(maximum)); 51 //Global::statusMessage(tr("Downloading message %1 of %2").arg( current).arg(maximum));
52 //qApp->processEvents() 52 //qApp->processEvents()
53 static int last = 0; 53 static int last = 0;
54 if ( last != current ) 54 if ( last != current )
55 IMAPwrapper::progress(); 55 IMAPwrapper::progress();
56 last = current; 56 last = current;
57} 57}
58void IMAPwrapper::progress( QString m ) 58void IMAPwrapper::progress( QString m )
59{ 59{
60 60
61 static QString mProgrMess; 61 static QString mProgrMess;
62 if ( m != QString::null ) { 62 if ( m != QString::null ) {
63 mProgrMess = m; 63 mProgrMess = m;
64 mCurrent = 1; 64 mCurrent = 1;
65 return; 65 return;
66 } 66 }
67 QString mess; 67 QString mess;
68 //qDebug("progress "); 68 //qDebug("progress ");
69 if ( mMax ) mess = mProgrMess +tr(" message %1 of %2").arg( mCurrent++).arg(mMax); 69 if ( mMax ) mess = mProgrMess +tr(" message %1 of %2").arg( mCurrent++).arg(mMax);
70 else mess = mProgrMess +tr(" message %1").arg( mCurrent++); 70 else mess = mProgrMess +tr(" message %1").arg( mCurrent++);
71 Global::statusMessage(mess); 71 Global::statusMessage(mess);
72 qDebug("Progress %s %s", mess.latin1(), m.latin1()); 72 //qDebug("Progress %s %s", mess.latin1(), m.latin1());
73 qApp->processEvents(); 73 qApp->processEvents();
74} 74}
75bool IMAPwrapper::start_tls(bool force_tls) 75bool IMAPwrapper::start_tls(bool force_tls)
76{ 76{
77 int err; 77 int err;
78 bool try_tls; 78 bool try_tls;
79 mailimap_capability_data * cap_data = 0; 79 mailimap_capability_data * cap_data = 0;
80 80
81 err = mailimap_capability(m_imap,&cap_data); 81 err = mailimap_capability(m_imap,&cap_data);
82 if (err != MAILIMAP_NO_ERROR) { 82 if (err != MAILIMAP_NO_ERROR) {
83 Global::statusMessage("error getting capabilities!"); 83 Global::statusMessage("error getting capabilities!");
84 return false; 84 return false;
85 } 85 }
86 clistiter * cur; 86 clistiter * cur;
87 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { 87 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) {
88 struct mailimap_capability * cap; 88 struct mailimap_capability * cap;
89 cap = (struct mailimap_capability *)clist_content(cur); 89 cap = (struct mailimap_capability *)clist_content(cur);
90 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { 90 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) {
91 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { 91 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) {
92 try_tls = true; 92 try_tls = true;
93 break; 93 break;
94 } 94 }
95 } 95 }
96 } 96 }
97 if (cap_data) { 97 if (cap_data) {
98 mailimap_capability_data_free(cap_data); 98 mailimap_capability_data_free(cap_data);
99 } 99 }
100 if (try_tls) { 100 if (try_tls) {
101 err = mailimap_starttls(m_imap); 101 err = mailimap_starttls(m_imap);
102 if (err != MAILIMAP_NO_ERROR && force_tls) { 102 if (err != MAILIMAP_NO_ERROR && force_tls) {
103 Global::statusMessage(tr("Server has no TLS support!")); 103 Global::statusMessage(tr("Server has no TLS support!"));
104 try_tls = false; 104 try_tls = false;
105 } else { 105 } else {
106 mailstream_low * low; 106 mailstream_low * low;
107 mailstream_low * new_low; 107 mailstream_low * new_low;
108 low = mailstream_get_low(m_imap->imap_stream); 108 low = mailstream_get_low(m_imap->imap_stream);
109 if (!low) { 109 if (!low) {
110 try_tls = false; 110 try_tls = false;
111 } else { 111 } else {
112 int fd = mailstream_low_get_fd(low); 112 int fd = mailstream_low_get_fd(low);
113 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { 113 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
114 mailstream_low_free(low); 114 mailstream_low_free(low);
115 mailstream_set_low(m_imap->imap_stream, new_low); 115 mailstream_set_low(m_imap->imap_stream, new_low);
116 } else { 116 } else {
117 try_tls = false; 117 try_tls = false;
118 } 118 }
119 } 119 }
120 } 120 }
121 } 121 }
122 return try_tls; 122 return try_tls;
123} 123}
124 124
125void IMAPwrapper::login() 125void IMAPwrapper::login()
126{ 126{
127 QString server, user, pass; 127 QString server, user, pass;
128 uint16_t port; 128 uint16_t port;
129 int err = MAILIMAP_NO_ERROR; 129 int err = MAILIMAP_NO_ERROR;
130 130
131 if (account->getOffline()) return; 131 if (account->getOffline()) return;
132 /* we are connected this moment */ 132 /* we are connected this moment */
133 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 133 /* TODO: setup a timer holding the line or if connection closed - delete the value */
134 if (m_imap) { 134 if (m_imap) {
135 err = mailimap_noop(m_imap); 135 err = mailimap_noop(m_imap);
136 if (err!=MAILIMAP_NO_ERROR) { 136 if (err!=MAILIMAP_NO_ERROR) {
137 logout(); 137 logout();
138 } else { 138 } else {
139 mailstream_flush(m_imap->imap_stream); 139 mailstream_flush(m_imap->imap_stream);
140 return; 140 return;
141 } 141 }
142 } 142 }
143 server = account->getServer(); 143 server = account->getServer();
144 port = account->getPort().toUInt(); 144 port = account->getPort().toUInt();
145 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 145 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
146 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 146 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
147 login.show(); 147 login.show();
148 if ( QDialog::Accepted == login.exec() ) { 148 if ( QDialog::Accepted == login.exec() ) {
149 // ok 149 // ok
150 user = login.getUser(); 150 user = login.getUser();
151 pass = login.getPassword(); 151 pass = login.getPassword();
152 } else { 152 } else {
153 // cancel 153 // cancel
154 return; 154 return;
155 } 155 }
156 } else { 156 } else {
157 user = account->getUser(); 157 user = account->getUser();
158 pass = account->getPassword(); 158 pass = account->getPassword();
159 } 159 }
160 160
161 m_imap = mailimap_new( 20, &imap_progress ); 161 m_imap = mailimap_new( 20, &imap_progress );
162 162
163 /* connect */ 163 /* connect */
164 bool ssl = false; 164 bool ssl = false;
165 bool try_tls = false; 165 bool try_tls = false;
166 bool force_tls = false; 166 bool force_tls = false;
167 167
168 if ( account->ConnectionType() == 2 ) { 168 if ( account->ConnectionType() == 2 ) {
169 ssl = true; 169 ssl = true;
170 } 170 }
171 if (account->ConnectionType()==1) { 171 if (account->ConnectionType()==1) {
172 force_tls = true; 172 force_tls = true;
173 } 173 }
174 174
175 if ( ssl ) { 175 if ( ssl ) {
176 //qDebug("using ssl "); 176 //qDebug("using ssl ");
177 err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port ); 177 err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port );
178 } else { 178 } else {
179 err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port ); 179 err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port );
180 } 180 }
181 181
182 if ( err != MAILIMAP_NO_ERROR && 182 if ( err != MAILIMAP_NO_ERROR &&
183 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 183 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
184 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 184 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
185 QString failure = ""; 185 QString failure = "";
186 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { 186 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) {
187 failure="Connection refused"; 187 failure="Connection refused";
188 } else { 188 } else {
189 failure="Unknown failure"; 189 failure="Unknown failure";
190 } 190 }
191 Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); 191 Global::statusMessage(tr("error connecting imap server: %1").arg(failure));
192 mailimap_free( m_imap ); 192 mailimap_free( m_imap );
193 m_imap = 0; 193 m_imap = 0;
194 return; 194 return;
195 } 195 }
196 196
197 if (!ssl) { 197 if (!ssl) {
198 try_tls = start_tls(force_tls); 198 try_tls = start_tls(force_tls);
199 } 199 }
200 200
201 bool ok = true; 201 bool ok = true;
202 if (force_tls && !try_tls) { 202 if (force_tls && !try_tls) {
203 Global::statusMessage(tr("Server has no TLS support!")); 203 Global::statusMessage(tr("Server has no TLS support!"));
204 ok = false; 204 ok = false;
205 } 205 }
206 206
207 207
208 /* login */ 208 /* login */
209 209
210 if (ok) { 210 if (ok) {
211 err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() ); 211 err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() );
212 if ( err != MAILIMAP_NO_ERROR ) { 212 if ( err != MAILIMAP_NO_ERROR ) {
213 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); 213 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response));
214 ok = false; 214 ok = false;
215 } 215 }
216 } 216 }
217 if (!ok) { 217 if (!ok) {
218 err = mailimap_close( m_imap ); 218 err = mailimap_close( m_imap );
219 mailimap_free( m_imap ); 219 mailimap_free( m_imap );
220 m_imap = 0; 220 m_imap = 0;
221 } 221 }
222} 222}
223 223
224void IMAPwrapper::logout() 224void IMAPwrapper::logout()
225{ 225{
226 int err = MAILIMAP_NO_ERROR; 226 int err = MAILIMAP_NO_ERROR;
227 if (!m_imap) return; 227 if (!m_imap) return;
228 err = mailimap_logout( m_imap ); 228 err = mailimap_logout( m_imap );
229 err = mailimap_close( m_imap ); 229 err = mailimap_close( m_imap );
230 mailimap_free( m_imap ); 230 mailimap_free( m_imap );
231 m_imap = 0; 231 m_imap = 0;
232 m_Lastmbox = ""; 232 m_Lastmbox = "";
233} 233}
234 234
235void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb) 235void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb)
236{ 236{
237 237
238 int tryAgain = 1; 238 int tryAgain = 1;
239 while ( tryAgain >= 0 ) { 239 while ( tryAgain >= 0 ) {
240 int err = MAILIMAP_NO_ERROR; 240 int err = MAILIMAP_NO_ERROR;
241 clist *result = 0; 241 clist *result = 0;
242 clistcell *current; 242 clistcell *current;
243 mailimap_fetch_type *fetchType = 0; 243 mailimap_fetch_type *fetchType = 0;
244 mailimap_set *set = 0; 244 mailimap_set *set = 0;
245 245
246 login(); 246 login();
247 if (!m_imap) { 247 if (!m_imap) {
248 return; 248 return;
249 } 249 }
250 /* select mailbox READONLY for operations */ 250 /* select mailbox READONLY for operations */
251 err = selectMbox(mailbox); 251 err = selectMbox(mailbox);
252 if ( err != MAILIMAP_NO_ERROR ) { 252 if ( err != MAILIMAP_NO_ERROR ) {
253 return; 253 return;
254 } 254 }
255 255
256 int last = m_imap->imap_selection_info->sel_exists; 256 int last = m_imap->imap_selection_info->sel_exists;
257 257
258 if (last == 0) { 258 if (last == 0) {
259 Global::statusMessage(tr("Mailbox has no mails")); 259 Global::statusMessage(tr("Mailbox has no mails"));
260 return; 260 return;
261 } else { 261 } else {
262 } 262 }
263 progress( tr("Fetch ")); 263 progress( tr("Fetch "));
264 mMax = last; 264 mMax = last;
265 //qDebug("last %d ", last); 265 //qDebug("last %d ", last);
266 Global::statusMessage(tr("Fetching header list")); 266 Global::statusMessage(tr("Fetching header list"));
267 qApp->processEvents(); 267 qApp->processEvents();
268 /* the range has to start at 1!!! not with 0!!!! */ 268 /* the range has to start at 1!!! not with 0!!!! */
269 //LR the access to web.de imap server is no working with value 1 269 //LR the access to web.de imap server is no working with value 1
270 qDebug("interval %d - %d ", tryAgain, last-1+tryAgain ); 270 //qDebug("interval %d - %d ", tryAgain, last-1+tryAgain );
271 set = mailimap_set_new_interval( tryAgain, last ); 271 set = mailimap_set_new_interval( tryAgain, last );
272 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 272 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
273 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 273 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
274 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 274 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
275 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 275 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
276 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 276 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
277 277
278 err = mailimap_fetch( m_imap, set, fetchType, &result ); 278 err = mailimap_fetch( m_imap, set, fetchType, &result );
279 mailimap_set_free( set ); 279 mailimap_set_free( set );
280 mailimap_fetch_type_free( fetchType ); 280 mailimap_fetch_type_free( fetchType );
281 281
282 QString date,subject,from; 282 QString date,subject,from;
283 283
284 if ( err == MAILIMAP_NO_ERROR ) { 284 if ( err == MAILIMAP_NO_ERROR ) {
285 tryAgain = -1; 285 tryAgain = -1;
286 mailimap_msg_att * msg_att; 286 mailimap_msg_att * msg_att;
287 int i = 0; 287 int i = 0;
288 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 288 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
289 ++i; 289 ++i;
290 //qDebug("iii %d ",i); 290 //qDebug("iii %d ",i);
291 msg_att = (mailimap_msg_att*)current->data; 291 msg_att = (mailimap_msg_att*)current->data;
292 RecMail*m = parse_list_result(msg_att); 292 RecMail*m = parse_list_result(msg_att);
293 if (m) { 293 if (m) {
294 if ( maxSizeInKb == 0 || m->Msgsize()<=maxSizeInKb*1024 ) { 294 if ( maxSizeInKb == 0 || m->Msgsize()<=maxSizeInKb*1024 ) {
295 m->setNumber(i); 295 m->setNumber(i);
296 m->setMbox(mailbox); 296 m->setMbox(mailbox);
297 m->setWrapper(this); 297 m->setWrapper(this);
298 target.append(m); 298 target.append(m);
299 } 299 }
300 } 300 }
301 } 301 }
302 Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); 302 Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count()));
303 } else { 303 } else {
304 --tryAgain; 304 --tryAgain;
305 --tryAgain; 305 --tryAgain;//disabled tryagain by adding this line
306 if ( tryAgain < 0 ) 306 if ( tryAgain < 0 )
307 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); 307 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response));
308 else 308 else
309 qDebug("try again... "); 309 qDebug("try again... ");
310 } 310 }
311 311
312 if (result) mailimap_fetch_list_free(result); 312 if (result) mailimap_fetch_list_free(result);
313 } 313 }
314} 314}
315 315
316QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() 316QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders()
317{ 317{
318 const char *path, *mask; 318 const char *path, *mask;
319 int err = MAILIMAP_NO_ERROR; 319 int err = MAILIMAP_NO_ERROR;
320 clist *result = 0; 320 clist *result = 0;
321 clistcell *current = 0; 321 clistcell *current = 0;
322 clistcell*cur_flag = 0; 322 clistcell*cur_flag = 0;
323 mailimap_mbx_list_flags*bflags = 0; 323 mailimap_mbx_list_flags*bflags = 0;
324 324
325 QValueList<FolderP>* folders = new QValueList<FolderP>(); 325 QValueList<FolderP>* folders = new QValueList<FolderP>();
326 login(); 326 login();
327 if (!m_imap) { 327 if (!m_imap) {
328 return folders; 328 return folders;
329 } 329 }
330 330
331/* 331/*
332 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 332 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
333 * We must not forget to filter them out in next loop! 333 * We must not forget to filter them out in next loop!
334 * it seems like ugly code. and yes - it is ugly code. but the best way. 334 * it seems like ugly code. and yes - it is ugly code. but the best way.
335 */ 335 */
336 Global::statusMessage(tr("Fetching folder list")); 336 Global::statusMessage(tr("Fetching folder list"));
337 qApp->processEvents(); 337 qApp->processEvents();
338 QString temp; 338 QString temp;
339 mask = "INBOX" ; 339 mask = "INBOX" ;
340 mailimap_mailbox_list *list; 340 mailimap_mailbox_list *list;
341 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 341 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
342 QString del; 342 QString del;
343 bool selectable = true; 343 bool selectable = true;
344 bool no_inferiors = false; 344 bool no_inferiors = false;
345 if ( err == MAILIMAP_NO_ERROR ) { 345 if ( err == MAILIMAP_NO_ERROR ) {
346 current = result->first; 346 current = result->first;
347 for ( int i = result->count; i > 0; i-- ) { 347 for ( int i = result->count; i > 0; i-- ) {
348 list = (mailimap_mailbox_list *) current->data; 348 list = (mailimap_mailbox_list *) current->data;
349 // it is better use the deep copy mechanism of qt itself 349 // it is better use the deep copy mechanism of qt itself
350 // instead of using strdup! 350 // instead of using strdup!
351 temp = list->mb_name; 351 temp = list->mb_name;
352 del = list->mb_delimiter; 352 del = list->mb_delimiter;
353 current = current->next; 353 current = current->next;
354 if ( (bflags = list->mb_flag) ) { 354 if ( (bflags = list->mb_flag) ) {
355 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 355 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
356 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 356 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
357 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 357 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
358 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 358 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
359 no_inferiors = true; 359 no_inferiors = true;
360 } 360 }
361 } 361 }
362 } 362 }
363 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 363 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
364 } 364 }
365 } else { 365 } else {
366 qDebug("error fetching folders: "); 366 qDebug("error fetching folders: ");
367 367
368 } 368 }
369 mailimap_list_result_free( result ); 369 mailimap_list_result_free( result );
370 370
371/* 371/*
372 * second stage - get the other then inbox folders 372 * second stage - get the other then inbox folders
373 */ 373 */
374 mask = "*" ; 374 mask = "*" ;
375 path = account->getPrefix().latin1(); 375 path = account->getPrefix().latin1();
376 if (!path) path = ""; 376 if (!path) path = "";
377 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 377 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
378 if ( err == MAILIMAP_NO_ERROR ) { 378 if ( err == MAILIMAP_NO_ERROR ) {
379 current = result->first; 379 current = result->first;
380 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 380 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
381 no_inferiors = false; 381 no_inferiors = false;
382 list = (mailimap_mailbox_list *) current->data; 382 list = (mailimap_mailbox_list *) current->data;
383 // it is better use the deep copy mechanism of qt itself 383 // it is better use the deep copy mechanism of qt itself
384 // instead of using strdup! 384 // instead of using strdup!
385 temp = list->mb_name; 385 temp = list->mb_name;
386 if (temp.lower()=="inbox") 386 if (temp.lower()=="inbox")
387 continue; 387 continue;
388 if (temp.lower()==account->getPrefix().lower()) 388 if (temp.lower()==account->getPrefix().lower())
389 continue; 389 continue;
390 if ( (bflags = list->mb_flag) ) { 390 if ( (bflags = list->mb_flag) ) {
391 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 391 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
392 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 392 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
393 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 393 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
394 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 394 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
395 no_inferiors = true; 395 no_inferiors = true;
396 } 396 }
397 } 397 }
398 } 398 }
399 del = list->mb_delimiter; 399 del = list->mb_delimiter;
400 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 400 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
401 } 401 }
402 } else { 402 } else {
403 qDebug("error fetching folders "); 403 qDebug("error fetching folders ");
404 404
405 } 405 }
406 if (result) mailimap_list_result_free( result ); 406 if (result) mailimap_list_result_free( result );
407 return folders; 407 return folders;
408} 408}
409 409
410RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 410RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
411{ 411{
412 RecMail * m = 0; 412 RecMail * m = 0;
413 mailimap_msg_att_item *item=0; 413 mailimap_msg_att_item *item=0;
414 clistcell *current,*c,*cf; 414 clistcell *current,*c,*cf;
415 mailimap_msg_att_dynamic*flist; 415 mailimap_msg_att_dynamic*flist;
416 mailimap_flag_fetch*cflag; 416 mailimap_flag_fetch*cflag;
417 int size; 417 int size;
418 QBitArray mFlags(7); 418 QBitArray mFlags(7);
419 QStringList addresslist; 419 QStringList addresslist;
420 420
421 if (!m_att) { 421 if (!m_att) {
422 return m; 422 return m;
423 } 423 }
424 m = new RecMail(); 424 m = new RecMail();
425 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 425 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
426 current = c; 426 current = c;
427 size = 0; 427 size = 0;
428 item = (mailimap_msg_att_item*)current->data; 428 item = (mailimap_msg_att_item*)current->data;
429 if ( !item ) 429 if ( !item )
430 continue; 430 continue;
431 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 431 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
432 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 432 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
433 if (!flist || !flist->att_list) { 433 if (!flist || !flist->att_list) {