summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/imapwrapper.cpp9
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp9
2 files changed, 16 insertions, 2 deletions
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
index a01a2a9..9ee0dff 100644
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/noncore/net/mail/imapwrapper.cpp
@@ -108,387 +108,389 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
108 result = clist_new(); 108 result = clist_new();
109 /* the range has to start at 1!!! not with 0!!!! */ 109 /* the range has to start at 1!!! not with 0!!!! */
110 set = mailimap_set_new_interval( 1, last ); 110 set = mailimap_set_new_interval( 1, last );
111 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 111 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
114 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 114 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
115 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 115 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
116 116
117 err = mailimap_fetch( m_imap, set, fetchType, &result ); 117 err = mailimap_fetch( m_imap, set, fetchType, &result );
118 mailimap_set_free( set ); 118 mailimap_set_free( set );
119 mailimap_fetch_type_free( fetchType ); 119 mailimap_fetch_type_free( fetchType );
120 120
121 QString date,subject,from; 121 QString date,subject,from;
122 122
123 if ( err == MAILIMAP_NO_ERROR ) { 123 if ( err == MAILIMAP_NO_ERROR ) {
124 124
125 mailimap_msg_att * msg_att; 125 mailimap_msg_att * msg_att;
126 int i = 0; 126 int i = 0;
127 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 127 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
128 ++i; 128 ++i;
129 msg_att = (mailimap_msg_att*)current->data; 129 msg_att = (mailimap_msg_att*)current->data;
130 RecMail*m = parse_list_result(msg_att); 130 RecMail*m = parse_list_result(msg_att);
131 if (m) { 131 if (m) {
132 m->setNumber(i); 132 m->setNumber(i);
133 m->setMbox(mailbox); 133 m->setMbox(mailbox);
134 m->setWrapper(this); 134 m->setWrapper(this);
135 target.append(m); 135 target.append(m);
136 } 136 }
137 } 137 }
138 } else { 138 } else {
139 qDebug("Error fetching headers: %s",m_imap->imap_response); 139 qDebug("Error fetching headers: %s",m_imap->imap_response);
140 } 140 }
141 mailimap_fetch_list_free(result); 141 mailimap_fetch_list_free(result);
142} 142}
143 143
144QList<Folder>* IMAPwrapper::listFolders() 144QList<Folder>* IMAPwrapper::listFolders()
145{ 145{
146 const char *path, *mask; 146 const char *path, *mask;
147 int err = MAILIMAP_NO_ERROR; 147 int err = MAILIMAP_NO_ERROR;
148 clist *result; 148 clist *result;
149 clistcell *current; 149 clistcell *current;
150 150
151 QList<Folder> * folders = new QList<Folder>(); 151 QList<Folder> * folders = new QList<Folder>();
152 folders->setAutoDelete( true ); 152 folders->setAutoDelete( true );
153 login(); 153 login();
154 if (!m_imap) { 154 if (!m_imap) {
155 return folders; 155 return folders;
156 } 156 }
157 157
158/* 158/*
159 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 159 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
160 * We must not forget to filter them out in next loop! 160 * We must not forget to filter them out in next loop!
161 * it seems like ugly code. and yes - it is ugly code. but the best way. 161 * it seems like ugly code. and yes - it is ugly code. but the best way.
162 */ 162 */
163 QString temp; 163 QString temp;
164 mask = "INBOX" ; 164 mask = "INBOX" ;
165 result = clist_new(); 165 result = clist_new();
166 mailimap_mailbox_list *list; 166 mailimap_mailbox_list *list;
167 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 167 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
168 if ( err == MAILIMAP_NO_ERROR ) { 168 if ( err == MAILIMAP_NO_ERROR ) {
169 current = result->first; 169 current = result->first;
170 for ( int i = result->count; i > 0; i-- ) { 170 for ( int i = result->count; i > 0; i-- ) {
171 list = (mailimap_mailbox_list *) current->data; 171 list = (mailimap_mailbox_list *) current->data;
172 // it is better use the deep copy mechanism of qt itself 172 // it is better use the deep copy mechanism of qt itself
173 // instead of using strdup! 173 // instead of using strdup!
174 temp = list->mb_name; 174 temp = list->mb_name;
175 folders->append( new IMAPFolder(temp)); 175 folders->append( new IMAPFolder(temp));
176 current = current->next; 176 current = current->next;
177 } 177 }
178 } else { 178 } else {
179 qDebug("error fetching folders: %s",m_imap->imap_response); 179 qDebug("error fetching folders: %s",m_imap->imap_response);
180 } 180 }
181 mailimap_list_result_free( result ); 181 mailimap_list_result_free( result );
182 182
183/* 183/*
184 * second stage - get the other then inbox folders 184 * second stage - get the other then inbox folders
185 */ 185 */
186 mask = "*" ; 186 mask = "*" ;
187 path = account->getPrefix().latin1(); 187 path = account->getPrefix().latin1();
188 if (!path) path = ""; 188 if (!path) path = "";
189 result = clist_new(); 189 result = clist_new();
190 qDebug(path); 190 qDebug(path);
191 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 191 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
192 if ( err == MAILIMAP_NO_ERROR ) { 192 if ( err == MAILIMAP_NO_ERROR ) {
193 current = result->first; 193 current = result->first;
194 for ( int i = result->count; i > 0; i-- ) { 194 for ( int i = result->count; i > 0; i-- ) {
195 list = (mailimap_mailbox_list *) current->data; 195 list = (mailimap_mailbox_list *) current->data;
196 // it is better use the deep copy mechanism of qt itself 196 // it is better use the deep copy mechanism of qt itself
197 // instead of using strdup! 197 // instead of using strdup!
198 temp = list->mb_name; 198 temp = list->mb_name;
199 current = current->next; 199 current = current->next;
200 if (temp.lower()=="inbox") 200 if (temp.lower()=="inbox")
201 continue; 201 continue;
202 folders->append(new IMAPFolder(temp)); 202 folders->append(new IMAPFolder(temp));
203 203
204 } 204 }
205 } else { 205 } else {
206 qDebug("error fetching folders %s",m_imap->imap_response); 206 qDebug("error fetching folders %s",m_imap->imap_response);
207 } 207 }
208 mailimap_list_result_free( result ); 208 mailimap_list_result_free( result );
209 return folders; 209 return folders;
210} 210}
211 211
212RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 212RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
213{ 213{
214 RecMail * m = 0; 214 RecMail * m = 0;
215 mailimap_msg_att_item *item=0; 215 mailimap_msg_att_item *item=0;
216 clistcell *current,*c,*cf; 216 clistcell *current,*c,*cf;
217 mailimap_msg_att_dynamic*flist; 217 mailimap_msg_att_dynamic*flist;
218 mailimap_flag_fetch*cflag; 218 mailimap_flag_fetch*cflag;
219 int size; 219 int size;
220 QBitArray mFlags(7); 220 QBitArray mFlags(7);
221 QStringList addresslist; 221 QStringList addresslist;
222 222
223 if (!m_att) { 223 if (!m_att) {
224 return m; 224 return m;
225 } 225 }
226 m = new RecMail(); 226 m = new RecMail();
227 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 227 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
228 current = c; 228 current = c;
229 size = 0; 229 size = 0;
230 item = (mailimap_msg_att_item*)current->data; 230 item = (mailimap_msg_att_item*)current->data;
231 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 231 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
232 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 232 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
233 if (!flist->att_list) { 233 if (!flist->att_list) {
234 continue; 234 continue;
235 } 235 }
236 cf = flist->att_list->first; 236 cf = flist->att_list->first;
237 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 237 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
238 cflag = (mailimap_flag_fetch*)cf->data; 238 cflag = (mailimap_flag_fetch*)cf->data;
239 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 239 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
240 switch (cflag->fl_flag->fl_type) { 240 switch (cflag->fl_flag->fl_type) {
241 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 241 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
242 mFlags.setBit(FLAG_ANSWERED); 242 mFlags.setBit(FLAG_ANSWERED);
243 break; 243 break;
244 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 244 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
245 mFlags.setBit(FLAG_FLAGGED); 245 mFlags.setBit(FLAG_FLAGGED);
246 break; 246 break;
247 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 247 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
248 mFlags.setBit(FLAG_DELETED); 248 mFlags.setBit(FLAG_DELETED);
249 break; 249 break;
250 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 250 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
251 mFlags.setBit(FLAG_SEEN); 251 mFlags.setBit(FLAG_SEEN);
252 break; 252 break;
253 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 253 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
254 mFlags.setBit(FLAG_DRAFT); 254 mFlags.setBit(FLAG_DRAFT);
255 break; 255 break;
256 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 256 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
257 break; 257 break;
258 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 258 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
259 break; 259 break;
260 default: 260 default:
261 break; 261 break;
262 } 262 }
263 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 263 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
264 mFlags.setBit(FLAG_RECENT); 264 mFlags.setBit(FLAG_RECENT);
265 } 265 }
266 } 266 }
267 continue; 267 continue;
268 } 268 }
269 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 269 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
270 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 270 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
271 m->setDate(head->env_date); 271 m->setDate(head->env_date);
272 m->setSubject(head->env_subject); 272 m->setSubject(head->env_subject);
273 if (head->env_from!=NULL) { 273 if (head->env_from!=NULL) {
274 addresslist = address_list_to_stringlist(head->env_from->frm_list); 274 addresslist = address_list_to_stringlist(head->env_from->frm_list);
275 if (addresslist.count()) { 275 if (addresslist.count()) {
276 m->setFrom(addresslist.first()); 276 m->setFrom(addresslist.first());
277 } 277 }
278 } 278 }
279 if (head->env_to!=NULL) { 279 if (head->env_to!=NULL) {
280 addresslist = address_list_to_stringlist(head->env_to->to_list); 280 addresslist = address_list_to_stringlist(head->env_to->to_list);
281 m->setTo(addresslist); 281 m->setTo(addresslist);
282 } 282 }
283 if (head->env_cc!=NULL) { 283 if (head->env_cc!=NULL) {
284 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 284 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
285 m->setCC(addresslist); 285 m->setCC(addresslist);
286 } 286 }
287 if (head->env_bcc!=NULL) { 287 if (head->env_bcc!=NULL) {
288 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 288 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
289 m->setBcc(addresslist); 289 m->setBcc(addresslist);
290 } 290 }
291 if (head->env_reply_to!=NULL) { 291 if (head->env_reply_to!=NULL) {
292 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 292 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
293 if (addresslist.count()) { 293 if (addresslist.count()) {
294 m->setReplyto(addresslist.first()); 294 m->setReplyto(addresslist.first());
295 } 295 }
296 } 296 }
297 m->setMsgid(QString(head->env_message_id)); 297 m->setMsgid(QString(head->env_message_id));
298 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 298 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
299 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 299 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
300#if 0
300 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 301 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
301 qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); 302 qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec);
302 qDebug(da.toString()); 303 qDebug(da.toString());
304#endif
303 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 305 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
304 size = item->att_data.att_static->att_data.att_rfc822_size; 306 size = item->att_data.att_static->att_data.att_rfc822_size;
305 } 307 }
306 } 308 }
307 /* msg is already deleted */ 309 /* msg is already deleted */
308 if (mFlags.testBit(FLAG_DELETED) && m) { 310 if (mFlags.testBit(FLAG_DELETED) && m) {
309 delete m; 311 delete m;
310 m = 0; 312 m = 0;
311 } 313 }
312 if (m) { 314 if (m) {
313 m->setFlags(mFlags); 315 m->setFlags(mFlags);
314 m->setMsgsize(size); 316 m->setMsgsize(size);
315 } 317 }
316 return m; 318 return m;
317} 319}
318 320
319RecBody IMAPwrapper::fetchBody(const RecMail&mail) 321RecBody IMAPwrapper::fetchBody(const RecMail&mail)
320{ 322{
321 RecBody body; 323 RecBody body;
322 const char *mb; 324 const char *mb;
323 int err = MAILIMAP_NO_ERROR; 325 int err = MAILIMAP_NO_ERROR;
324 clist *result; 326 clist *result;
325 clistcell *current; 327 clistcell *current;
326 mailimap_fetch_att *fetchAtt; 328 mailimap_fetch_att *fetchAtt;
327 mailimap_fetch_type *fetchType; 329 mailimap_fetch_type *fetchType;
328 mailimap_set *set; 330 mailimap_set *set;
329 mailimap_body*body_desc; 331 mailimap_body*body_desc;
330 332
331 mb = mail.getMbox().latin1(); 333 mb = mail.getMbox().latin1();
332 334
333 login(); 335 login();
334 if (!m_imap) { 336 if (!m_imap) {
335 return body; 337 return body;
336 } 338 }
337 339
338 err = mailimap_select( m_imap, (char*)mb); 340 err = mailimap_select( m_imap, (char*)mb);
339 if ( err != MAILIMAP_NO_ERROR ) { 341 if ( err != MAILIMAP_NO_ERROR ) {
340 qDebug("error selecting mailbox: %s",m_imap->imap_response); 342 qDebug("error selecting mailbox: %s",m_imap->imap_response);
341 return body; 343 return body;
342 } 344 }
343 345
344 result = clist_new(); 346 result = clist_new();
345 /* the range has to start at 1!!! not with 0!!!! */ 347 /* the range has to start at 1!!! not with 0!!!! */
346 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 348 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
347 fetchAtt = mailimap_fetch_att_new_bodystructure(); 349 fetchAtt = mailimap_fetch_att_new_bodystructure();
348 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 350 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
349 err = mailimap_fetch( m_imap, set, fetchType, &result ); 351 err = mailimap_fetch( m_imap, set, fetchType, &result );
350 mailimap_set_free( set ); 352 mailimap_set_free( set );
351 mailimap_fetch_type_free( fetchType ); 353 mailimap_fetch_type_free( fetchType );
352 354
353 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 355 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
354 mailimap_msg_att * msg_att; 356 mailimap_msg_att * msg_att;
355 msg_att = (mailimap_msg_att*)current->data; 357 msg_att = (mailimap_msg_att*)current->data;
356 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 358 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
357 body_desc = item->att_data.att_static->att_data.att_body; 359 body_desc = item->att_data.att_static->att_data.att_body;
358 if (body_desc->bd_type==MAILIMAP_BODY_1PART) { 360 if (body_desc->bd_type==MAILIMAP_BODY_1PART) {
359 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); 361 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
360 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { 362 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) {
361 qDebug("Mulitpart mail"); 363 qDebug("Mulitpart mail");
362 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); 364 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body);
363 } 365 }
364 } else { 366 } else {
365 qDebug("error fetching body: %s",m_imap->imap_response); 367 qDebug("error fetching body: %s",m_imap->imap_response);
366 } 368 }
367 mailimap_fetch_list_free(result); 369 mailimap_fetch_list_free(result);
368 return body; 370 return body;
369} 371}
370 372
371/* this routine is just called when the mail has only ONE part. 373/* this routine is just called when the mail has only ONE part.
372 for filling the parts of a multi-part-message there are other 374 for filling the parts of a multi-part-message there are other
373 routines 'cause we can not simply fetch the whole body. */ 375 routines 'cause we can not simply fetch the whole body. */
374void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 376void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
375{ 377{
376 if (!mailDescription) { 378 if (!mailDescription) {
377 return; 379 return;
378 } 380 }
379 QString sub,body_text; 381 QString sub,body_text;
380 RecPart singlePart; 382 RecPart singlePart;
381 QValueList<int> path; 383 QValueList<int> path;
382 fillSinglePart(singlePart,mailDescription); 384 fillSinglePart(singlePart,mailDescription);
383 switch (mailDescription->bd_type) { 385 switch (mailDescription->bd_type) {
384 case MAILIMAP_BODY_TYPE_1PART_MSG: 386 case MAILIMAP_BODY_TYPE_1PART_MSG:
385 path.append(1); 387 path.append(1);
386 body_text = fetchPart(mail,path,true); 388 body_text = fetchPart(mail,path,true);
387 target_body.setBodytext(body_text); 389 target_body.setBodytext(body_text);
388 target_body.setDescription(singlePart); 390 target_body.setDescription(singlePart);
389 break; 391 break;
390 case MAILIMAP_BODY_TYPE_1PART_TEXT: 392 case MAILIMAP_BODY_TYPE_1PART_TEXT:
391 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); 393 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
392 path.append(1); 394 path.append(1);
393 body_text = fetchPart(mail,path,true); 395 body_text = fetchPart(mail,path,true);
394 target_body.setBodytext(body_text); 396 target_body.setBodytext(body_text);
395 target_body.setDescription(singlePart); 397 target_body.setDescription(singlePart);
396 break; 398 break;
397 case MAILIMAP_BODY_TYPE_1PART_BASIC: 399 case MAILIMAP_BODY_TYPE_1PART_BASIC:
398 qDebug("Single attachment"); 400 qDebug("Single attachment");
399 target_body.setBodytext(""); 401 target_body.setBodytext("");
400 target_body.addPart(singlePart); 402 target_body.addPart(singlePart);
401 break; 403 break;
402 default: 404 default:
403 break; 405 break;
404 } 406 }
405 407
406 return; 408 return;
407} 409}
408 410
409QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 411QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
410{ 412{
411 QStringList l; 413 QStringList l;
412 QString from; 414 QString from;
413 bool named_from; 415 bool named_from;
414 clistcell *current = NULL; 416 clistcell *current = NULL;
415 mailimap_address * current_address=NULL; 417 mailimap_address * current_address=NULL;
416 if (!list) { 418 if (!list) {
417 return l; 419 return l;
418 } 420 }
419 unsigned int count = 0; 421 unsigned int count = 0;
420 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 422 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
421 from = ""; 423 from = "";
422 named_from = false; 424 named_from = false;
423 current_address=(mailimap_address*)current->data; 425 current_address=(mailimap_address*)current->data;
424 if (current_address->ad_personal_name){ 426 if (current_address->ad_personal_name){
425 from+=QString(current_address->ad_personal_name); 427 from+=QString(current_address->ad_personal_name);
426 from+=" "; 428 from+=" ";
427 named_from = true; 429 named_from = true;
428 } 430 }
429 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 431 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
430 from+="<"; 432 from+="<";
431 } 433 }
432 if (current_address->ad_mailbox_name) { 434 if (current_address->ad_mailbox_name) {
433 from+=QString(current_address->ad_mailbox_name); 435 from+=QString(current_address->ad_mailbox_name);
434 from+="@"; 436 from+="@";
435 } 437 }
436 if (current_address->ad_host_name) { 438 if (current_address->ad_host_name) {
437 from+=QString(current_address->ad_host_name); 439 from+=QString(current_address->ad_host_name);
438 } 440 }
439 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 441 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
440 from+=">"; 442 from+=">";
441 } 443 }
442 l.append(QString(from)); 444 l.append(QString(from));
443 if (++count > 99) { 445 if (++count > 99) {
444 break; 446 break;
445 } 447 }
446 } 448 }
447 return l; 449 return l;
448} 450}
449 451
450QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 452QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
451{ 453{
452 QString body(""); 454 QString body("");
453 const char*mb; 455 const char*mb;
454 int err; 456 int err;
455 mailimap_fetch_type *fetchType; 457 mailimap_fetch_type *fetchType;
456 mailimap_set *set; 458 mailimap_set *set;
457 clistcell*current,*cur; 459 clistcell*current,*cur;
458 460
459 login(); 461 login();
460 if (!m_imap) { 462 if (!m_imap) {
461 return body; 463 return body;
462 } 464 }
463 if (!internal_call) { 465 if (!internal_call) {
464 mb = mail.getMbox().latin1(); 466 mb = mail.getMbox().latin1();
465 err = mailimap_select( m_imap, (char*)mb); 467 err = mailimap_select( m_imap, (char*)mb);
466 if ( err != MAILIMAP_NO_ERROR ) { 468 if ( err != MAILIMAP_NO_ERROR ) {
467 qDebug("error selecting mailbox: %s",m_imap->imap_response); 469 qDebug("error selecting mailbox: %s",m_imap->imap_response);
468 return body; 470 return body;
469 } 471 }
470 } 472 }
471 set = mailimap_set_new_single(mail.getNumber()); 473 set = mailimap_set_new_single(mail.getNumber());
472 clist*id_list=clist_new(); 474 clist*id_list=clist_new();
473 for (unsigned j=0; j < path.count();++j) { 475 for (unsigned j=0; j < path.count();++j) {
474 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 476 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
475 *p_id = path[j]; 477 *p_id = path[j];
476 clist_append(id_list,p_id); 478 clist_append(id_list,p_id);
477 } 479 }
478 mailimap_section_part * section_part = mailimap_section_part_new(id_list); 480 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
479 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 481 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
480 mailimap_section * section = mailimap_section_new(section_spec); 482 mailimap_section * section = mailimap_section_new(section_spec);
481 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); 483 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section);
482 484
483 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 485 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
484 486
485 clist*result = clist_new(); 487 clist*result = clist_new();
486 488
487 err = mailimap_fetch( m_imap, set, fetchType, &result ); 489 err = mailimap_fetch( m_imap, set, fetchType, &result );
488 mailimap_set_free( set ); 490 mailimap_set_free( set );
489 mailimap_fetch_type_free( fetchType ); 491 mailimap_fetch_type_free( fetchType );
490 492
491 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 493 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
492 mailimap_msg_att * msg_att; 494 mailimap_msg_att * msg_att;
493 msg_att = (mailimap_msg_att*)current->data; 495 msg_att = (mailimap_msg_att*)current->data;
494 mailimap_msg_att_item*msg_att_item; 496 mailimap_msg_att_item*msg_att_item;
@@ -529,202 +531,207 @@ void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mai
529 ++count; 531 ++count;
530 current_body = (mailimap_body*)current->data; 532 current_body = (mailimap_body*)current->data;
531 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 533 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
532 QValueList<int>clist = recList; 534 QValueList<int>clist = recList;
533 clist.append(count); 535 clist.append(count);
534 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); 536 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist);
535 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ 537 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
536 RecPart currentPart; 538 RecPart currentPart;
537 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); 539 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
538 QValueList<int>clist = recList; 540 QValueList<int>clist = recList;
539 clist.append(count); 541 clist.append(count);
540 /* important: Check for is NULL 'cause a body can be empty! */ 542 /* important: Check for is NULL 'cause a body can be empty! */
541 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { 543 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
542 QString body_text = fetchPart(mail,clist,true); 544 QString body_text = fetchPart(mail,clist,true);
543 target_body.setDescription(currentPart); 545 target_body.setDescription(currentPart);
544 target_body.setBodytext(body_text); 546 target_body.setBodytext(body_text);
545 } else { 547 } else {
546 QString id(""); 548 QString id("");
547 for (unsigned int j = 0; j < clist.count();++j) { 549 for (unsigned int j = 0; j < clist.count();++j) {
548 id+=(j>0?" ":""); 550 id+=(j>0?" ":"");
549 id+=QString("%1").arg(clist[j]); 551 id+=QString("%1").arg(clist[j]);
550 } 552 }
551 qDebug("ID= %s",id.latin1()); 553 qDebug("ID= %s",id.latin1());
552 currentPart.setIdentifier(id); 554 currentPart.setIdentifier(id);
553 currentPart.setPositionlist(clist); 555 currentPart.setPositionlist(clist);
554 target_body.addPart(currentPart); 556 target_body.addPart(currentPart);
555 } 557 }
556 } 558 }
557 } 559 }
558} 560}
559 561
560void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 562void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
561{ 563{
562 if (!Description) { 564 if (!Description) {
563 return; 565 return;
564 } 566 }
565 switch (Description->bd_type) { 567 switch (Description->bd_type) {
566 case MAILIMAP_BODY_TYPE_1PART_TEXT: 568 case MAILIMAP_BODY_TYPE_1PART_TEXT:
567 target_part.setType("text"); 569 target_part.setType("text");
568 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 570 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
569 break; 571 break;
570 case MAILIMAP_BODY_TYPE_1PART_BASIC: 572 case MAILIMAP_BODY_TYPE_1PART_BASIC:
571 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 573 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
572 break; 574 break;
573 case MAILIMAP_BODY_TYPE_1PART_MSG: 575 case MAILIMAP_BODY_TYPE_1PART_MSG:
574 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 576 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
575 break; 577 break;
576 default: 578 default:
577 break; 579 break;
578 } 580 }
579} 581}
580 582
581void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 583void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
582{ 584{
583 if (!which) { 585 if (!which) {
584 return; 586 return;
585 } 587 }
586 QString sub; 588 QString sub;
587 sub = which->bd_media_text; 589 sub = which->bd_media_text;
588 target_part.setSubtype(sub.lower()); 590 target_part.setSubtype(sub.lower());
589 target_part.setLines(which->bd_lines); 591 target_part.setLines(which->bd_lines);
590 fillBodyFields(target_part,which->bd_fields); 592 fillBodyFields(target_part,which->bd_fields);
591} 593}
592 594
593void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 595void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
594{ 596{
595 if (!which) { 597 if (!which) {
596 return; 598 return;
597 } 599 }
598// QString sub; 600// QString sub;
599// sub = which->bd_media_text; 601// sub = which->bd_media_text;
600// target_part.setSubtype(sub.lower()); 602// target_part.setSubtype(sub.lower());
601 qDebug("Message part"); 603 qDebug("Message part");
602 /* we set this type to text/plain */ 604 /* we set this type to text/plain */
603 target_part.setType("text"); 605 target_part.setType("text");
604 target_part.setSubtype("plain"); 606 target_part.setSubtype("plain");
605 target_part.setLines(which->bd_lines); 607 target_part.setLines(which->bd_lines);
606 fillBodyFields(target_part,which->bd_fields); 608 fillBodyFields(target_part,which->bd_fields);
607} 609}
608 610
609void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 611void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
610{ 612{
611 if (!which) { 613 if (!which) {
612 return; 614 return;
613 } 615 }
614 QString type,sub; 616 QString type,sub;
615 switch (which->bd_media_basic->med_type) { 617 switch (which->bd_media_basic->med_type) {
616 case MAILIMAP_MEDIA_BASIC_APPLICATION: 618 case MAILIMAP_MEDIA_BASIC_APPLICATION:
617 type = "application"; 619 type = "application";
618 break; 620 break;
619 case MAILIMAP_MEDIA_BASIC_AUDIO: 621 case MAILIMAP_MEDIA_BASIC_AUDIO:
620 type = "audio"; 622 type = "audio";
621 break; 623 break;
622 case MAILIMAP_MEDIA_BASIC_IMAGE: 624 case MAILIMAP_MEDIA_BASIC_IMAGE:
623 type = "image"; 625 type = "image";
624 break; 626 break;
625 case MAILIMAP_MEDIA_BASIC_MESSAGE: 627 case MAILIMAP_MEDIA_BASIC_MESSAGE:
626 type = "message"; 628 type = "message";
627 break; 629 break;
628 case MAILIMAP_MEDIA_BASIC_VIDEO: 630 case MAILIMAP_MEDIA_BASIC_VIDEO:
629 type = "video"; 631 type = "video";
630 break; 632 break;
631 case MAILIMAP_MEDIA_BASIC_OTHER: 633 case MAILIMAP_MEDIA_BASIC_OTHER:
632 default: 634 default:
633 if (which->bd_media_basic->med_basic_type) { 635 if (which->bd_media_basic->med_basic_type) {
634 type = which->bd_media_basic->med_basic_type; 636 type = which->bd_media_basic->med_basic_type;
635 } else { 637 } else {
636 type = ""; 638 type = "";
637 } 639 }
638 break; 640 break;
639 } 641 }
640 if (which->bd_media_basic->med_subtype) { 642 if (which->bd_media_basic->med_subtype) {
641 sub = which->bd_media_basic->med_subtype; 643 sub = which->bd_media_basic->med_subtype;
642 } else { 644 } else {
643 sub = ""; 645 sub = "";
644 } 646 }
645 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 647 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
646 target_part.setType(type.lower()); 648 target_part.setType(type.lower());
647 target_part.setSubtype(sub.lower()); 649 target_part.setSubtype(sub.lower());
648 fillBodyFields(target_part,which->bd_fields); 650 fillBodyFields(target_part,which->bd_fields);
649} 651}
650 652
651void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) 653void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
652{ 654{
653 if (!which) return; 655 if (!which) return;
654 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 656 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
655 clistcell*cur; 657 clistcell*cur;
656 mailimap_single_body_fld_param*param=0; 658 mailimap_single_body_fld_param*param=0;
657 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 659 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
658 param = (mailimap_single_body_fld_param*)cur->data; 660 param = (mailimap_single_body_fld_param*)cur->data;
659 if (param) { 661 if (param) {
660 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 662 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
661 } 663 }
662 } 664 }
663 } 665 }
664 mailimap_body_fld_enc*enc = which->bd_encoding; 666 mailimap_body_fld_enc*enc = which->bd_encoding;
665 QString encoding(""); 667 QString encoding("");
666 switch (enc->enc_type) { 668 switch (enc->enc_type) {
667 case MAILIMAP_BODY_FLD_ENC_7BIT: 669 case MAILIMAP_BODY_FLD_ENC_7BIT:
668 encoding = "7bit"; 670 encoding = "7bit";
669 break; 671 break;
670 case MAILIMAP_BODY_FLD_ENC_8BIT: 672 case MAILIMAP_BODY_FLD_ENC_8BIT:
671 encoding = "8bit"; 673 encoding = "8bit";
672 break; 674 break;
673 case MAILIMAP_BODY_FLD_ENC_BINARY: 675 case MAILIMAP_BODY_FLD_ENC_BINARY:
674 encoding="binary"; 676 encoding="binary";
675 break; 677 break;
676 case MAILIMAP_BODY_FLD_ENC_BASE64: 678 case MAILIMAP_BODY_FLD_ENC_BASE64:
677 encoding="base64"; 679 encoding="base64";
678 break; 680 break;
679 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 681 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
680 encoding="quoted-printable"; 682 encoding="quoted-printable";
681 break; 683 break;
682 case MAILIMAP_BODY_FLD_ENC_OTHER: 684 case MAILIMAP_BODY_FLD_ENC_OTHER:
683 default: 685 default:
684 if (enc->enc_value) { 686 if (enc->enc_value) {
685 char*t=enc->enc_value; 687 char*t=enc->enc_value;
686 encoding=QString(enc->enc_value); 688 encoding=QString(enc->enc_value);
687 enc->enc_value=0L; 689 enc->enc_value=0L;
688 free(t); 690 free(t);
689 } 691 }
690 } 692 }
691 target_part.setEncoding(encoding); 693 target_part.setEncoding(encoding);
692 target_part.setSize(which->bd_size); 694 target_part.setSize(which->bd_size);
693} 695}
694 696
695QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part) 697QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part)
696{ 698{
697 return fetchPart(mail,part.Positionlist(),false); 699 return fetchPart(mail,part.Positionlist(),false);
698} 700}
699 701
700void IMAPwrapper::deleteMail(const RecMail&mail) 702void IMAPwrapper::deleteMail(const RecMail&mail)
701{ 703{
702 mailimap_flag_list*flist; 704 mailimap_flag_list*flist;
703 mailimap_set *set; 705 mailimap_set *set;
704 mailimap_store_att_flags * store_flags; 706 mailimap_store_att_flags * store_flags;
705 int err; 707 int err;
706 login(); 708 login();
707 if (!m_imap) { 709 if (!m_imap) {
708 return; 710 return;
709 } 711 }
710 const char *mb = mail.getMbox().latin1(); 712 const char *mb = mail.getMbox().latin1();
711 err = mailimap_select( m_imap, (char*)mb); 713 err = mailimap_select( m_imap, (char*)mb);
712 if ( err != MAILIMAP_NO_ERROR ) { 714 if ( err != MAILIMAP_NO_ERROR ) {
713 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); 715 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response);
714 return; 716 return;
715 } 717 }
716 flist = mailimap_flag_list_new_empty(); 718 flist = mailimap_flag_list_new_empty();
717 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 719 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
718 store_flags = mailimap_store_att_flags_new_set_flags(flist); 720 store_flags = mailimap_store_att_flags_new_set_flags(flist);
719 set = mailimap_set_new_single(mail.getNumber()); 721 set = mailimap_set_new_single(mail.getNumber());
720 err = mailimap_store(m_imap,set,store_flags); 722 err = mailimap_store(m_imap,set,store_flags);
723 mailimap_set_free( set );
724 mailimap_store_att_flags_free(store_flags);
725
721 if (err != MAILIMAP_NO_ERROR) { 726 if (err != MAILIMAP_NO_ERROR) {
722 qDebug("error deleting mail: %s",m_imap->imap_response); 727 qDebug("error deleting mail: %s",m_imap->imap_response);
723 return; 728 return;
724 } 729 }
730 qDebug("deleting mail: %s",m_imap->imap_response);
731 /* should we realy do that at this moment? */
725 err = mailimap_expunge(m_imap); 732 err = mailimap_expunge(m_imap);
726 if (err != MAILIMAP_NO_ERROR) { 733 if (err != MAILIMAP_NO_ERROR) {
727 qDebug("error deleting mail: %s",m_imap->imap_response); 734 qDebug("error deleting mail: %s",m_imap->imap_response);
728 } 735 }
729 qDebug("Delete successfull"); 736 qDebug("Delete successfull %s",m_imap->imap_response);
730} 737}
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index a01a2a9..9ee0dff 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -108,387 +108,389 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
108 result = clist_new(); 108 result = clist_new();
109 /* the range has to start at 1!!! not with 0!!!! */ 109 /* the range has to start at 1!!! not with 0!!!! */
110 set = mailimap_set_new_interval( 1, last ); 110 set = mailimap_set_new_interval( 1, last );
111 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 111 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
114 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 114 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
115 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 115 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
116 116
117 err = mailimap_fetch( m_imap, set, fetchType, &result ); 117 err = mailimap_fetch( m_imap, set, fetchType, &result );
118 mailimap_set_free( set ); 118 mailimap_set_free( set );
119 mailimap_fetch_type_free( fetchType ); 119 mailimap_fetch_type_free( fetchType );
120 120
121 QString date,subject,from; 121 QString date,subject,from;
122 122
123 if ( err == MAILIMAP_NO_ERROR ) { 123 if ( err == MAILIMAP_NO_ERROR ) {
124 124
125 mailimap_msg_att * msg_att; 125 mailimap_msg_att * msg_att;
126 int i = 0; 126 int i = 0;
127 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 127 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
128 ++i; 128 ++i;
129 msg_att = (mailimap_msg_att*)current->data; 129 msg_att = (mailimap_msg_att*)current->data;
130 RecMail*m = parse_list_result(msg_att); 130 RecMail*m = parse_list_result(msg_att);
131 if (m) { 131 if (m) {
132 m->setNumber(i); 132 m->setNumber(i);
133 m->setMbox(mailbox); 133 m->setMbox(mailbox);
134 m->setWrapper(this); 134 m->setWrapper(this);
135 target.append(m); 135 target.append(m);
136 } 136 }
137 } 137 }
138 } else { 138 } else {
139 qDebug("Error fetching headers: %s",m_imap->imap_response); 139 qDebug("Error fetching headers: %s",m_imap->imap_response);
140 } 140 }
141 mailimap_fetch_list_free(result); 141 mailimap_fetch_list_free(result);
142} 142}
143 143
144QList<Folder>* IMAPwrapper::listFolders() 144QList<Folder>* IMAPwrapper::listFolders()
145{ 145{
146 const char *path, *mask; 146 const char *path, *mask;
147 int err = MAILIMAP_NO_ERROR; 147 int err = MAILIMAP_NO_ERROR;
148 clist *result; 148 clist *result;
149 clistcell *current; 149 clistcell *current;
150 150
151 QList<Folder> * folders = new QList<Folder>(); 151 QList<Folder> * folders = new QList<Folder>();
152 folders->setAutoDelete( true ); 152 folders->setAutoDelete( true );
153 login(); 153 login();
154 if (!m_imap) { 154 if (!m_imap) {
155 return folders; 155 return folders;
156 } 156 }
157 157
158/* 158/*
159 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 159 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
160 * We must not forget to filter them out in next loop! 160 * We must not forget to filter them out in next loop!
161 * it seems like ugly code. and yes - it is ugly code. but the best way. 161 * it seems like ugly code. and yes - it is ugly code. but the best way.
162 */ 162 */
163 QString temp; 163 QString temp;
164 mask = "INBOX" ; 164 mask = "INBOX" ;
165 result = clist_new(); 165 result = clist_new();
166 mailimap_mailbox_list *list; 166 mailimap_mailbox_list *list;
167 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 167 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
168 if ( err == MAILIMAP_NO_ERROR ) { 168 if ( err == MAILIMAP_NO_ERROR ) {
169 current = result->first; 169 current = result->first;
170 for ( int i = result->count; i > 0; i-- ) { 170 for ( int i = result->count; i > 0; i-- ) {
171 list = (mailimap_mailbox_list *) current->data; 171 list = (mailimap_mailbox_list *) current->data;
172 // it is better use the deep copy mechanism of qt itself 172 // it is better use the deep copy mechanism of qt itself
173 // instead of using strdup! 173 // instead of using strdup!
174 temp = list->mb_name; 174 temp = list->mb_name;
175 folders->append( new IMAPFolder(temp)); 175 folders->append( new IMAPFolder(temp));
176 current = current->next; 176 current = current->next;
177 } 177 }
178 } else { 178 } else {
179 qDebug("error fetching folders: %s",m_imap->imap_response); 179 qDebug("error fetching folders: %s",m_imap->imap_response);
180 } 180 }
181 mailimap_list_result_free( result ); 181 mailimap_list_result_free( result );
182 182
183/* 183/*
184 * second stage - get the other then inbox folders 184 * second stage - get the other then inbox folders
185 */ 185 */
186 mask = "*" ; 186 mask = "*" ;
187 path = account->getPrefix().latin1(); 187 path = account->getPrefix().latin1();
188 if (!path) path = ""; 188 if (!path) path = "";
189 result = clist_new(); 189 result = clist_new();
190 qDebug(path); 190 qDebug(path);
191 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 191 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
192 if ( err == MAILIMAP_NO_ERROR ) { 192 if ( err == MAILIMAP_NO_ERROR ) {
193 current = result->first; 193 current = result->first;
194 for ( int i = result->count; i > 0; i-- ) { 194 for ( int i = result->count; i > 0; i-- ) {
195 list = (mailimap_mailbox_list *) current->data; 195 list = (mailimap_mailbox_list *) current->data;
196 // it is better use the deep copy mechanism of qt itself 196 // it is better use the deep copy mechanism of qt itself
197 // instead of using strdup! 197 // instead of using strdup!
198 temp = list->mb_name; 198 temp = list->mb_name;
199 current = current->next; 199 current = current->next;
200 if (temp.lower()=="inbox") 200 if (temp.lower()=="inbox")
201 continue; 201 continue;
202 folders->append(new IMAPFolder(temp)); 202 folders->append(new IMAPFolder(temp));
203 203
204 } 204 }
205 } else { 205 } else {
206 qDebug("error fetching folders %s",m_imap->imap_response); 206 qDebug("error fetching folders %s",m_imap->imap_response);
207 } 207 }
208 mailimap_list_result_free( result ); 208 mailimap_list_result_free( result );
209 return folders; 209 return folders;
210} 210}
211 211
212RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 212RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
213{ 213{
214 RecMail * m = 0; 214 RecMail * m = 0;
215 mailimap_msg_att_item *item=0; 215 mailimap_msg_att_item *item=0;
216 clistcell *current,*c,*cf; 216 clistcell *current,*c,*cf;
217 mailimap_msg_att_dynamic*flist; 217 mailimap_msg_att_dynamic*flist;
218 mailimap_flag_fetch*cflag; 218 mailimap_flag_fetch*cflag;
219 int size; 219 int size;
220 QBitArray mFlags(7); 220 QBitArray mFlags(7);
221 QStringList addresslist; 221 QStringList addresslist;
222 222
223 if (!m_att) { 223 if (!m_att) {
224 return m; 224 return m;
225 } 225 }
226 m = new RecMail(); 226 m = new RecMail();
227 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 227 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
228 current = c; 228 current = c;
229 size = 0; 229 size = 0;
230 item = (mailimap_msg_att_item*)current->data; 230 item = (mailimap_msg_att_item*)current->data;
231 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 231 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
232 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 232 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
233 if (!flist->att_list) { 233 if (!flist->att_list) {
234 continue; 234 continue;
235 } 235 }
236 cf = flist->att_list->first; 236 cf = flist->att_list->first;
237 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 237 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
238 cflag = (mailimap_flag_fetch*)cf->data; 238 cflag = (mailimap_flag_fetch*)cf->data;
239 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 239 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
240 switch (cflag->fl_flag->fl_type) { 240 switch (cflag->fl_flag->fl_type) {
241 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 241 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
242 mFlags.setBit(FLAG_ANSWERED); 242 mFlags.setBit(FLAG_ANSWERED);
243 break; 243 break;
244 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 244 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
245 mFlags.setBit(FLAG_FLAGGED); 245 mFlags.setBit(FLAG_FLAGGED);
246 break; 246 break;
247 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 247 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
248 mFlags.setBit(FLAG_DELETED); 248 mFlags.setBit(FLAG_DELETED);
249 break; 249 break;
250 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 250 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
251 mFlags.setBit(FLAG_SEEN); 251 mFlags.setBit(FLAG_SEEN);
252 break; 252 break;
253 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 253 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
254 mFlags.setBit(FLAG_DRAFT); 254 mFlags.setBit(FLAG_DRAFT);
255 break; 255 break;
256 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 256 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
257 break; 257 break;
258 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 258 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
259 break; 259 break;
260 default: 260 default:
261 break; 261 break;
262 } 262 }
263 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 263 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
264 mFlags.setBit(FLAG_RECENT); 264 mFlags.setBit(FLAG_RECENT);
265 } 265 }
266 } 266 }
267 continue; 267 continue;
268 } 268 }
269 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 269 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
270 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 270 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
271 m->setDate(head->env_date); 271 m->setDate(head->env_date);
272 m->setSubject(head->env_subject); 272 m->setSubject(head->env_subject);
273 if (head->env_from!=NULL) { 273 if (head->env_from!=NULL) {
274 addresslist = address_list_to_stringlist(head->env_from->frm_list); 274 addresslist = address_list_to_stringlist(head->env_from->frm_list);
275 if (addresslist.count()) { 275 if (addresslist.count()) {
276 m->setFrom(addresslist.first()); 276 m->setFrom(addresslist.first());
277 } 277 }
278 } 278 }
279 if (head->env_to!=NULL) { 279 if (head->env_to!=NULL) {
280 addresslist = address_list_to_stringlist(head->env_to->to_list); 280 addresslist = address_list_to_stringlist(head->env_to->to_list);
281 m->setTo(addresslist); 281 m->setTo(addresslist);
282 } 282 }
283 if (head->env_cc!=NULL) { 283 if (head->env_cc!=NULL) {
284 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 284 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
285 m->setCC(addresslist); 285 m->setCC(addresslist);
286 } 286 }
287 if (head->env_bcc!=NULL) { 287 if (head->env_bcc!=NULL) {
288 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 288 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
289 m->setBcc(addresslist); 289 m->setBcc(addresslist);
290 } 290 }
291 if (head->env_reply_to!=NULL) { 291 if (head->env_reply_to!=NULL) {
292 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 292 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
293 if (addresslist.count()) { 293 if (addresslist.count()) {
294 m->setReplyto(addresslist.first()); 294 m->setReplyto(addresslist.first());
295 } 295 }
296 } 296 }
297 m->setMsgid(QString(head->env_message_id)); 297 m->setMsgid(QString(head->env_message_id));
298 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 298 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
299 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 299 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
300#if 0
300 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 301 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
301 qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); 302 qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec);
302 qDebug(da.toString()); 303 qDebug(da.toString());
304#endif
303 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 305 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
304 size = item->att_data.att_static->att_data.att_rfc822_size; 306 size = item->att_data.att_static->att_data.att_rfc822_size;
305 } 307 }
306 } 308 }
307 /* msg is already deleted */ 309 /* msg is already deleted */
308 if (mFlags.testBit(FLAG_DELETED) && m) { 310 if (mFlags.testBit(FLAG_DELETED) && m) {
309 delete m; 311 delete m;
310 m = 0; 312 m = 0;
311 } 313 }
312 if (m) { 314 if (m) {
313 m->setFlags(mFlags); 315 m->setFlags(mFlags);
314 m->setMsgsize(size); 316 m->setMsgsize(size);
315 } 317 }
316 return m; 318 return m;
317} 319}
318 320
319RecBody IMAPwrapper::fetchBody(const RecMail&mail) 321RecBody IMAPwrapper::fetchBody(const RecMail&mail)
320{ 322{
321 RecBody body; 323 RecBody body;
322 const char *mb; 324 const char *mb;
323 int err = MAILIMAP_NO_ERROR; 325 int err = MAILIMAP_NO_ERROR;
324 clist *result; 326 clist *result;
325 clistcell *current; 327 clistcell *current;
326 mailimap_fetch_att *fetchAtt; 328 mailimap_fetch_att *fetchAtt;
327 mailimap_fetch_type *fetchType; 329 mailimap_fetch_type *fetchType;
328 mailimap_set *set; 330 mailimap_set *set;
329 mailimap_body*body_desc; 331 mailimap_body*body_desc;
330 332
331 mb = mail.getMbox().latin1(); 333 mb = mail.getMbox().latin1();
332 334
333 login(); 335 login();
334 if (!m_imap) { 336 if (!m_imap) {
335 return body; 337 return body;
336 } 338 }
337 339
338 err = mailimap_select( m_imap, (char*)mb); 340 err = mailimap_select( m_imap, (char*)mb);
339 if ( err != MAILIMAP_NO_ERROR ) { 341 if ( err != MAILIMAP_NO_ERROR ) {
340 qDebug("error selecting mailbox: %s",m_imap->imap_response); 342 qDebug("error selecting mailbox: %s",m_imap->imap_response);
341 return body; 343 return body;
342 } 344 }
343 345
344 result = clist_new(); 346 result = clist_new();
345 /* the range has to start at 1!!! not with 0!!!! */ 347 /* the range has to start at 1!!! not with 0!!!! */
346 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 348 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
347 fetchAtt = mailimap_fetch_att_new_bodystructure(); 349 fetchAtt = mailimap_fetch_att_new_bodystructure();
348 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 350 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
349 err = mailimap_fetch( m_imap, set, fetchType, &result ); 351 err = mailimap_fetch( m_imap, set, fetchType, &result );
350 mailimap_set_free( set ); 352 mailimap_set_free( set );
351 mailimap_fetch_type_free( fetchType ); 353 mailimap_fetch_type_free( fetchType );
352 354
353 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 355 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
354 mailimap_msg_att * msg_att; 356 mailimap_msg_att * msg_att;
355 msg_att = (mailimap_msg_att*)current->data; 357 msg_att = (mailimap_msg_att*)current->data;
356 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 358 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
357 body_desc = item->att_data.att_static->att_data.att_body; 359 body_desc = item->att_data.att_static->att_data.att_body;
358 if (body_desc->bd_type==MAILIMAP_BODY_1PART) { 360 if (body_desc->bd_type==MAILIMAP_BODY_1PART) {
359 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); 361 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
360 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { 362 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) {
361 qDebug("Mulitpart mail"); 363 qDebug("Mulitpart mail");
362 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); 364 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body);
363 } 365 }
364 } else { 366 } else {
365 qDebug("error fetching body: %s",m_imap->imap_response); 367 qDebug("error fetching body: %s",m_imap->imap_response);
366 } 368 }
367 mailimap_fetch_list_free(result); 369 mailimap_fetch_list_free(result);
368 return body; 370 return body;
369} 371}
370 372
371/* this routine is just called when the mail has only ONE part. 373/* this routine is just called when the mail has only ONE part.
372 for filling the parts of a multi-part-message there are other 374 for filling the parts of a multi-part-message there are other
373 routines 'cause we can not simply fetch the whole body. */ 375 routines 'cause we can not simply fetch the whole body. */
374void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 376void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
375{ 377{
376 if (!mailDescription) { 378 if (!mailDescription) {
377 return; 379 return;
378 } 380 }
379 QString sub,body_text; 381 QString sub,body_text;
380 RecPart singlePart; 382 RecPart singlePart;
381 QValueList<int> path; 383 QValueList<int> path;
382 fillSinglePart(singlePart,mailDescription); 384 fillSinglePart(singlePart,mailDescription);
383 switch (mailDescription->bd_type) { 385 switch (mailDescription->bd_type) {
384 case MAILIMAP_BODY_TYPE_1PART_MSG: 386 case MAILIMAP_BODY_TYPE_1PART_MSG:
385 path.append(1); 387 path.append(1);
386 body_text = fetchPart(mail,path,true); 388 body_text = fetchPart(mail,path,true);
387 target_body.setBodytext(body_text); 389 target_body.setBodytext(body_text);
388 target_body.setDescription(singlePart); 390 target_body.setDescription(singlePart);
389 break; 391 break;
390 case MAILIMAP_BODY_TYPE_1PART_TEXT: 392 case MAILIMAP_BODY_TYPE_1PART_TEXT:
391 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); 393 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
392 path.append(1); 394 path.append(1);
393 body_text = fetchPart(mail,path,true); 395 body_text = fetchPart(mail,path,true);
394 target_body.setBodytext(body_text); 396 target_body.setBodytext(body_text);
395 target_body.setDescription(singlePart); 397 target_body.setDescription(singlePart);
396 break; 398 break;
397 case MAILIMAP_BODY_TYPE_1PART_BASIC: 399 case MAILIMAP_BODY_TYPE_1PART_BASIC:
398 qDebug("Single attachment"); 400 qDebug("Single attachment");
399 target_body.setBodytext(""); 401 target_body.setBodytext("");
400 target_body.addPart(singlePart); 402 target_body.addPart(singlePart);
401 break; 403 break;
402 default: 404 default:
403 break; 405 break;
404 } 406 }
405 407
406 return; 408 return;
407} 409}
408 410
409QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 411QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
410{ 412{
411 QStringList l; 413 QStringList l;
412 QString from; 414 QString from;
413 bool named_from; 415 bool named_from;
414 clistcell *current = NULL; 416 clistcell *current = NULL;
415 mailimap_address * current_address=NULL; 417 mailimap_address * current_address=NULL;
416 if (!list) { 418 if (!list) {
417 return l; 419 return l;
418 } 420 }
419 unsigned int count = 0; 421 unsigned int count = 0;
420 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 422 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
421 from = ""; 423 from = "";
422 named_from = false; 424 named_from = false;
423 current_address=(mailimap_address*)current->data; 425 current_address=(mailimap_address*)current->data;
424 if (current_address->ad_personal_name){ 426 if (current_address->ad_personal_name){
425 from+=QString(current_address->ad_personal_name); 427 from+=QString(current_address->ad_personal_name);
426 from+=" "; 428 from+=" ";
427 named_from = true; 429 named_from = true;
428 } 430 }
429 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 431 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
430 from+="<"; 432 from+="<";
431 } 433 }
432 if (current_address->ad_mailbox_name) { 434 if (current_address->ad_mailbox_name) {
433 from+=QString(current_address->ad_mailbox_name); 435 from+=QString(current_address->ad_mailbox_name);
434 from+="@"; 436 from+="@";
435 } 437 }
436 if (current_address->ad_host_name) { 438 if (current_address->ad_host_name) {
437 from+=QString(current_address->ad_host_name); 439 from+=QString(current_address->ad_host_name);
438 } 440 }
439 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 441 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
440 from+=">"; 442 from+=">";
441 } 443 }
442 l.append(QString(from)); 444 l.append(QString(from));
443 if (++count > 99) { 445 if (++count > 99) {
444 break; 446 break;
445 } 447 }
446 } 448 }
447 return l; 449 return l;
448} 450}
449 451
450QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 452QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
451{ 453{
452 QString body(""); 454 QString body("");
453 const char*mb; 455 const char*mb;
454 int err; 456 int err;
455 mailimap_fetch_type *fetchType; 457 mailimap_fetch_type *fetchType;
456 mailimap_set *set; 458 mailimap_set *set;
457 clistcell*current,*cur; 459 clistcell*current,*cur;
458 460
459 login(); 461 login();
460 if (!m_imap) { 462 if (!m_imap) {
461 return body; 463 return body;
462 } 464 }
463 if (!internal_call) { 465 if (!internal_call) {
464 mb = mail.getMbox().latin1(); 466 mb = mail.getMbox().latin1();
465 err = mailimap_select( m_imap, (char*)mb); 467 err = mailimap_select( m_imap, (char*)mb);
466 if ( err != MAILIMAP_NO_ERROR ) { 468 if ( err != MAILIMAP_NO_ERROR ) {
467 qDebug("error selecting mailbox: %s",m_imap->imap_response); 469 qDebug("error selecting mailbox: %s",m_imap->imap_response);
468 return body; 470 return body;
469 } 471 }
470 } 472 }
471 set = mailimap_set_new_single(mail.getNumber()); 473 set = mailimap_set_new_single(mail.getNumber());
472 clist*id_list=clist_new(); 474 clist*id_list=clist_new();
473 for (unsigned j=0; j < path.count();++j) { 475 for (unsigned j=0; j < path.count();++j) {
474 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 476 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
475 *p_id = path[j]; 477 *p_id = path[j];
476 clist_append(id_list,p_id); 478 clist_append(id_list,p_id);
477 } 479 }
478 mailimap_section_part * section_part = mailimap_section_part_new(id_list); 480 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
479 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 481 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
480 mailimap_section * section = mailimap_section_new(section_spec); 482 mailimap_section * section = mailimap_section_new(section_spec);
481 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); 483 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section);
482 484
483 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 485 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
484 486
485 clist*result = clist_new(); 487 clist*result = clist_new();
486 488
487 err = mailimap_fetch( m_imap, set, fetchType, &result ); 489 err = mailimap_fetch( m_imap, set, fetchType, &result );
488 mailimap_set_free( set ); 490 mailimap_set_free( set );
489 mailimap_fetch_type_free( fetchType ); 491 mailimap_fetch_type_free( fetchType );
490 492
491 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 493 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
492 mailimap_msg_att * msg_att; 494 mailimap_msg_att * msg_att;
493 msg_att = (mailimap_msg_att*)current->data; 495 msg_att = (mailimap_msg_att*)current->data;
494 mailimap_msg_att_item*msg_att_item; 496 mailimap_msg_att_item*msg_att_item;
@@ -529,202 +531,207 @@ void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mai
529 ++count; 531 ++count;
530 current_body = (mailimap_body*)current->data; 532 current_body = (mailimap_body*)current->data;
531 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 533 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
532 QValueList<int>clist = recList; 534 QValueList<int>clist = recList;
533 clist.append(count); 535 clist.append(count);
534 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); 536 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist);
535 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ 537 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
536 RecPart currentPart; 538 RecPart currentPart;
537 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); 539 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
538 QValueList<int>clist = recList; 540 QValueList<int>clist = recList;
539 clist.append(count); 541 clist.append(count);
540 /* important: Check for is NULL 'cause a body can be empty! */ 542 /* important: Check for is NULL 'cause a body can be empty! */
541 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { 543 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
542 QString body_text = fetchPart(mail,clist,true); 544 QString body_text = fetchPart(mail,clist,true);
543 target_body.setDescription(currentPart); 545 target_body.setDescription(currentPart);
544 target_body.setBodytext(body_text); 546 target_body.setBodytext(body_text);
545 } else { 547 } else {
546 QString id(""); 548 QString id("");
547 for (unsigned int j = 0; j < clist.count();++j) { 549 for (unsigned int j = 0; j < clist.count();++j) {
548 id+=(j>0?" ":""); 550 id+=(j>0?" ":"");
549 id+=QString("%1").arg(clist[j]); 551 id+=QString("%1").arg(clist[j]);
550 } 552 }
551 qDebug("ID= %s",id.latin1()); 553 qDebug("ID= %s",id.latin1());
552 currentPart.setIdentifier(id); 554 currentPart.setIdentifier(id);
553 currentPart.setPositionlist(clist); 555 currentPart.setPositionlist(clist);
554 target_body.addPart(currentPart); 556 target_body.addPart(currentPart);
555 } 557 }
556 } 558 }
557 } 559 }
558} 560}
559 561
560void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 562void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
561{ 563{
562 if (!Description) { 564 if (!Description) {
563 return; 565 return;
564 } 566 }
565 switch (Description->bd_type) { 567 switch (Description->bd_type) {
566 case MAILIMAP_BODY_TYPE_1PART_TEXT: 568 case MAILIMAP_BODY_TYPE_1PART_TEXT:
567 target_part.setType("text"); 569 target_part.setType("text");
568 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 570 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
569 break; 571 break;
570 case MAILIMAP_BODY_TYPE_1PART_BASIC: 572 case MAILIMAP_BODY_TYPE_1PART_BASIC:
571 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 573 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
572 break; 574 break;
573 case MAILIMAP_BODY_TYPE_1PART_MSG: 575 case MAILIMAP_BODY_TYPE_1PART_MSG:
574 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 576 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
575 break; 577 break;
576 default: 578 default:
577 break; 579 break;
578 } 580 }
579} 581}
580 582
581void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 583void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
582{ 584{
583 if (!which) { 585 if (!which) {
584 return; 586 return;
585 } 587 }
586 QString sub; 588 QString sub;
587 sub = which->bd_media_text; 589 sub = which->bd_media_text;
588 target_part.setSubtype(sub.lower()); 590 target_part.setSubtype(sub.lower());
589 target_part.setLines(which->bd_lines); 591 target_part.setLines(which->bd_lines);
590 fillBodyFields(target_part,which->bd_fields); 592 fillBodyFields(target_part,which->bd_fields);
591} 593}
592 594
593void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 595void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
594{ 596{
595 if (!which) { 597 if (!which) {
596 return; 598 return;
597 } 599 }
598// QString sub; 600// QString sub;
599// sub = which->bd_media_text; 601// sub = which->bd_media_text;
600// target_part.setSubtype(sub.lower()); 602// target_part.setSubtype(sub.lower());
601 qDebug("Message part"); 603 qDebug("Message part");
602 /* we set this type to text/plain */ 604 /* we set this type to text/plain */
603 target_part.setType("text"); 605 target_part.setType("text");
604 target_part.setSubtype("plain"); 606 target_part.setSubtype("plain");
605 target_part.setLines(which->bd_lines); 607 target_part.setLines(which->bd_lines);
606 fillBodyFields(target_part,which->bd_fields); 608 fillBodyFields(target_part,which->bd_fields);
607} 609}
608 610
609void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 611void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
610{ 612{
611 if (!which) { 613 if (!which) {
612 return; 614 return;
613 } 615 }
614 QString type,sub; 616 QString type,sub;
615 switch (which->bd_media_basic->med_type) { 617 switch (which->bd_media_basic->med_type) {
616 case MAILIMAP_MEDIA_BASIC_APPLICATION: 618 case MAILIMAP_MEDIA_BASIC_APPLICATION:
617 type = "application"; 619 type = "application";
618 break; 620 break;
619 case MAILIMAP_MEDIA_BASIC_AUDIO: 621 case MAILIMAP_MEDIA_BASIC_AUDIO:
620 type = "audio"; 622 type = "audio";
621 break; 623 break;
622 case MAILIMAP_MEDIA_BASIC_IMAGE: 624 case MAILIMAP_MEDIA_BASIC_IMAGE:
623 type = "image"; 625 type = "image";
624 break; 626 break;
625 case MAILIMAP_MEDIA_BASIC_MESSAGE: 627 case MAILIMAP_MEDIA_BASIC_MESSAGE:
626 type = "message"; 628 type = "message";
627 break; 629 break;
628 case MAILIMAP_MEDIA_BASIC_VIDEO: 630 case MAILIMAP_MEDIA_BASIC_VIDEO:
629 type = "video"; 631 type = "video";
630 break; 632 break;
631 case MAILIMAP_MEDIA_BASIC_OTHER: 633 case MAILIMAP_MEDIA_BASIC_OTHER:
632 default: 634 default:
633 if (which->bd_media_basic->med_basic_type) { 635 if (which->bd_media_basic->med_basic_type) {
634 type = which->bd_media_basic->med_basic_type; 636 type = which->bd_media_basic->med_basic_type;
635 } else { 637 } else {
636 type = ""; 638 type = "";
637 } 639 }
638 break; 640 break;
639 } 641 }
640 if (which->bd_media_basic->med_subtype) { 642 if (which->bd_media_basic->med_subtype) {
641 sub = which->bd_media_basic->med_subtype; 643 sub = which->bd_media_basic->med_subtype;
642 } else { 644 } else {
643 sub = ""; 645 sub = "";
644 } 646 }
645 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 647 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
646 target_part.setType(type.lower()); 648 target_part.setType(type.lower());
647 target_part.setSubtype(sub.lower()); 649 target_part.setSubtype(sub.lower());
648 fillBodyFields(target_part,which->bd_fields); 650 fillBodyFields(target_part,which->bd_fields);
649} 651}
650 652
651void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) 653void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
652{ 654{
653 if (!which) return; 655 if (!which) return;
654 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 656 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
655 clistcell*cur; 657 clistcell*cur;
656 mailimap_single_body_fld_param*param=0; 658 mailimap_single_body_fld_param*param=0;
657 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 659 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
658 param = (mailimap_single_body_fld_param*)cur->data; 660 param = (mailimap_single_body_fld_param*)cur->data;
659 if (param) { 661 if (param) {
660 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 662 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
661 } 663 }
662 } 664 }
663 } 665 }
664 mailimap_body_fld_enc*enc = which->bd_encoding; 666 mailimap_body_fld_enc*enc = which->bd_encoding;
665 QString encoding(""); 667 QString encoding("");
666 switch (enc->enc_type) { 668 switch (enc->enc_type) {
667 case MAILIMAP_BODY_FLD_ENC_7BIT: 669 case MAILIMAP_BODY_FLD_ENC_7BIT:
668 encoding = "7bit"; 670 encoding = "7bit";
669 break; 671 break;
670 case MAILIMAP_BODY_FLD_ENC_8BIT: 672 case MAILIMAP_BODY_FLD_ENC_8BIT:
671 encoding = "8bit"; 673 encoding = "8bit";
672 break; 674 break;
673 case MAILIMAP_BODY_FLD_ENC_BINARY: 675 case MAILIMAP_BODY_FLD_ENC_BINARY:
674 encoding="binary"; 676 encoding="binary";
675 break; 677 break;
676 case MAILIMAP_BODY_FLD_ENC_BASE64: 678 case MAILIMAP_BODY_FLD_ENC_BASE64:
677 encoding="base64"; 679 encoding="base64";
678 break; 680 break;
679 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 681 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
680 encoding="quoted-printable"; 682 encoding="quoted-printable";
681 break; 683 break;
682 case MAILIMAP_BODY_FLD_ENC_OTHER: 684 case MAILIMAP_BODY_FLD_ENC_OTHER:
683 default: 685 default:
684 if (enc->enc_value) { 686 if (enc->enc_value) {
685 char*t=enc->enc_value; 687 char*t=enc->enc_value;
686 encoding=QString(enc->enc_value); 688 encoding=QString(enc->enc_value);
687 enc->enc_value=0L; 689 enc->enc_value=0L;
688 free(t); 690 free(t);
689 } 691 }
690 } 692 }
691 target_part.setEncoding(encoding); 693 target_part.setEncoding(encoding);
692 target_part.setSize(which->bd_size); 694 target_part.setSize(which->bd_size);
693} 695}
694 696
695QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part) 697QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part)
696{ 698{
697 return fetchPart(mail,part.Positionlist(),false); 699 return fetchPart(mail,part.Positionlist(),false);
698} 700}
699 701
700void IMAPwrapper::deleteMail(const RecMail&mail) 702void IMAPwrapper::deleteMail(const RecMail&mail)
701{ 703{
702 mailimap_flag_list*flist; 704 mailimap_flag_list*flist;
703 mailimap_set *set; 705 mailimap_set *set;
704 mailimap_store_att_flags * store_flags; 706 mailimap_store_att_flags * store_flags;
705 int err; 707 int err;
706 login(); 708 login();
707 if (!m_imap) { 709 if (!m_imap) {
708 return; 710 return;
709 } 711 }
710 const char *mb = mail.getMbox().latin1(); 712 const char *mb = mail.getMbox().latin1();
711 err = mailimap_select( m_imap, (char*)mb); 713 err = mailimap_select( m_imap, (char*)mb);
712 if ( err != MAILIMAP_NO_ERROR ) { 714 if ( err != MAILIMAP_NO_ERROR ) {
713 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); 715 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response);
714 return; 716 return;
715 } 717 }
716 flist = mailimap_flag_list_new_empty(); 718 flist = mailimap_flag_list_new_empty();
717 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 719 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
718 store_flags = mailimap_store_att_flags_new_set_flags(flist); 720 store_flags = mailimap_store_att_flags_new_set_flags(flist);
719 set = mailimap_set_new_single(mail.getNumber()); 721 set = mailimap_set_new_single(mail.getNumber());
720 err = mailimap_store(m_imap,set,store_flags); 722 err = mailimap_store(m_imap,set,store_flags);
723 mailimap_set_free( set );
724 mailimap_store_att_flags_free(store_flags);
725
721 if (err != MAILIMAP_NO_ERROR) { 726 if (err != MAILIMAP_NO_ERROR) {
722 qDebug("error deleting mail: %s",m_imap->imap_response); 727 qDebug("error deleting mail: %s",m_imap->imap_response);
723 return; 728 return;
724 } 729 }
730 qDebug("deleting mail: %s",m_imap->imap_response);
731 /* should we realy do that at this moment? */
725 err = mailimap_expunge(m_imap); 732 err = mailimap_expunge(m_imap);
726 if (err != MAILIMAP_NO_ERROR) { 733 if (err != MAILIMAP_NO_ERROR) {
727 qDebug("error deleting mail: %s",m_imap->imap_response); 734 qDebug("error deleting mail: %s",m_imap->imap_response);
728 } 735 }
729 qDebug("Delete successfull"); 736 qDebug("Delete successfull %s",m_imap->imap_response);
730} 737}