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