summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-18 11:01:02 (UTC)
committer zautrix <zautrix>2004-10-18 11:01:02 (UTC)
commitc613ac44ea26c66305252feb4ed4ad17f79b5cc6 (patch) (unidiff)
tree3dbdfc228c6103025781a20292f8855b24b55dd1
parenta83b6694d2f80ec58f6eb88684897052c69276a0 (diff)
downloadkdepimpi-c613ac44ea26c66305252feb4ed4ad17f79b5cc6.zip
kdepimpi-c613ac44ea26c66305252feb4ed4ad17f79b5cc6.tar.gz
kdepimpi-c613ac44ea26c66305252feb4ed4ad17f79b5cc6.tar.bz2
some mail imap changes
Diffstat (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,1329 +1,1329 @@
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) {
434 continue; 434 continue;
435 } 435 }
436 cf = flist->att_list->first; 436 cf = flist->att_list->first;
437 if( ! cf ) 437 if( ! cf )
438 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)) {
439 cflag = (mailimap_flag_fetch*)cf->data; 439 cflag = (mailimap_flag_fetch*)cf->data;
440 if( ! cflag ) 440 if( ! cflag )
441 qDebug("imap:not cflag "); 441 qDebug("imap:not cflag ");
442 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) {
443 switch (cflag->fl_flag->fl_type) { 443 switch (cflag->fl_flag->fl_type) {
444 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 444 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
445 mFlags.setBit(FLAG_ANSWERED); 445 mFlags.setBit(FLAG_ANSWERED);
446 break; 446 break;
447 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 447 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
448 mFlags.setBit(FLAG_FLAGGED); 448 mFlags.setBit(FLAG_FLAGGED);
449 break; 449 break;
450 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 450 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
451 mFlags.setBit(FLAG_DELETED); 451 mFlags.setBit(FLAG_DELETED);
452 break; 452 break;
453 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 453 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
454 mFlags.setBit(FLAG_SEEN); 454 mFlags.setBit(FLAG_SEEN);
455 break; 455 break;
456 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 456 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
457 mFlags.setBit(FLAG_DRAFT); 457 mFlags.setBit(FLAG_DRAFT);
458 break; 458 break;
459 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 459 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
460 break; 460 break;
461 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 461 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
462 break; 462 break;
463 default: 463 default:
464 break; 464 break;
465 } 465 }
466 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 466 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
467 mFlags.setBit(FLAG_RECENT); 467 mFlags.setBit(FLAG_RECENT);
468 } 468 }
469 } 469 }
470 continue; 470 continue;
471 } 471 }
472 if ( item->att_data.att_static == NULL ) 472 if ( item->att_data.att_static == NULL )
473 continue; 473 continue;
474 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) {
475 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;
476 if ( head == NULL ) 476 if ( head == NULL )
477 continue; 477 continue;
478 if ( head->env_date != NULL ) { 478 if ( head->env_date != NULL ) {
479 m->setDate(head->env_date); 479 m->setDate(head->env_date);
480 struct mailimf_date_time result; 480 struct mailimf_date_time result;
481 struct mailimf_date_time* date = &result; 481 struct mailimf_date_time* date = &result;
482 struct mailimf_date_time **re = &date; 482 struct mailimf_date_time **re = &date;
483 size_t length = m->getDate().length(); 483 size_t length = m->getDate().length();
484 size_t index = 0; 484 size_t index = 0;
485 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 ) {
486 QDateTime dt = Genericwrapper::parseDateTime( date ); 486 QDateTime dt = Genericwrapper::parseDateTime( date );
487 QString ret; 487 QString ret;
488 if ( dt.date() == QDate::currentDate () ) 488 if ( dt.date() == QDate::currentDate () )
489 ret = KGlobal::locale()->formatTime( dt.time(),true); 489 ret = KGlobal::locale()->formatTime( dt.time(),true);
490 else { 490 else {
491 ret = KGlobal::locale()->formatDateTime( dt,true,true); 491 ret = KGlobal::locale()->formatDateTime( dt,true,true);
492 } 492 }
493 m->setDate( ret ); 493 m->setDate( ret );
494 char tmp[20]; 494 char tmp[20];
495 snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i", 495 snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i",
496 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() );
497 //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);
498 m->setIsoDate( QString( tmp ) ); 498 m->setIsoDate( QString( tmp ) );
499 } else { 499 } else {
500 m->setIsoDate(head->env_date); 500 m->setIsoDate(head->env_date);
501 } 501 }
502 } 502 }
503 if ( head->env_subject != NULL ) 503 if ( head->env_subject != NULL )
504 m->setSubject(convert_String((const char*)head->env_subject)); 504 m->setSubject(convert_String((const char*)head->env_subject));
505 //m->setSubject(head->env_subject); 505 //m->setSubject(head->env_subject);
506 if (head->env_from!=NULL) { 506 if (head->env_from!=NULL) {
507 addresslist = address_list_to_stringlist(head->env_from->frm_list); 507 addresslist = address_list_to_stringlist(head->env_from->frm_list);
508 if (addresslist.count()) { 508 if (addresslist.count()) {
509 m->setFrom(addresslist.first()); 509 m->setFrom(addresslist.first());
510 } 510 }
511 } 511 }
512 if (head->env_to!=NULL) { 512 if (head->env_to!=NULL) {
513 addresslist = address_list_to_stringlist(head->env_to->to_list); 513 addresslist = address_list_to_stringlist(head->env_to->to_list);
514 m->setTo(addresslist); 514 m->setTo(addresslist);
515 } 515 }
516 if (head->env_cc!=NULL) { 516 if (head->env_cc!=NULL) {
517 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 517 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
518 m->setCC(addresslist); 518 m->setCC(addresslist);
519 } 519 }
520 if (head->env_bcc!=NULL) { 520 if (head->env_bcc!=NULL) {
521 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 521 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
522 m->setBcc(addresslist); 522 m->setBcc(addresslist);
523 } 523 }
524 /* reply to address, eg. email. */ 524 /* reply to address, eg. email. */
525 if (head->env_reply_to!=NULL) { 525 if (head->env_reply_to!=NULL) {
526 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 526 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
527 if (addresslist.count()) { 527 if (addresslist.count()) {
528 m->setReplyto(addresslist.first()); 528 m->setReplyto(addresslist.first());
529 } 529 }
530 } 530 }
531 if (head->env_in_reply_to!=NULL) { 531 if (head->env_in_reply_to!=NULL) {
532 QString h(head->env_in_reply_to); 532 QString h(head->env_in_reply_to);
533 while (h.length()>0 && h[0]=='<') { 533 while (h.length()>0 && h[0]=='<') {
534 h.remove(0,1); 534 h.remove(0,1);
535 } 535 }
536 while (h.length()>0 && h[h.length()-1]=='>') { 536 while (h.length()>0 && h[h.length()-1]=='>') {
537 h.remove(h.length()-1,1); 537 h.remove(h.length()-1,1);
538 } 538 }
539 if (h.length()>0) { 539 if (h.length()>0) {
540 m->setInreply(QStringList(h)); 540 m->setInreply(QStringList(h));
541 } 541 }
542 } 542 }
543 if (head->env_message_id != NULL) { 543 if (head->env_message_id != NULL) {
544 m->setMsgid(QString(head->env_message_id)); 544 m->setMsgid(QString(head->env_message_id));
545 } 545 }
546 } 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) {
547#if 0 547#if 0
548 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;
549 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));
550 qDebug("time %s ",da.toString().latin1() ); 550 qDebug("time %s ",da.toString().latin1() );
551#endif 551#endif
552 } 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) {
553 size = item->att_data.att_static->att_data.att_rfc822_size; 553 size = item->att_data.att_static->att_data.att_rfc822_size;
554 } 554 }
555 } 555 }
556 /* msg is already deleted */ 556 /* msg is already deleted */
557 if (mFlags.testBit(FLAG_DELETED) && m) { 557 if (mFlags.testBit(FLAG_DELETED) && m) {
558 delete m; 558 delete m;
559 m = 0; 559 m = 0;
560 } 560 }
561 if (m) { 561 if (m) {
562 m->setFlags(mFlags); 562 m->setFlags(mFlags);
563 m->setMsgsize(size); 563 m->setMsgsize(size);
564 } 564 }
565 return m; 565 return m;
566} 566}
567 567
568RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail) 568RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail)
569{ 569{
570 RecBodyP body = new RecBody(); 570 RecBodyP body = new RecBody();
571 const char *mb; 571 const char *mb;
572 int err = MAILIMAP_NO_ERROR; 572 int err = MAILIMAP_NO_ERROR;
573 clist *result = 0; 573 clist *result = 0;
574 clistcell *current; 574 clistcell *current;
575 mailimap_fetch_att *fetchAtt = 0; 575 mailimap_fetch_att *fetchAtt = 0;
576 mailimap_fetch_type *fetchType = 0; 576 mailimap_fetch_type *fetchType = 0;
577 mailimap_set *set = 0; 577 mailimap_set *set = 0;
578 mailimap_body*body_desc = 0; 578 mailimap_body*body_desc = 0;
579 579
580 mb = mail->getMbox().latin1(); 580 mb = mail->getMbox().latin1();
581 581
582 login(); 582 login();
583 if (!m_imap) { 583 if (!m_imap) {
584 return body; 584 return body;
585 } 585 }
586 err = selectMbox(mail->getMbox()); 586 err = selectMbox(mail->getMbox());
587 if ( err != MAILIMAP_NO_ERROR ) { 587 if ( err != MAILIMAP_NO_ERROR ) {
588 return body; 588 return body;
589 } 589 }
590 590
591 /* the range has to start at 1!!! not with 0!!!! */ 591 /* the range has to start at 1!!! not with 0!!!! */
592 set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); 592 set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() );
593 fetchAtt = mailimap_fetch_att_new_bodystructure(); 593 fetchAtt = mailimap_fetch_att_new_bodystructure();
594 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 594 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
595 err = mailimap_fetch( m_imap, set, fetchType, &result ); 595 err = mailimap_fetch( m_imap, set, fetchType, &result );
596 mailimap_set_free( set ); 596 mailimap_set_free( set );
597 mailimap_fetch_type_free( fetchType ); 597 mailimap_fetch_type_free( fetchType );
598 598
599 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 599 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
600 mailimap_msg_att * msg_att; 600 mailimap_msg_att * msg_att;
601 msg_att = (mailimap_msg_att*)current->data; 601 msg_att = (mailimap_msg_att*)current->data;
602 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;
603 QValueList<int> path; 603 QValueList<int> path;
604 body_desc = item->att_data.att_static->att_data.att_body; 604 body_desc = item->att_data.att_static->att_data.att_body;
605 traverseBody(mail,body_desc,body,0,path); 605 traverseBody(mail,body_desc,body,0,path);
606 } else { 606 } else {
607 //odebug << "error fetching body: " << m_imap->imap_response << "" << oendl; 607 //odebug << "error fetching body: " << m_imap->imap_response << "" << oendl;
608 } 608 }
609 if (result) mailimap_fetch_list_free(result); 609 if (result) mailimap_fetch_list_free(result);
610 return body; 610 return body;
611} 611}
612 612
613QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 613QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
614{ 614{
615 QStringList l; 615 QStringList l;
616 QString from; 616 QString from;
617 bool named_from; 617 bool named_from;
618 clistcell *current = NULL; 618 clistcell *current = NULL;
619 mailimap_address * current_address=NULL; 619 mailimap_address * current_address=NULL;
620 if (!list) { 620 if (!list) {
621 return l; 621 return l;
622 } 622 }
623 unsigned int count = 0; 623 unsigned int count = 0;
624 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 624 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
625 from = ""; 625 from = "";
626 named_from = false; 626 named_from = false;
627 current_address=(mailimap_address*)current->data; 627 current_address=(mailimap_address*)current->data;
628 if (current_address->ad_personal_name){ 628 if (current_address->ad_personal_name){
629 from+=convert_String((const char*)current_address->ad_personal_name); 629 from+=convert_String((const char*)current_address->ad_personal_name);
630 from+=" "; 630 from+=" ";
631 named_from = true; 631 named_from = true;
632 } 632 }
633 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)) {
634 from+="<"; 634 from+="<";
635 } 635 }
636 if (current_address->ad_mailbox_name) { 636 if (current_address->ad_mailbox_name) {
637 from+=QString(current_address->ad_mailbox_name); 637 from+=QString(current_address->ad_mailbox_name);
638 from+="@"; 638 from+="@";
639 } 639 }
640 if (current_address->ad_host_name) { 640 if (current_address->ad_host_name) {
641 from+=QString(current_address->ad_host_name); 641 from+=QString(current_address->ad_host_name);
642 } 642 }
643 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)) {
644 from+=">"; 644 from+=">";
645 } 645 }
646 l.append(QString(from)); 646 l.append(QString(from));
647 if (++count > 99) { 647 if (++count > 99) {
648 break; 648 break;
649 } 649 }
650 } 650 }
651 return l; 651 return l;
652} 652}
653 653
654encodedString*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)
655{ 655{
656 encodedString*res=new encodedString; 656 encodedString*res=new encodedString;
657 int err; 657 int err;
658 mailimap_fetch_type *fetchType; 658 mailimap_fetch_type *fetchType;
659 mailimap_set *set; 659 mailimap_set *set;
660 clistcell*current,*cur; 660 clistcell*current,*cur;
661 mailimap_section_part * section_part = 0; 661 mailimap_section_part * section_part = 0;
662 mailimap_section_spec * section_spec = 0; 662 mailimap_section_spec * section_spec = 0;
663 mailimap_section * section = 0; 663 mailimap_section * section = 0;
664 mailimap_fetch_att * fetch_att = 0; 664 mailimap_fetch_att * fetch_att = 0;
665 665
666 login(); 666 login();
667 if (!m_imap) { 667 if (!m_imap) {
668 return res; 668 return res;
669 } 669 }
670 if (!internal_call) { 670 if (!internal_call) {
671 err = selectMbox(mail->getMbox()); 671 err = selectMbox(mail->getMbox());
672 if ( err != MAILIMAP_NO_ERROR ) { 672 if ( err != MAILIMAP_NO_ERROR ) {
673 return res; 673 return res;
674 } 674 }
675 } 675 }
676 set = mailimap_set_new_single(mail->getNumber()); 676 set = mailimap_set_new_single(mail->getNumber());
677 677
678 clist*id_list = 0; 678 clist*id_list = 0;
679 679
680 /* 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
681 a "fetch <id> (body[])" statement on imap server */ 681 a "fetch <id> (body[])" statement on imap server */
682 if (path.count()>0 ) { 682 if (path.count()>0 ) {
683 id_list = clist_new(); 683 id_list = clist_new();
684 for (unsigned j=0; j < path.count();++j) { 684 for (unsigned j=0; j < path.count();++j) {
685 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 685 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
686 *p_id = path[j]; 686 *p_id = path[j];
687 clist_append(id_list,p_id); 687 clist_append(id_list,p_id);
688 } 688 }
689 section_part = mailimap_section_part_new(id_list); 689 section_part = mailimap_section_part_new(id_list);
690 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);
691 } 691 }
692 692
693 section = mailimap_section_new(section_spec); 693 section = mailimap_section_new(section_spec);
694 fetch_att = mailimap_fetch_att_new_body_section(section); 694 fetch_att = mailimap_fetch_att_new_body_section(section);
695 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 695 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
696 696
697 clist*result = 0; 697 clist*result = 0;
698 698
699 err = mailimap_fetch( m_imap, set, fetchType, &result ); 699 err = mailimap_fetch( m_imap, set, fetchType, &result );
700 mailimap_set_free( set ); 700 mailimap_set_free( set );
701 mailimap_fetch_type_free( fetchType ); 701 mailimap_fetch_type_free( fetchType );
702 702
703 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 703 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
704 mailimap_msg_att * msg_att; 704 mailimap_msg_att * msg_att;
705 msg_att = (mailimap_msg_att*)current->data; 705 msg_att = (mailimap_msg_att*)current->data;
706 mailimap_msg_att_item*msg_att_item; 706 mailimap_msg_att_item*msg_att_item;
707 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)) {
708 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 708 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
709 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 709 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
710 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) {
711 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;
712 /* detach - we take over the content */ 712 /* detach - we take over the content */
713 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;
714 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);
715 } 715 }
716 } 716 }
717 } 717 }
718 } else { 718 } else {
719 ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl; 719 ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl;
720 } 720 }
721 if (result) mailimap_fetch_list_free(result); 721 if (result) mailimap_fetch_list_free(result);
722 return res; 722 return res;
723} 723}
724 724
725/* current_recursion is for recursive calls. 725/* current_recursion is for recursive calls.
726 current_count means the position inside the internal loop! */ 726 current_count means the position inside the internal loop! */
727void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body, 727void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body,
728 int current_recursion,QValueList<int>recList,int current_count) 728 int current_recursion,QValueList<int>recList,int current_count)
729{ 729{
730 if (!body || current_recursion>=10) { 730 if (!body || current_recursion>=10) {
731 return; 731 return;
732 } 732 }
733 switch (body->bd_type) { 733 switch (body->bd_type) {
734 case MAILIMAP_BODY_1PART: 734 case MAILIMAP_BODY_1PART:
735 { 735 {
736 QValueList<int>countlist = recList; 736 QValueList<int>countlist = recList;
737 countlist.append(current_count); 737 countlist.append(current_count);
738 RecPartP currentPart = new RecPart(); 738 RecPartP currentPart = new RecPart();
739 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; 739 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part;
740 QString id(""); 740 QString id("");
741 currentPart->setPositionlist(countlist); 741 currentPart->setPositionlist(countlist);
742 for (unsigned int j = 0; j < countlist.count();++j) { 742 for (unsigned int j = 0; j < countlist.count();++j) {
743 id+=(j>0?" ":""); 743 id+=(j>0?" ":"");
744 id+=QString("%1").arg(countlist[j]); 744 id+=QString("%1").arg(countlist[j]);
745 } 745 }
746 //odebug << "ID = " << id.latin1() << "" << oendl; 746 //odebug << "ID = " << id.latin1() << "" << oendl;
747 currentPart->setIdentifier(id); 747 currentPart->setIdentifier(id);
748 fillSinglePart(currentPart,part1); 748 fillSinglePart(currentPart,part1);
749 /* important: Check for is NULL 'cause a body can be empty! 749 /* important: Check for is NULL 'cause a body can be empty!
750 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 */
751 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) {
752 QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding()); 752 QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding());
753 target_body->setDescription(currentPart); 753 target_body->setDescription(currentPart);
754 target_body->setBodytext(body_text); 754 target_body->setBodytext(body_text);
755 if (countlist.count()>1) { 755 if (countlist.count()>1) {
756 target_body->addPart(currentPart); 756 target_body->addPart(currentPart);
757 } 757 }
758 } else { 758 } else {
759 target_body->addPart(currentPart); 759 target_body->addPart(currentPart);
760 } 760 }
761 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { 761 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) {
762 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);
763 } 763 }
764 } 764 }
765 break; 765 break;
766 case MAILIMAP_BODY_MPART: 766 case MAILIMAP_BODY_MPART:
767 { 767 {
768 QValueList<int>countlist = recList; 768 QValueList<int>countlist = recList;
769 clistcell*current=0; 769 clistcell*current=0;
770 mailimap_body*current_body=0; 770 mailimap_body*current_body=0;
771 unsigned int ccount = 1; 771 unsigned int ccount = 1;
772 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; 772 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart;
773 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)) {
774 current_body = (mailimap_body*)current->data; 774 current_body = (mailimap_body*)current->data;
775 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 775 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
776 RecPartP targetPart = new RecPart(); 776 RecPartP targetPart = new RecPart();
777 targetPart->setType("multipart"); 777 targetPart->setType("multipart");
778 fillMultiPart(targetPart,mailDescription); 778 fillMultiPart(targetPart,mailDescription);
779 countlist.append(current_count); 779 countlist.append(current_count);
780 targetPart->setPositionlist(countlist); 780 targetPart->setPositionlist(countlist);
781 target_body->addPart(targetPart); 781 target_body->addPart(targetPart);
782 QString id(""); 782 QString id("");
783 for (unsigned int j = 0; j < countlist.count();++j) { 783 for (unsigned int j = 0; j < countlist.count();++j) {
784 id+=(j>0?" ":""); 784 id+=(j>0?" ":"");
785 id+=QString("%1").arg(countlist[j]); 785 id+=QString("%1").arg(countlist[j]);
786 } 786 }
787 // odebug << "ID(mpart) = " << id.latin1() << "" << oendl; 787 // odebug << "ID(mpart) = " << id.latin1() << "" << oendl;
788 } 788 }
789 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); 789 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount);
790 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 790 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
791 countlist = recList; 791 countlist = recList;
792 } 792 }
793 ++ccount; 793 ++ccount;
794 } 794 }
795 } 795 }
796 break; 796 break;
797 default: 797 default:
798 break; 798 break;
799 } 799 }
800} 800}
801 801
802void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description) 802void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description)
803{ 803{
804 if (!Description) { 804 if (!Description) {
805 return; 805 return;
806 } 806 }
807 switch (Description->bd_type) { 807 switch (Description->bd_type) {
808 case MAILIMAP_BODY_TYPE_1PART_TEXT: 808 case MAILIMAP_BODY_TYPE_1PART_TEXT:
809 target_part->setType("text"); 809 target_part->setType("text");
810 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 810 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
811 break; 811 break;
812 case MAILIMAP_BODY_TYPE_1PART_BASIC: 812 case MAILIMAP_BODY_TYPE_1PART_BASIC:
813 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 813 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
814 break; 814 break;
815 case MAILIMAP_BODY_TYPE_1PART_MSG: 815 case MAILIMAP_BODY_TYPE_1PART_MSG:
816 target_part->setType("message"); 816 target_part->setType("message");
817 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 817 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
818 break; 818 break;
819 default: 819 default:
820 break; 820 break;
821 } 821 }
822} 822}
823 823
824void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which) 824void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which)
825{ 825{
826 if (!which) { 826 if (!which) {
827 return; 827 return;
828 } 828 }
829 QString sub; 829 QString sub;
830 sub = which->bd_media_text; 830 sub = which->bd_media_text;
831 //odebug << "Type= text/" << which->bd_media_text << "" << oendl; 831 //odebug << "Type= text/" << which->bd_media_text << "" << oendl;
832 target_part->setSubtype(sub.lower()); 832 target_part->setSubtype(sub.lower());
833 target_part->setLines(which->bd_lines); 833 target_part->setLines(which->bd_lines);
834 fillBodyFields(target_part,which->bd_fields); 834 fillBodyFields(target_part,which->bd_fields);
835} 835}
836 836
837void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which) 837void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which)
838{ 838{
839 if (!which) { 839 if (!which) {
840 return; 840 return;
841 } 841 }
842 target_part->setSubtype("rfc822"); 842 target_part->setSubtype("rfc822");
843 //odebug << "Message part" << oendl; 843 //odebug << "Message part" << oendl;
844 /* we set this type to text/plain */ 844 /* we set this type to text/plain */
845 target_part->setLines(which->bd_lines); 845 target_part->setLines(which->bd_lines);
846 fillBodyFields(target_part,which->bd_fields); 846 fillBodyFields(target_part,which->bd_fields);
847} 847}
848 848
849void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which) 849void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which)
850{ 850{
851 if (!which) return; 851 if (!which) return;
852 QString sub = which->bd_media_subtype; 852 QString sub = which->bd_media_subtype;
853 target_part->setSubtype(sub.lower()); 853 target_part->setSubtype(sub.lower());
854 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) {
855 clistcell*cur = 0; 855 clistcell*cur = 0;
856 mailimap_single_body_fld_param*param=0; 856 mailimap_single_body_fld_param*param=0;
857 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)) {
858 param = (mailimap_single_body_fld_param*)cur->data; 858 param = (mailimap_single_body_fld_param*)cur->data;
859 if (param) { 859 if (param) {
860 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));
861 } 861 }
862 } 862 }
863 } 863 }
864} 864}
865 865
866void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which) 866void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which)
867{ 867{
868 if (!which) { 868 if (!which) {
869 return; 869 return;
870 } 870 }
871 QString type,sub; 871 QString type,sub;
872 switch (which->bd_media_basic->med_type) { 872 switch (which->bd_media_basic->med_type) {
873 case MAILIMAP_MEDIA_BASIC_APPLICATION: 873 case MAILIMAP_MEDIA_BASIC_APPLICATION:
874 type = "application"; 874 type = "application";
875 break; 875 break;
876 case MAILIMAP_MEDIA_BASIC_AUDIO: 876 case MAILIMAP_MEDIA_BASIC_AUDIO:
877 type = "audio"; 877 type = "audio";
878 break; 878 break;
879 case MAILIMAP_MEDIA_BASIC_IMAGE: 879 case MAILIMAP_MEDIA_BASIC_IMAGE:
880 type = "image"; 880 type = "image";
881 break; 881 break;
882 case MAILIMAP_MEDIA_BASIC_MESSAGE: 882 case MAILIMAP_MEDIA_BASIC_MESSAGE:
883 type = "message"; 883 type = "message";
884 break; 884 break;
885 case MAILIMAP_MEDIA_BASIC_VIDEO: 885 case MAILIMAP_MEDIA_BASIC_VIDEO:
886 type = "video"; 886 type = "video";
887 break; 887 break;
888 case MAILIMAP_MEDIA_BASIC_OTHER: 888 case MAILIMAP_MEDIA_BASIC_OTHER:
889 default: 889 default:
890 if (which->bd_media_basic->med_basic_type) { 890 if (which->bd_media_basic->med_basic_type) {
891 type = which->bd_media_basic->med_basic_type; 891 type = which->bd_media_basic->med_basic_type;
892 } else { 892 } else {
893 type = ""; 893 type = "";
894 } 894 }
895 break; 895 break;
896 } 896 }
897 if (which->bd_media_basic->med_subtype) { 897 if (which->bd_media_basic->med_subtype) {
898 sub = which->bd_media_basic->med_subtype; 898 sub = which->bd_media_basic->med_subtype;
899 } else { 899 } else {
900 sub = ""; 900 sub = "";
901 } 901 }
902 // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl; 902 // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl;
903 target_part->setType(type.lower()); 903 target_part->setType(type.lower());
904 target_part->setSubtype(sub.lower()); 904 target_part->setSubtype(sub.lower());
905 fillBodyFields(target_part,which->bd_fields); 905 fillBodyFields(target_part,which->bd_fields);
906} 906}
907 907
908void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which) 908void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which)
909{ 909{
910 if (!which) return; 910 if (!which) return;
911 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) {
912 clistcell*cur; 912 clistcell*cur;
913 mailimap_single_body_fld_param*param=0; 913 mailimap_single_body_fld_param*param=0;
914 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)) {
915 param = (mailimap_single_body_fld_param*)cur->data; 915 param = (mailimap_single_body_fld_param*)cur->data;
916 if (param) { 916 if (param) {
917 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));
918 } 918 }
919 } 919 }
920 } 920 }
921 mailimap_body_fld_enc*enc = which->bd_encoding; 921 mailimap_body_fld_enc*enc = which->bd_encoding;
922 QString encoding(""); 922 QString encoding("");
923 switch (enc->enc_type) { 923 switch (enc->enc_type) {
924 case MAILIMAP_BODY_FLD_ENC_7BIT: 924 case MAILIMAP_BODY_FLD_ENC_7BIT:
925 encoding = "7bit"; 925 encoding = "7bit";
926 break; 926 break;
927 case MAILIMAP_BODY_FLD_ENC_8BIT: 927 case MAILIMAP_BODY_FLD_ENC_8BIT:
928 encoding = "8bit"; 928 encoding = "8bit";
929 break; 929 break;
930 case MAILIMAP_BODY_FLD_ENC_BINARY: 930 case MAILIMAP_BODY_FLD_ENC_BINARY:
931 encoding="binary"; 931 encoding="binary";
932 break; 932 break;
933 case MAILIMAP_BODY_FLD_ENC_BASE64: 933 case MAILIMAP_BODY_FLD_ENC_BASE64:
934 encoding="base64"; 934 encoding="base64";
935 break; 935 break;
936 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 936 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
937 encoding="quoted-printable"; 937 encoding="quoted-printable";
938 break; 938 break;
939 case MAILIMAP_BODY_FLD_ENC_OTHER: 939 case MAILIMAP_BODY_FLD_ENC_OTHER:
940 default: 940 default:
941 if (enc->enc_value) { 941 if (enc->enc_value) {
942 char*t=enc->enc_value; 942 char*t=enc->enc_value;
943 encoding=QString(enc->enc_value); 943 encoding=QString(enc->enc_value);
944 enc->enc_value=0L; 944 enc->enc_value=0L;
945 free(t); 945 free(t);
946 } 946 }
947 } 947 }
948 if (which->bd_description) { 948 if (which->bd_description) {
949 target_part->setDescription(QString(which->bd_description)); 949 target_part->setDescription(QString(which->bd_description));
950 } 950 }
951 target_part->setEncoding(encoding); 951 target_part->setEncoding(encoding);
952 target_part->setSize(which->bd_size); 952 target_part->setSize(which->bd_size);
953} 953}
954void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target) 954void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target)
955{ 955{
956 //#if 0 956 //#if 0
957 mailimap_flag_list*flist; 957 mailimap_flag_list*flist;
958 mailimap_set *set; 958 mailimap_set *set;
959 mailimap_store_att_flags * store_flags; 959 mailimap_store_att_flags * store_flags;
960 int err; 960 int err;
961 login(); 961 login();
962 //#endif 962 //#endif
963 if (!m_imap) { 963 if (!m_imap) {
964 return; 964 return;
965 } 965 }
966 int iii = 0; 966 int iii = 0;
967 int count = target.count(); 967 int count = target.count();
968 // qDebug("imap remove count %d ", count); 968 // qDebug("imap remove count %d ", count);
969 969
970 970
971 mMax = count; 971 mMax = count;
972 progress( tr("Delete")); 972 progress( tr("Delete"));
973 973
974 QProgressBar wid ( count ); 974 QProgressBar wid ( count );
975 wid.setCaption( tr("Deleting ...")); 975 wid.setCaption( tr("Deleting ..."));
976 wid.show(); 976 wid.show();
977 while (iii < count ) { 977 while (iii < count ) {
978 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));
979 wid.setProgress( iii ); 979 wid.setProgress( iii );
980 wid.raise(); 980 wid.raise();
981 qApp->processEvents(); 981 qApp->processEvents();
982 RecMailP mail = (*target.at( iii )); 982 RecMailP mail = (*target.at( iii ));
983 //#if 0 983 //#if 0
984 //qDebug("IMAP remove %d %d ", iii, mail->getNumber() ); 984 //qDebug("IMAP remove %d %d ", iii, mail->getNumber() );
985 err = selectMbox(mail->getMbox()); 985 err = selectMbox(mail->getMbox());
986 if ( err != MAILIMAP_NO_ERROR ) { 986 if ( err != MAILIMAP_NO_ERROR ) {
987 return; 987 return;
988 } 988 }
989 flist = mailimap_flag_list_new_empty(); 989 flist = mailimap_flag_list_new_empty();
990 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 990 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
991 store_flags = mailimap_store_att_flags_new_set_flags(flist); 991 store_flags = mailimap_store_att_flags_new_set_flags(flist);
992 set = mailimap_set_new_single(mail->getNumber()); 992 set = mailimap_set_new_single(mail->getNumber());
993 err = mailimap_store(m_imap,set,store_flags); 993 err = mailimap_store(m_imap,set,store_flags);
994 mailimap_set_free( set ); 994 mailimap_set_free( set );
995 mailimap_store_att_flags_free(store_flags); 995 mailimap_store_att_flags_free(store_flags);
996 996
997 if (err != MAILIMAP_NO_ERROR) { 997 if (err != MAILIMAP_NO_ERROR) {
998 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; 998 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl;
999 return; 999 return;
1000 } 1000 }
1001 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 1001 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
1002 /* should we realy do that at this moment? */ 1002 /* should we realy do that at this moment? */
1003 1003
1004 // err = mailimap_expunge(m_imap); 1004 // err = mailimap_expunge(m_imap);
1005 //if (err != MAILIMAP_NO_ERROR) { 1005 //if (err != MAILIMAP_NO_ERROR) {
1006 // 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));
1007 // } 1007 // }
1008 //#endif 1008 //#endif
1009 //deleteMail( mail); 1009 //deleteMail( mail);
1010 ++iii; 1010 ++iii;
1011 } 1011 }
1012 //qDebug("Deleting imap mails... "); 1012 //qDebug("Deleting imap mails... ");
1013 err = mailimap_expunge(m_imap); 1013 err = mailimap_expunge(m_imap);
1014 if (err != MAILIMAP_NO_ERROR) { 1014 if (err != MAILIMAP_NO_ERROR) {
1015 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));
1016 } 1016 }
1017} 1017}
1018void IMAPwrapper::deleteMail(const RecMailP&mail) 1018void IMAPwrapper::deleteMail(const RecMailP&mail)
1019{ 1019{
1020 mailimap_flag_list*flist; 1020 mailimap_flag_list*flist;
1021 mailimap_set *set; 1021 mailimap_set *set;
1022 mailimap_store_att_flags * store_flags; 1022 mailimap_store_att_flags * store_flags;
1023 int err; 1023 int err;
1024 login(); 1024 login();
1025 if (!m_imap) { 1025 if (!m_imap) {
1026 return; 1026 return;
1027 } 1027 }
1028 err = selectMbox(mail->getMbox()); 1028 err = selectMbox(mail->getMbox());
1029 if ( err != MAILIMAP_NO_ERROR ) { 1029 if ( err != MAILIMAP_NO_ERROR ) {
1030 return; 1030 return;
1031 } 1031 }
1032 flist = mailimap_flag_list_new_empty(); 1032 flist = mailimap_flag_list_new_empty();
1033 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 1033 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
1034 store_flags = mailimap_store_att_flags_new_set_flags(flist); 1034 store_flags = mailimap_store_att_flags_new_set_flags(flist);
1035 set = mailimap_set_new_single(mail->getNumber()); 1035 set = mailimap_set_new_single(mail->getNumber());
1036 err = mailimap_store(m_imap,set,store_flags); 1036 err = mailimap_store(m_imap,set,store_flags);
1037 mailimap_set_free( set ); 1037 mailimap_set_free( set );
1038 mailimap_store_att_flags_free(store_flags); 1038 mailimap_store_att_flags_free(store_flags);
1039 1039
1040 if (err != MAILIMAP_NO_ERROR) { 1040 if (err != MAILIMAP_NO_ERROR) {
1041 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; 1041 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl;
1042 return; 1042 return;
1043 } 1043 }
1044 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 1044 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
1045 /* should we realy do that at this moment? */ 1045 /* should we realy do that at this moment? */
1046 1046
1047 err = mailimap_expunge(m_imap); 1047 err = mailimap_expunge(m_imap);
1048 if (err != MAILIMAP_NO_ERROR) { 1048 if (err != MAILIMAP_NO_ERROR) {
1049 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));
1050 } 1050 }
1051 //qDebug("IMAPwrapper::deleteMail 2"); 1051 //qDebug("IMAPwrapper::deleteMail 2");
1052 1052
1053} 1053}
1054 1054
1055void IMAPwrapper::answeredMail(const RecMailP&mail) 1055void IMAPwrapper::answeredMail(const RecMailP&mail)
1056{ 1056{
1057 mailimap_flag_list*flist; 1057 mailimap_flag_list*flist;
1058 mailimap_set *set; 1058 mailimap_set *set;
1059 mailimap_store_att_flags * store_flags; 1059 mailimap_store_att_flags * store_flags;
1060 int err; 1060 int err;
1061 login(); 1061 login();
1062 if (!m_imap) { 1062 if (!m_imap) {
1063 return; 1063 return;
1064 } 1064 }
1065 err = selectMbox(mail->getMbox()); 1065 err = selectMbox(mail->getMbox());
1066 if ( err != MAILIMAP_NO_ERROR ) { 1066 if ( err != MAILIMAP_NO_ERROR ) {
1067 return; 1067 return;
1068 } 1068 }
1069 flist = mailimap_flag_list_new_empty(); 1069 flist = mailimap_flag_list_new_empty();
1070 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 1070 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
1071 store_flags = mailimap_store_att_flags_new_add_flags(flist); 1071 store_flags = mailimap_store_att_flags_new_add_flags(flist);
1072 set = mailimap_set_new_single(mail->getNumber()); 1072 set = mailimap_set_new_single(mail->getNumber());
1073 err = mailimap_store(m_imap,set,store_flags); 1073 err = mailimap_store(m_imap,set,store_flags);
1074 mailimap_set_free( set ); 1074 mailimap_set_free( set );
1075 mailimap_store_att_flags_free(store_flags); 1075 mailimap_store_att_flags_free(store_flags);
1076 1076
1077 if (err != MAILIMAP_NO_ERROR) { 1077 if (err != MAILIMAP_NO_ERROR) {
1078 // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl; 1078 // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl;
1079 return; 1079 return;
1080 } 1080 }
1081} 1081}
1082 1082
1083QString 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)
1084{ 1084{
1085 QString body(""); 1085 QString body("");
1086 encodedString*res = fetchRawPart(mail,path,internal_call); 1086 encodedString*res = fetchRawPart(mail,path,internal_call);
1087 encodedString*r = decode_String(res,enc); 1087 encodedString*r = decode_String(res,enc);
1088 delete res; 1088 delete res;
1089 if (r) { 1089 if (r) {
1090 if (r->Length()>0) { 1090 if (r->Length()>0) {
1091 body = r->Content(); 1091 body = r->Content();
1092 } 1092 }
1093 delete r; 1093 delete r;
1094 } 1094 }
1095 return body; 1095 return body;
1096} 1096}
1097 1097
1098QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) 1098QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part)
1099{ 1099{
1100 return fetchTextPart(mail,part->Positionlist(),false,part->Encoding()); 1100 return fetchTextPart(mail,part->Positionlist(),false,part->Encoding());
1101} 1101}
1102 1102
1103encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part) 1103encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part)
1104{ 1104{
1105 encodedString*res = fetchRawPart(mail,part->Positionlist(),false); 1105 encodedString*res = fetchRawPart(mail,part->Positionlist(),false);
1106 encodedString*r = decode_String(res,part->Encoding()); 1106 encodedString*r = decode_String(res,part->Encoding());
1107 delete res; 1107 delete res;
1108 return r; 1108 return r;
1109} 1109}
1110 1110
1111encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part) 1111encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part)
1112{ 1112{
1113 return fetchRawPart(mail,part->Positionlist(),false); 1113 return fetchRawPart(mail,part->Positionlist(),false);
1114} 1114}
1115 1115
1116int IMAPwrapper::deleteAllMail(const FolderP&folder) 1116int IMAPwrapper::deleteAllMail(const FolderP&folder)
1117{ 1117{
1118 login(); 1118 login();
1119 if (!m_imap) { 1119 if (!m_imap) {
1120 return 0; 1120 return 0;
1121 } 1121 }
1122 mailimap_flag_list*flist; 1122 mailimap_flag_list*flist;
1123 mailimap_set *set; 1123 mailimap_set *set;
1124 mailimap_store_att_flags * store_flags; 1124 mailimap_store_att_flags * store_flags;
1125 int err = selectMbox(folder->getName()); 1125 int err = selectMbox(folder->getName());
1126 if ( err != MAILIMAP_NO_ERROR ) { 1126 if ( err != MAILIMAP_NO_ERROR ) {
1127 return 0; 1127 return 0;
1128 } 1128 }
1129 1129
1130 int last = m_imap->imap_selection_info->sel_exists; 1130 int last = m_imap->imap_selection_info->sel_exists;
1131 if (last == 0) { 1131 if (last == 0) {
1132 Global::statusMessage(tr("Mailbox has no mails!")); 1132 Global::statusMessage(tr("Mailbox has no mails!"));
1133 return 0; 1133 return 0;
1134 } 1134 }
1135 flist = mailimap_flag_list_new_empty(); 1135 flist = mailimap_flag_list_new_empty();
1136 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 1136 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
1137 store_flags = mailimap_store_att_flags_new_set_flags(flist); 1137 store_flags = mailimap_store_att_flags_new_set_flags(flist);
1138 set = mailimap_set_new_interval( 1, last ); 1138 set = mailimap_set_new_interval( 1, last );
1139 err = mailimap_store(m_imap,set,store_flags); 1139 err = mailimap_store(m_imap,set,store_flags);
1140 mailimap_set_free( set ); 1140 mailimap_set_free( set );
1141 mailimap_store_att_flags_free(store_flags); 1141 mailimap_store_att_flags_free(store_flags);
1142 if (err != MAILIMAP_NO_ERROR) { 1142 if (err != MAILIMAP_NO_ERROR) {
1143 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));
1144 return 0; 1144 return 0;
1145 } 1145 }
1146 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 1146 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
1147 /* should we realy do that at this moment? */ 1147 /* should we realy do that at this moment? */
1148 err = mailimap_expunge(m_imap); 1148 err = mailimap_expunge(m_imap);
1149 if (err != MAILIMAP_NO_ERROR) { 1149 if (err != MAILIMAP_NO_ERROR) {
1150 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));
1151 return 0; 1151 return 0;
1152 } 1152 }
1153 // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; 1153 // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl;
1154 return 1; 1154 return 1;
1155} 1155}
1156 1156
1157int 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)
1158{ 1158{
1159 if (folder.length()==0) return 0; 1159 if (folder.length()==0) return 0;
1160 login(); 1160 login();
1161 if (!m_imap) {return 0;} 1161 if (!m_imap) {return 0;}
1162 QString pre = account->getPrefix(); 1162 QString pre = account->getPrefix();
1163 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { 1163 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) {
1164 pre+=delemiter; 1164 pre+=delemiter;
1165 } 1165 }
1166 if (parentfolder) { 1166 if (parentfolder) {
1167 pre += parentfolder->getDisplayName()+delemiter; 1167 pre += parentfolder->getDisplayName()+delemiter;
1168 } 1168 }
1169 pre+=folder; 1169 pre+=folder;
1170 if (getsubfolder) { 1170 if (getsubfolder) {
1171 if (delemiter.length()>0) { 1171 if (delemiter.length()>0) {
1172 pre+=delemiter; 1172 pre+=delemiter;
1173 } else { 1173 } else {
1174 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));
1175 return 0; 1175 return 0;
1176 } 1176 }
1177 } 1177 }
1178 // odebug << "Creating " << pre.latin1() << "" << oendl; 1178 // odebug << "Creating " << pre.latin1() << "" << oendl;
1179 int res = mailimap_create(m_imap,pre.latin1()); 1179 int res = mailimap_create(m_imap,pre.latin1());
1180 if (res != MAILIMAP_NO_ERROR) { 1180 if (res != MAILIMAP_NO_ERROR) {
1181 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 1181 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
1182 return 0; 1182 return 0;
1183 } 1183 }
1184 return 1; 1184 return 1;
1185} 1185}
1186 1186
1187int IMAPwrapper::deleteMbox(const FolderP&folder) 1187int IMAPwrapper::deleteMbox(const FolderP&folder)
1188{ 1188{
1189 if (!folder) return 0; 1189 if (!folder) return 0;
1190 login(); 1190 login();
1191 if (!m_imap) {return 0;} 1191 if (!m_imap) {return 0;}
1192 int res = mailimap_delete(m_imap,folder->getName()); 1192 int res = mailimap_delete(m_imap,folder->getName());
1193 if (res != MAILIMAP_NO_ERROR) { 1193 if (res != MAILIMAP_NO_ERROR) {
1194 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 1194 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
1195 return 0; 1195 return 0;
1196 } 1196 }
1197 return 1; 1197 return 1;
1198} 1198}
1199 1199
1200void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 1200void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
1201{ 1201{
1202 mailimap_status_att_list * att_list =0; 1202 mailimap_status_att_list * att_list =0;
1203 mailimap_mailbox_data_status * status=0; 1203 mailimap_mailbox_data_status * status=0;
1204 clistiter * cur = 0; 1204 clistiter * cur = 0;
1205 int r = 0; 1205 int r = 0;
1206 target_stat.message_count = 0; 1206 target_stat.message_count = 0;
1207 target_stat.message_unseen = 0; 1207 target_stat.message_unseen = 0;
1208 target_stat.message_recent = 0; 1208 target_stat.message_recent = 0;
1209 login(); 1209 login();
1210 if (!m_imap) { 1210 if (!m_imap) {
1211 return; 1211 return;
1212 } 1212 }
1213 att_list = mailimap_status_att_list_new_empty(); 1213 att_list = mailimap_status_att_list_new_empty();
1214 if (!att_list) return; 1214 if (!att_list) return;
1215 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);
1216 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);
1217 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);
1218 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); 1218 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status);
1219 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { 1219 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) {
1220 for (cur = clist_begin(status->st_info_list); 1220 for (cur = clist_begin(status->st_info_list);
1221 cur != NULL ; cur = clist_next(cur)) { 1221 cur != NULL ; cur = clist_next(cur)) {
1222 mailimap_status_info * status_info; 1222 mailimap_status_info * status_info;
1223 status_info = (mailimap_status_info *)clist_content(cur); 1223 status_info = (mailimap_status_info *)clist_content(cur);
1224 switch (status_info->st_att) { 1224 switch (status_info->st_att) {
1225 case MAILIMAP_STATUS_ATT_MESSAGES: 1225 case MAILIMAP_STATUS_ATT_MESSAGES:
1226 target_stat.message_count = status_info->st_value; 1226 target_stat.message_count = status_info->st_value;
1227 break; 1227 break;
1228 case MAILIMAP_STATUS_ATT_RECENT: 1228 case MAILIMAP_STATUS_ATT_RECENT:
1229 target_stat.message_recent = status_info->st_value; 1229 target_stat.message_recent = status_info->st_value;
1230 break; 1230 break;
1231 case MAILIMAP_STATUS_ATT_UNSEEN: 1231 case MAILIMAP_STATUS_ATT_UNSEEN:
1232 target_stat.message_unseen = status_info->st_value; 1232 target_stat.message_unseen = status_info->st_value;
1233 break; 1233 break;
1234 } 1234 }
1235 } 1235 }
1236 } else { 1236 } else {
1237 // odebug << "Error retrieving status" << oendl; 1237 // odebug << "Error retrieving status" << oendl;
1238 } 1238 }
1239 if (status) mailimap_mailbox_data_status_free(status); 1239 if (status) mailimap_mailbox_data_status_free(status);
1240 if (att_list) mailimap_status_att_list_free(att_list); 1240 if (att_list) mailimap_status_att_list_free(att_list);
1241} 1241}
1242 1242
1243void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) 1243void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
1244{ 1244{
1245 login(); 1245 login();
1246 if (!m_imap) return; 1246 if (!m_imap) return;
1247 if (!msg) return; 1247 if (!msg) return;
1248 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);
1249 if (r != MAILIMAP_NO_ERROR) { 1249 if (r != MAILIMAP_NO_ERROR) {
1250 Global::statusMessage("Error storing mail!"); 1250 Global::statusMessage("Error storing mail!");
1251 } 1251 }
1252} 1252}
1253 1253
1254MAILLIB::ATYPE IMAPwrapper::getType()const 1254MAILLIB::ATYPE IMAPwrapper::getType()const
1255{ 1255{
1256 return account->getType(); 1256 return account->getType();
1257} 1257}
1258 1258
1259const QString&IMAPwrapper::getName()const 1259const QString&IMAPwrapper::getName()const
1260{ 1260{
1261 // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl; 1261 // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl;
1262 return account->getAccountName(); 1262 return account->getAccountName();
1263} 1263}
1264 1264
1265encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) 1265encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail)
1266{ 1266{
1267 // dummy 1267 // dummy
1268 QValueList<int> path; 1268 QValueList<int> path;
1269 return fetchRawPart(mail,path,false); 1269 return fetchRawPart(mail,path,false);
1270} 1270}
1271 1271
1272void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, 1272void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder,
1273 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) 1273 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb)
1274{ 1274{
1275 if (targetWrapper != this || maxSizeInKb > 0 ) { 1275 if (targetWrapper != this || maxSizeInKb > 0 ) {
1276 mMax = 0; 1276 mMax = 0;
1277 progress( tr("Copy")); 1277 progress( tr("Copy"));
1278 AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb); 1278 AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb);
1279 //qDebug("IMAPwrapper::mvcpAllMails::Using generic"); 1279 //qDebug("IMAPwrapper::mvcpAllMails::Using generic");
1280 // odebug << "Using generic" << oendl; 1280 // odebug << "Using generic" << oendl;
1281 return; 1281 return;
1282 } 1282 }
1283 mailimap_set *set = 0; 1283 mailimap_set *set = 0;
1284 login(); 1284 login();
1285 if (!m_imap) { 1285 if (!m_imap) {
1286 return; 1286 return;
1287 } 1287 }
1288 int err = selectMbox(fromFolder->getName()); 1288 int err = selectMbox(fromFolder->getName());
1289 if ( err != MAILIMAP_NO_ERROR ) { 1289 if ( err != MAILIMAP_NO_ERROR ) {
1290 return; 1290 return;
1291 } 1291 }
1292 Global::statusMessage( tr("Copying mails on server...") ); 1292 Global::statusMessage( tr("Copying mails on server...") );
1293 int last = m_imap->imap_selection_info->sel_exists; 1293 int last = m_imap->imap_selection_info->sel_exists;
1294 set = mailimap_set_new_interval( 1, last ); 1294 set = mailimap_set_new_interval( 1, last );
1295 err = mailimap_copy(m_imap,set,targetFolder.latin1()); 1295 err = mailimap_copy(m_imap,set,targetFolder.latin1());
1296 mailimap_set_free( set ); 1296 mailimap_set_free( set );
1297 if ( err != MAILIMAP_NO_ERROR ) { 1297 if ( err != MAILIMAP_NO_ERROR ) {
1298 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);
1299 Global::statusMessage(error_msg); 1299 Global::statusMessage(error_msg);
1300 // odebug << error_msg << oendl; 1300 // odebug << error_msg << oendl;
1301 return; 1301 return;
1302 } 1302 }
1303 if (moveit) { 1303 if (moveit) {
1304 deleteAllMail(fromFolder); 1304 deleteAllMail(fromFolder);
1305 } 1305 }
1306} 1306}
1307 1307
1308void 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)
1309{ 1309{
1310 if (targetWrapper != this) { 1310 if (targetWrapper != this) {
1311 // odebug << "Using generic" << oendl; 1311 // odebug << "Using generic" << oendl;
1312 AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); 1312 AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit);
1313 return; 1313 return;
1314 } 1314 }
1315 mailimap_set *set = 0; 1315 mailimap_set *set = 0;
1316 login(); 1316 login();
1317 if (!m_imap) { 1317 if (!m_imap) {
1318 return; 1318 return;
1319 } 1319 }
1320 int err = selectMbox(mail->getMbox()); 1320 int err = selectMbox(mail->getMbox());
1321 if ( err != MAILIMAP_NO_ERROR ) { 1321 if ( err != MAILIMAP_NO_ERROR ) {
1322 return; 1322 return;
1323 } 1323 }
1324 set = mailimap_set_new_single(mail->getNumber()); 1324 set = mailimap_set_new_single(mail->getNumber());
1325 err = mailimap_copy(m_imap,set,targetFolder.latin1()); 1325 err = mailimap_copy(m_imap,set,targetFolder.latin1());
1326 mailimap_set_free( set ); 1326 mailimap_set_free( set );
1327 if ( err != MAILIMAP_NO_ERROR ) { 1327 if ( err != MAILIMAP_NO_ERROR ) {
1328 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);
1329 Global::statusMessage(error_msg); 1329 Global::statusMessage(error_msg);