author | alwin <alwin> | 2003-12-13 02:36:57 (UTC) |
---|---|---|
committer | alwin <alwin> | 2003-12-13 02:36:57 (UTC) |
commit | a170120c655169de904ff282e23461ba4eef2b47 (patch) (unidiff) | |
tree | 0c7f7612fbe9610cf4bc23a5b9aba5f5591d7caf | |
parent | f689ef512cfc0a56fead4839a6b2e24a6ee282e0 (diff) | |
download | opie-a170120c655169de904ff282e23461ba4eef2b47.zip opie-a170120c655169de904ff282e23461ba4eef2b47.tar.gz opie-a170120c655169de904ff282e23461ba4eef2b47.tar.bz2 |
mails will marked as read now
-rw-r--r-- | noncore/net/mail/imapwrapper.cpp | 7 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 7 |
2 files changed, 6 insertions, 8 deletions
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp index 7b75ffa..3941cec 100644 --- a/noncore/net/mail/imapwrapper.cpp +++ b/noncore/net/mail/imapwrapper.cpp | |||
@@ -238,322 +238,321 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | |||
238 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 238 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
239 | mFlags.setBit(FLAG_ANSWERED); | 239 | mFlags.setBit(FLAG_ANSWERED); |
240 | break; | 240 | break; |
241 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 241 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
242 | mFlags.setBit(FLAG_FLAGGED); | 242 | mFlags.setBit(FLAG_FLAGGED); |
243 | break; | 243 | break; |
244 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 244 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
245 | mFlags.setBit(FLAG_DELETED); | 245 | mFlags.setBit(FLAG_DELETED); |
246 | break; | 246 | break; |
247 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 247 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
248 | mFlags.setBit(FLAG_SEEN); | 248 | mFlags.setBit(FLAG_SEEN); |
249 | break; | 249 | break; |
250 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 250 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
251 | mFlags.setBit(FLAG_DRAFT); | 251 | mFlags.setBit(FLAG_DRAFT); |
252 | break; | 252 | break; |
253 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 253 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
254 | break; | 254 | break; |
255 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 255 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
256 | break; | 256 | break; |
257 | default: | 257 | default: |
258 | break; | 258 | break; |
259 | } | 259 | } |
260 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | 260 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { |
261 | mFlags.setBit(FLAG_RECENT); | 261 | mFlags.setBit(FLAG_RECENT); |
262 | } | 262 | } |
263 | } | 263 | } |
264 | continue; | 264 | continue; |
265 | } | 265 | } |
266 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { | 266 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { |
267 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; | 267 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; |
268 | m->setDate(head->env_date); | 268 | m->setDate(head->env_date); |
269 | m->setSubject(head->env_subject); | 269 | m->setSubject(head->env_subject); |
270 | if (head->env_from!=NULL) { | 270 | if (head->env_from!=NULL) { |
271 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | 271 | addresslist = address_list_to_stringlist(head->env_from->frm_list); |
272 | if (addresslist.count()) { | 272 | if (addresslist.count()) { |
273 | m->setFrom(addresslist.first()); | 273 | m->setFrom(addresslist.first()); |
274 | } | 274 | } |
275 | } | 275 | } |
276 | if (head->env_to!=NULL) { | 276 | if (head->env_to!=NULL) { |
277 | addresslist = address_list_to_stringlist(head->env_to->to_list); | 277 | addresslist = address_list_to_stringlist(head->env_to->to_list); |
278 | m->setTo(addresslist); | 278 | m->setTo(addresslist); |
279 | } | 279 | } |
280 | if (head->env_cc!=NULL) { | 280 | if (head->env_cc!=NULL) { |
281 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); | 281 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); |
282 | m->setCC(addresslist); | 282 | m->setCC(addresslist); |
283 | } | 283 | } |
284 | if (head->env_bcc!=NULL) { | 284 | if (head->env_bcc!=NULL) { |
285 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); | 285 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); |
286 | m->setBcc(addresslist); | 286 | m->setBcc(addresslist); |
287 | } | 287 | } |
288 | if (head->env_reply_to!=NULL) { | 288 | if (head->env_reply_to!=NULL) { |
289 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | 289 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); |
290 | if (addresslist.count()) { | 290 | if (addresslist.count()) { |
291 | m->setReplyto(addresslist.first()); | 291 | m->setReplyto(addresslist.first()); |
292 | } | 292 | } |
293 | } | 293 | } |
294 | m->setMsgid(QString(head->env_message_id)); | 294 | m->setMsgid(QString(head->env_message_id)); |
295 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 295 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
296 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | 296 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; |
297 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 297 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
298 | 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); | 298 | 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); |
299 | qDebug(da.toString()); | 299 | qDebug(da.toString()); |
300 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 300 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
301 | size = item->att_data.att_static->att_data.att_rfc822_size; | 301 | size = item->att_data.att_static->att_data.att_rfc822_size; |
302 | } | 302 | } |
303 | } | 303 | } |
304 | /* msg is already deleted */ | 304 | /* msg is already deleted */ |
305 | if (mFlags.testBit(FLAG_DELETED) && m) { | 305 | if (mFlags.testBit(FLAG_DELETED) && m) { |
306 | delete m; | 306 | delete m; |
307 | m = 0; | 307 | m = 0; |
308 | } | 308 | } |
309 | if (m) { | 309 | if (m) { |
310 | m->setFlags(mFlags); | 310 | m->setFlags(mFlags); |
311 | m->setMsgsize(size); | 311 | m->setMsgsize(size); |
312 | } | 312 | } |
313 | return m; | 313 | return m; |
314 | } | 314 | } |
315 | 315 | ||
316 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) | 316 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) |
317 | { | 317 | { |
318 | RecBody body; | 318 | RecBody body; |
319 | const char *mb; | 319 | const char *mb; |
320 | int err = MAILIMAP_NO_ERROR; | 320 | int err = MAILIMAP_NO_ERROR; |
321 | clist *result; | 321 | clist *result; |
322 | clistcell *current; | 322 | clistcell *current; |
323 | mailimap_fetch_att *fetchAtt; | 323 | mailimap_fetch_att *fetchAtt; |
324 | mailimap_fetch_type *fetchType; | 324 | mailimap_fetch_type *fetchType; |
325 | mailimap_set *set; | 325 | mailimap_set *set; |
326 | mailimap_body*body_desc; | 326 | mailimap_body*body_desc; |
327 | 327 | ||
328 | mb = mail.getMbox().latin1(); | 328 | mb = mail.getMbox().latin1(); |
329 | 329 | ||
330 | login(); | 330 | login(); |
331 | if (!m_imap) { | 331 | if (!m_imap) { |
332 | return body; | 332 | return body; |
333 | } | 333 | } |
334 | /* select mailbox READONLY for operations */ | 334 | |
335 | err = mailimap_examine( m_imap, (char*)mb); | 335 | err = mailimap_select( m_imap, (char*)mb); |
336 | if ( err != MAILIMAP_NO_ERROR ) { | 336 | if ( err != MAILIMAP_NO_ERROR ) { |
337 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 337 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
338 | return body; | 338 | return body; |
339 | } | 339 | } |
340 | 340 | ||
341 | result = clist_new(); | 341 | result = clist_new(); |
342 | /* the range has to start at 1!!! not with 0!!!! */ | 342 | /* the range has to start at 1!!! not with 0!!!! */ |
343 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 343 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
344 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 344 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
345 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 345 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
346 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 346 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
347 | mailimap_set_free( set ); | 347 | mailimap_set_free( set ); |
348 | mailimap_fetch_type_free( fetchType ); | 348 | mailimap_fetch_type_free( fetchType ); |
349 | 349 | ||
350 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 350 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
351 | mailimap_msg_att * msg_att; | 351 | mailimap_msg_att * msg_att; |
352 | msg_att = (mailimap_msg_att*)current->data; | 352 | msg_att = (mailimap_msg_att*)current->data; |
353 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 353 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
354 | body_desc = item->att_data.att_static->att_data.att_body; | 354 | body_desc = item->att_data.att_static->att_data.att_body; |
355 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { | 355 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { |
356 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); | 356 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); |
357 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { | 357 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { |
358 | qDebug("Mulitpart mail"); | 358 | qDebug("Mulitpart mail"); |
359 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); | 359 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); |
360 | } | 360 | } |
361 | } else { | 361 | } else { |
362 | qDebug("error fetching body: %s",m_imap->imap_response); | 362 | qDebug("error fetching body: %s",m_imap->imap_response); |
363 | } | 363 | } |
364 | mailimap_fetch_list_free(result); | 364 | mailimap_fetch_list_free(result); |
365 | return body; | 365 | return body; |
366 | } | 366 | } |
367 | 367 | ||
368 | /* this routine is just called when the mail has only ONE part. | 368 | /* this routine is just called when the mail has only ONE part. |
369 | for filling the parts of a multi-part-message there are other | 369 | for filling the parts of a multi-part-message there are other |
370 | routines 'cause we can not simply fetch the whole body. */ | 370 | routines 'cause we can not simply fetch the whole body. */ |
371 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) | 371 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) |
372 | { | 372 | { |
373 | if (!mailDescription) { | 373 | if (!mailDescription) { |
374 | return; | 374 | return; |
375 | } | 375 | } |
376 | QString sub,body_text; | 376 | QString sub,body_text; |
377 | RecPart singlePart; | 377 | RecPart singlePart; |
378 | QValueList<int> path; | 378 | QValueList<int> path; |
379 | fillSinglePart(singlePart,mailDescription); | 379 | fillSinglePart(singlePart,mailDescription); |
380 | switch (mailDescription->bd_type) { | 380 | switch (mailDescription->bd_type) { |
381 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 381 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
382 | path.append(1); | 382 | path.append(1); |
383 | body_text = fetchPart(mail,path,true); | 383 | body_text = fetchPart(mail,path,true); |
384 | target_body.setBodytext(body_text); | 384 | target_body.setBodytext(body_text); |
385 | target_body.setDescription(singlePart); | 385 | target_body.setDescription(singlePart); |
386 | break; | 386 | break; |
387 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 387 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
388 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); | 388 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); |
389 | path.append(1); | 389 | path.append(1); |
390 | body_text = fetchPart(mail,path,true); | 390 | body_text = fetchPart(mail,path,true); |
391 | target_body.setBodytext(body_text); | 391 | target_body.setBodytext(body_text); |
392 | target_body.setDescription(singlePart); | 392 | target_body.setDescription(singlePart); |
393 | break; | 393 | break; |
394 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 394 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
395 | qDebug("Single attachment"); | 395 | qDebug("Single attachment"); |
396 | target_body.setBodytext(""); | 396 | target_body.setBodytext(""); |
397 | target_body.addPart(singlePart); | 397 | target_body.addPart(singlePart); |
398 | break; | 398 | break; |
399 | default: | 399 | default: |
400 | break; | 400 | break; |
401 | } | 401 | } |
402 | 402 | ||
403 | return; | 403 | return; |
404 | } | 404 | } |
405 | 405 | ||
406 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 406 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
407 | { | 407 | { |
408 | QStringList l; | 408 | QStringList l; |
409 | QString from; | 409 | QString from; |
410 | bool named_from; | 410 | bool named_from; |
411 | clistcell *current = NULL; | 411 | clistcell *current = NULL; |
412 | mailimap_address * current_address=NULL; | 412 | mailimap_address * current_address=NULL; |
413 | if (!list) { | 413 | if (!list) { |
414 | return l; | 414 | return l; |
415 | } | 415 | } |
416 | unsigned int count = 0; | 416 | unsigned int count = 0; |
417 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | 417 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
418 | from = ""; | 418 | from = ""; |
419 | named_from = false; | 419 | named_from = false; |
420 | current_address=(mailimap_address*)current->data; | 420 | current_address=(mailimap_address*)current->data; |
421 | if (current_address->ad_personal_name){ | 421 | if (current_address->ad_personal_name){ |
422 | from+=QString(current_address->ad_personal_name); | 422 | from+=QString(current_address->ad_personal_name); |
423 | from+=" "; | 423 | from+=" "; |
424 | named_from = true; | 424 | named_from = true; |
425 | } | 425 | } |
426 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 426 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
427 | from+="<"; | 427 | from+="<"; |
428 | } | 428 | } |
429 | if (current_address->ad_mailbox_name) { | 429 | if (current_address->ad_mailbox_name) { |
430 | from+=QString(current_address->ad_mailbox_name); | 430 | from+=QString(current_address->ad_mailbox_name); |
431 | from+="@"; | 431 | from+="@"; |
432 | } | 432 | } |
433 | if (current_address->ad_host_name) { | 433 | if (current_address->ad_host_name) { |
434 | from+=QString(current_address->ad_host_name); | 434 | from+=QString(current_address->ad_host_name); |
435 | } | 435 | } |
436 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 436 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
437 | from+=">"; | 437 | from+=">"; |
438 | } | 438 | } |
439 | l.append(QString(from)); | 439 | l.append(QString(from)); |
440 | if (++count > 99) { | 440 | if (++count > 99) { |
441 | break; | 441 | break; |
442 | } | 442 | } |
443 | } | 443 | } |
444 | return l; | 444 | return l; |
445 | } | 445 | } |
446 | 446 | ||
447 | QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) | 447 | QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) |
448 | { | 448 | { |
449 | QString body(""); | 449 | QString body(""); |
450 | const char*mb; | 450 | const char*mb; |
451 | int err; | 451 | int err; |
452 | mailimap_fetch_type *fetchType; | 452 | mailimap_fetch_type *fetchType; |
453 | mailimap_set *set; | 453 | mailimap_set *set; |
454 | clistcell*current,*cur; | 454 | clistcell*current,*cur; |
455 | 455 | ||
456 | login(); | 456 | login(); |
457 | if (!m_imap) { | 457 | if (!m_imap) { |
458 | return body; | 458 | return body; |
459 | } | 459 | } |
460 | if (!internal_call) { | 460 | if (!internal_call) { |
461 | mb = mail.getMbox().latin1(); | 461 | mb = mail.getMbox().latin1(); |
462 | /* select mailbox READONLY for operations */ | 462 | err = mailimap_select( m_imap, (char*)mb); |
463 | err = mailimap_examine( m_imap, (char*)mb); | ||
464 | if ( err != MAILIMAP_NO_ERROR ) { | 463 | if ( err != MAILIMAP_NO_ERROR ) { |
465 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 464 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
466 | return body; | 465 | return body; |
467 | } | 466 | } |
468 | } | 467 | } |
469 | set = mailimap_set_new_single(mail.getNumber()); | 468 | set = mailimap_set_new_single(mail.getNumber()); |
470 | clist*id_list=clist_new(); | 469 | clist*id_list=clist_new(); |
471 | for (unsigned j=0; j < path.count();++j) { | 470 | for (unsigned j=0; j < path.count();++j) { |
472 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | 471 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); |
473 | *p_id = path[j]; | 472 | *p_id = path[j]; |
474 | clist_append(id_list,p_id); | 473 | clist_append(id_list,p_id); |
475 | } | 474 | } |
476 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); | 475 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); |
477 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 476 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
478 | mailimap_section * section = mailimap_section_new(section_spec); | 477 | mailimap_section * section = mailimap_section_new(section_spec); |
479 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); | 478 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); |
480 | 479 | ||
481 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 480 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
482 | 481 | ||
483 | clist*result = clist_new(); | 482 | clist*result = clist_new(); |
484 | 483 | ||
485 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 484 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
486 | mailimap_set_free( set ); | 485 | mailimap_set_free( set ); |
487 | mailimap_fetch_type_free( fetchType ); | 486 | mailimap_fetch_type_free( fetchType ); |
488 | 487 | ||
489 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 488 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
490 | mailimap_msg_att * msg_att; | 489 | mailimap_msg_att * msg_att; |
491 | msg_att = (mailimap_msg_att*)current->data; | 490 | msg_att = (mailimap_msg_att*)current->data; |
492 | mailimap_msg_att_item*msg_att_item; | 491 | mailimap_msg_att_item*msg_att_item; |
493 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 492 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
494 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 493 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
495 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 494 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
496 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 495 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
497 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 496 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
498 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 497 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
499 | if (text) { | 498 | if (text) { |
500 | body = QString(text); | 499 | body = QString(text); |
501 | free(text); | 500 | free(text); |
502 | } else { | 501 | } else { |
503 | body = ""; | 502 | body = ""; |
504 | } | 503 | } |
505 | } | 504 | } |
506 | } | 505 | } |
507 | } | 506 | } |
508 | 507 | ||
509 | } else { | 508 | } else { |
510 | qDebug("error fetching text: %s",m_imap->imap_response); | 509 | qDebug("error fetching text: %s",m_imap->imap_response); |
511 | } | 510 | } |
512 | mailimap_fetch_list_free(result); | 511 | mailimap_fetch_list_free(result); |
513 | return body; | 512 | return body; |
514 | } | 513 | } |
515 | 514 | ||
516 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) | 515 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) |
517 | { | 516 | { |
518 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ | 517 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ |
519 | if (!mailDescription||current_recursion==10) { | 518 | if (!mailDescription||current_recursion==10) { |
520 | return; | 519 | return; |
521 | } | 520 | } |
522 | clistcell*current; | 521 | clistcell*current; |
523 | mailimap_body*current_body; | 522 | mailimap_body*current_body; |
524 | unsigned int count = 0; | 523 | unsigned int count = 0; |
525 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 524 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { |
526 | /* the point in the message */ | 525 | /* the point in the message */ |
527 | ++count; | 526 | ++count; |
528 | current_body = (mailimap_body*)current->data; | 527 | current_body = (mailimap_body*)current->data; |
529 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 528 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
530 | QValueList<int>clist = recList; | 529 | QValueList<int>clist = recList; |
531 | clist.append(count); | 530 | clist.append(count); |
532 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); | 531 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); |
533 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ | 532 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ |
534 | RecPart currentPart; | 533 | RecPart currentPart; |
535 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); | 534 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); |
536 | QValueList<int>clist = recList; | 535 | QValueList<int>clist = recList; |
537 | clist.append(count); | 536 | clist.append(count); |
538 | /* important: Check for is NULL 'cause a body can be empty! */ | 537 | /* important: Check for is NULL 'cause a body can be empty! */ |
539 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { | 538 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { |
540 | QString body_text = fetchPart(mail,clist,true); | 539 | QString body_text = fetchPart(mail,clist,true); |
541 | target_body.setDescription(currentPart); | 540 | target_body.setDescription(currentPart); |
542 | target_body.setBodytext(body_text); | 541 | target_body.setBodytext(body_text); |
543 | } else { | 542 | } else { |
544 | QString id(""); | 543 | QString id(""); |
545 | for (unsigned int j = 0; j < clist.count();++j) { | 544 | for (unsigned int j = 0; j < clist.count();++j) { |
546 | id+=(j>0?" ":""); | 545 | id+=(j>0?" ":""); |
547 | id+=QString("%1").arg(clist[j]); | 546 | id+=QString("%1").arg(clist[j]); |
548 | } | 547 | } |
549 | qDebug("ID= %s",id.latin1()); | 548 | qDebug("ID= %s",id.latin1()); |
550 | currentPart.setIdentifier(id); | 549 | currentPart.setIdentifier(id); |
551 | currentPart.setPositionlist(clist); | 550 | currentPart.setPositionlist(clist); |
552 | target_body.addPart(currentPart); | 551 | target_body.addPart(currentPart); |
553 | } | 552 | } |
554 | } | 553 | } |
555 | } | 554 | } |
556 | } | 555 | } |
557 | 556 | ||
558 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) | 557 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) |
559 | { | 558 | { |
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index 7b75ffa..3941cec 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -238,322 +238,321 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | |||
238 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 238 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
239 | mFlags.setBit(FLAG_ANSWERED); | 239 | mFlags.setBit(FLAG_ANSWERED); |
240 | break; | 240 | break; |
241 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 241 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
242 | mFlags.setBit(FLAG_FLAGGED); | 242 | mFlags.setBit(FLAG_FLAGGED); |
243 | break; | 243 | break; |
244 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 244 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
245 | mFlags.setBit(FLAG_DELETED); | 245 | mFlags.setBit(FLAG_DELETED); |
246 | break; | 246 | break; |
247 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 247 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
248 | mFlags.setBit(FLAG_SEEN); | 248 | mFlags.setBit(FLAG_SEEN); |
249 | break; | 249 | break; |
250 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 250 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
251 | mFlags.setBit(FLAG_DRAFT); | 251 | mFlags.setBit(FLAG_DRAFT); |
252 | break; | 252 | break; |
253 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 253 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
254 | break; | 254 | break; |
255 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 255 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
256 | break; | 256 | break; |
257 | default: | 257 | default: |
258 | break; | 258 | break; |
259 | } | 259 | } |
260 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | 260 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { |
261 | mFlags.setBit(FLAG_RECENT); | 261 | mFlags.setBit(FLAG_RECENT); |
262 | } | 262 | } |
263 | } | 263 | } |
264 | continue; | 264 | continue; |
265 | } | 265 | } |
266 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { | 266 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { |
267 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; | 267 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; |
268 | m->setDate(head->env_date); | 268 | m->setDate(head->env_date); |
269 | m->setSubject(head->env_subject); | 269 | m->setSubject(head->env_subject); |
270 | if (head->env_from!=NULL) { | 270 | if (head->env_from!=NULL) { |
271 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | 271 | addresslist = address_list_to_stringlist(head->env_from->frm_list); |
272 | if (addresslist.count()) { | 272 | if (addresslist.count()) { |
273 | m->setFrom(addresslist.first()); | 273 | m->setFrom(addresslist.first()); |
274 | } | 274 | } |
275 | } | 275 | } |
276 | if (head->env_to!=NULL) { | 276 | if (head->env_to!=NULL) { |
277 | addresslist = address_list_to_stringlist(head->env_to->to_list); | 277 | addresslist = address_list_to_stringlist(head->env_to->to_list); |
278 | m->setTo(addresslist); | 278 | m->setTo(addresslist); |
279 | } | 279 | } |
280 | if (head->env_cc!=NULL) { | 280 | if (head->env_cc!=NULL) { |
281 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); | 281 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); |
282 | m->setCC(addresslist); | 282 | m->setCC(addresslist); |
283 | } | 283 | } |
284 | if (head->env_bcc!=NULL) { | 284 | if (head->env_bcc!=NULL) { |
285 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); | 285 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); |
286 | m->setBcc(addresslist); | 286 | m->setBcc(addresslist); |
287 | } | 287 | } |
288 | if (head->env_reply_to!=NULL) { | 288 | if (head->env_reply_to!=NULL) { |
289 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | 289 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); |
290 | if (addresslist.count()) { | 290 | if (addresslist.count()) { |
291 | m->setReplyto(addresslist.first()); | 291 | m->setReplyto(addresslist.first()); |
292 | } | 292 | } |
293 | } | 293 | } |
294 | m->setMsgid(QString(head->env_message_id)); | 294 | m->setMsgid(QString(head->env_message_id)); |
295 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 295 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
296 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | 296 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; |
297 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 297 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
298 | 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); | 298 | 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); |
299 | qDebug(da.toString()); | 299 | qDebug(da.toString()); |
300 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 300 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
301 | size = item->att_data.att_static->att_data.att_rfc822_size; | 301 | size = item->att_data.att_static->att_data.att_rfc822_size; |
302 | } | 302 | } |
303 | } | 303 | } |
304 | /* msg is already deleted */ | 304 | /* msg is already deleted */ |
305 | if (mFlags.testBit(FLAG_DELETED) && m) { | 305 | if (mFlags.testBit(FLAG_DELETED) && m) { |
306 | delete m; | 306 | delete m; |
307 | m = 0; | 307 | m = 0; |
308 | } | 308 | } |
309 | if (m) { | 309 | if (m) { |
310 | m->setFlags(mFlags); | 310 | m->setFlags(mFlags); |
311 | m->setMsgsize(size); | 311 | m->setMsgsize(size); |
312 | } | 312 | } |
313 | return m; | 313 | return m; |
314 | } | 314 | } |
315 | 315 | ||
316 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) | 316 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) |
317 | { | 317 | { |
318 | RecBody body; | 318 | RecBody body; |
319 | const char *mb; | 319 | const char *mb; |
320 | int err = MAILIMAP_NO_ERROR; | 320 | int err = MAILIMAP_NO_ERROR; |
321 | clist *result; | 321 | clist *result; |
322 | clistcell *current; | 322 | clistcell *current; |
323 | mailimap_fetch_att *fetchAtt; | 323 | mailimap_fetch_att *fetchAtt; |
324 | mailimap_fetch_type *fetchType; | 324 | mailimap_fetch_type *fetchType; |
325 | mailimap_set *set; | 325 | mailimap_set *set; |
326 | mailimap_body*body_desc; | 326 | mailimap_body*body_desc; |
327 | 327 | ||
328 | mb = mail.getMbox().latin1(); | 328 | mb = mail.getMbox().latin1(); |
329 | 329 | ||
330 | login(); | 330 | login(); |
331 | if (!m_imap) { | 331 | if (!m_imap) { |
332 | return body; | 332 | return body; |
333 | } | 333 | } |
334 | /* select mailbox READONLY for operations */ | 334 | |
335 | err = mailimap_examine( m_imap, (char*)mb); | 335 | err = mailimap_select( m_imap, (char*)mb); |
336 | if ( err != MAILIMAP_NO_ERROR ) { | 336 | if ( err != MAILIMAP_NO_ERROR ) { |
337 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 337 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
338 | return body; | 338 | return body; |
339 | } | 339 | } |
340 | 340 | ||
341 | result = clist_new(); | 341 | result = clist_new(); |
342 | /* the range has to start at 1!!! not with 0!!!! */ | 342 | /* the range has to start at 1!!! not with 0!!!! */ |
343 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 343 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
344 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 344 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
345 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 345 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
346 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 346 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
347 | mailimap_set_free( set ); | 347 | mailimap_set_free( set ); |
348 | mailimap_fetch_type_free( fetchType ); | 348 | mailimap_fetch_type_free( fetchType ); |
349 | 349 | ||
350 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 350 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
351 | mailimap_msg_att * msg_att; | 351 | mailimap_msg_att * msg_att; |
352 | msg_att = (mailimap_msg_att*)current->data; | 352 | msg_att = (mailimap_msg_att*)current->data; |
353 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 353 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
354 | body_desc = item->att_data.att_static->att_data.att_body; | 354 | body_desc = item->att_data.att_static->att_data.att_body; |
355 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { | 355 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { |
356 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); | 356 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); |
357 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { | 357 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { |
358 | qDebug("Mulitpart mail"); | 358 | qDebug("Mulitpart mail"); |
359 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); | 359 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); |
360 | } | 360 | } |
361 | } else { | 361 | } else { |
362 | qDebug("error fetching body: %s",m_imap->imap_response); | 362 | qDebug("error fetching body: %s",m_imap->imap_response); |
363 | } | 363 | } |
364 | mailimap_fetch_list_free(result); | 364 | mailimap_fetch_list_free(result); |
365 | return body; | 365 | return body; |
366 | } | 366 | } |
367 | 367 | ||
368 | /* this routine is just called when the mail has only ONE part. | 368 | /* this routine is just called when the mail has only ONE part. |
369 | for filling the parts of a multi-part-message there are other | 369 | for filling the parts of a multi-part-message there are other |
370 | routines 'cause we can not simply fetch the whole body. */ | 370 | routines 'cause we can not simply fetch the whole body. */ |
371 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) | 371 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) |
372 | { | 372 | { |
373 | if (!mailDescription) { | 373 | if (!mailDescription) { |
374 | return; | 374 | return; |
375 | } | 375 | } |
376 | QString sub,body_text; | 376 | QString sub,body_text; |
377 | RecPart singlePart; | 377 | RecPart singlePart; |
378 | QValueList<int> path; | 378 | QValueList<int> path; |
379 | fillSinglePart(singlePart,mailDescription); | 379 | fillSinglePart(singlePart,mailDescription); |
380 | switch (mailDescription->bd_type) { | 380 | switch (mailDescription->bd_type) { |
381 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 381 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
382 | path.append(1); | 382 | path.append(1); |
383 | body_text = fetchPart(mail,path,true); | 383 | body_text = fetchPart(mail,path,true); |
384 | target_body.setBodytext(body_text); | 384 | target_body.setBodytext(body_text); |
385 | target_body.setDescription(singlePart); | 385 | target_body.setDescription(singlePart); |
386 | break; | 386 | break; |
387 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 387 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
388 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); | 388 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); |
389 | path.append(1); | 389 | path.append(1); |
390 | body_text = fetchPart(mail,path,true); | 390 | body_text = fetchPart(mail,path,true); |
391 | target_body.setBodytext(body_text); | 391 | target_body.setBodytext(body_text); |
392 | target_body.setDescription(singlePart); | 392 | target_body.setDescription(singlePart); |
393 | break; | 393 | break; |
394 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 394 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
395 | qDebug("Single attachment"); | 395 | qDebug("Single attachment"); |
396 | target_body.setBodytext(""); | 396 | target_body.setBodytext(""); |
397 | target_body.addPart(singlePart); | 397 | target_body.addPart(singlePart); |
398 | break; | 398 | break; |
399 | default: | 399 | default: |
400 | break; | 400 | break; |
401 | } | 401 | } |
402 | 402 | ||
403 | return; | 403 | return; |
404 | } | 404 | } |
405 | 405 | ||
406 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 406 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
407 | { | 407 | { |
408 | QStringList l; | 408 | QStringList l; |
409 | QString from; | 409 | QString from; |
410 | bool named_from; | 410 | bool named_from; |
411 | clistcell *current = NULL; | 411 | clistcell *current = NULL; |
412 | mailimap_address * current_address=NULL; | 412 | mailimap_address * current_address=NULL; |
413 | if (!list) { | 413 | if (!list) { |
414 | return l; | 414 | return l; |
415 | } | 415 | } |
416 | unsigned int count = 0; | 416 | unsigned int count = 0; |
417 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | 417 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
418 | from = ""; | 418 | from = ""; |
419 | named_from = false; | 419 | named_from = false; |
420 | current_address=(mailimap_address*)current->data; | 420 | current_address=(mailimap_address*)current->data; |
421 | if (current_address->ad_personal_name){ | 421 | if (current_address->ad_personal_name){ |
422 | from+=QString(current_address->ad_personal_name); | 422 | from+=QString(current_address->ad_personal_name); |
423 | from+=" "; | 423 | from+=" "; |
424 | named_from = true; | 424 | named_from = true; |
425 | } | 425 | } |
426 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 426 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
427 | from+="<"; | 427 | from+="<"; |
428 | } | 428 | } |
429 | if (current_address->ad_mailbox_name) { | 429 | if (current_address->ad_mailbox_name) { |
430 | from+=QString(current_address->ad_mailbox_name); | 430 | from+=QString(current_address->ad_mailbox_name); |
431 | from+="@"; | 431 | from+="@"; |
432 | } | 432 | } |
433 | if (current_address->ad_host_name) { | 433 | if (current_address->ad_host_name) { |
434 | from+=QString(current_address->ad_host_name); | 434 | from+=QString(current_address->ad_host_name); |
435 | } | 435 | } |
436 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 436 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
437 | from+=">"; | 437 | from+=">"; |
438 | } | 438 | } |
439 | l.append(QString(from)); | 439 | l.append(QString(from)); |
440 | if (++count > 99) { | 440 | if (++count > 99) { |
441 | break; | 441 | break; |
442 | } | 442 | } |
443 | } | 443 | } |
444 | return l; | 444 | return l; |
445 | } | 445 | } |
446 | 446 | ||
447 | QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) | 447 | QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) |
448 | { | 448 | { |
449 | QString body(""); | 449 | QString body(""); |
450 | const char*mb; | 450 | const char*mb; |
451 | int err; | 451 | int err; |
452 | mailimap_fetch_type *fetchType; | 452 | mailimap_fetch_type *fetchType; |
453 | mailimap_set *set; | 453 | mailimap_set *set; |
454 | clistcell*current,*cur; | 454 | clistcell*current,*cur; |
455 | 455 | ||
456 | login(); | 456 | login(); |
457 | if (!m_imap) { | 457 | if (!m_imap) { |
458 | return body; | 458 | return body; |
459 | } | 459 | } |
460 | if (!internal_call) { | 460 | if (!internal_call) { |
461 | mb = mail.getMbox().latin1(); | 461 | mb = mail.getMbox().latin1(); |
462 | /* select mailbox READONLY for operations */ | 462 | err = mailimap_select( m_imap, (char*)mb); |
463 | err = mailimap_examine( m_imap, (char*)mb); | ||
464 | if ( err != MAILIMAP_NO_ERROR ) { | 463 | if ( err != MAILIMAP_NO_ERROR ) { |
465 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 464 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
466 | return body; | 465 | return body; |
467 | } | 466 | } |
468 | } | 467 | } |
469 | set = mailimap_set_new_single(mail.getNumber()); | 468 | set = mailimap_set_new_single(mail.getNumber()); |
470 | clist*id_list=clist_new(); | 469 | clist*id_list=clist_new(); |
471 | for (unsigned j=0; j < path.count();++j) { | 470 | for (unsigned j=0; j < path.count();++j) { |
472 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | 471 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); |
473 | *p_id = path[j]; | 472 | *p_id = path[j]; |
474 | clist_append(id_list,p_id); | 473 | clist_append(id_list,p_id); |
475 | } | 474 | } |
476 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); | 475 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); |
477 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 476 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
478 | mailimap_section * section = mailimap_section_new(section_spec); | 477 | mailimap_section * section = mailimap_section_new(section_spec); |
479 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); | 478 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); |
480 | 479 | ||
481 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 480 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
482 | 481 | ||
483 | clist*result = clist_new(); | 482 | clist*result = clist_new(); |
484 | 483 | ||
485 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 484 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
486 | mailimap_set_free( set ); | 485 | mailimap_set_free( set ); |
487 | mailimap_fetch_type_free( fetchType ); | 486 | mailimap_fetch_type_free( fetchType ); |
488 | 487 | ||
489 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 488 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
490 | mailimap_msg_att * msg_att; | 489 | mailimap_msg_att * msg_att; |
491 | msg_att = (mailimap_msg_att*)current->data; | 490 | msg_att = (mailimap_msg_att*)current->data; |
492 | mailimap_msg_att_item*msg_att_item; | 491 | mailimap_msg_att_item*msg_att_item; |
493 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 492 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
494 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 493 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
495 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 494 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
496 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 495 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
497 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 496 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
498 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 497 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
499 | if (text) { | 498 | if (text) { |
500 | body = QString(text); | 499 | body = QString(text); |
501 | free(text); | 500 | free(text); |
502 | } else { | 501 | } else { |
503 | body = ""; | 502 | body = ""; |
504 | } | 503 | } |
505 | } | 504 | } |
506 | } | 505 | } |
507 | } | 506 | } |
508 | 507 | ||
509 | } else { | 508 | } else { |
510 | qDebug("error fetching text: %s",m_imap->imap_response); | 509 | qDebug("error fetching text: %s",m_imap->imap_response); |
511 | } | 510 | } |
512 | mailimap_fetch_list_free(result); | 511 | mailimap_fetch_list_free(result); |
513 | return body; | 512 | return body; |
514 | } | 513 | } |
515 | 514 | ||
516 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) | 515 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) |
517 | { | 516 | { |
518 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ | 517 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ |
519 | if (!mailDescription||current_recursion==10) { | 518 | if (!mailDescription||current_recursion==10) { |
520 | return; | 519 | return; |
521 | } | 520 | } |
522 | clistcell*current; | 521 | clistcell*current; |
523 | mailimap_body*current_body; | 522 | mailimap_body*current_body; |
524 | unsigned int count = 0; | 523 | unsigned int count = 0; |
525 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 524 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { |
526 | /* the point in the message */ | 525 | /* the point in the message */ |
527 | ++count; | 526 | ++count; |
528 | current_body = (mailimap_body*)current->data; | 527 | current_body = (mailimap_body*)current->data; |
529 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 528 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
530 | QValueList<int>clist = recList; | 529 | QValueList<int>clist = recList; |
531 | clist.append(count); | 530 | clist.append(count); |
532 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); | 531 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); |
533 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ | 532 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ |
534 | RecPart currentPart; | 533 | RecPart currentPart; |
535 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); | 534 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); |
536 | QValueList<int>clist = recList; | 535 | QValueList<int>clist = recList; |
537 | clist.append(count); | 536 | clist.append(count); |
538 | /* important: Check for is NULL 'cause a body can be empty! */ | 537 | /* important: Check for is NULL 'cause a body can be empty! */ |
539 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { | 538 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { |
540 | QString body_text = fetchPart(mail,clist,true); | 539 | QString body_text = fetchPart(mail,clist,true); |
541 | target_body.setDescription(currentPart); | 540 | target_body.setDescription(currentPart); |
542 | target_body.setBodytext(body_text); | 541 | target_body.setBodytext(body_text); |
543 | } else { | 542 | } else { |
544 | QString id(""); | 543 | QString id(""); |
545 | for (unsigned int j = 0; j < clist.count();++j) { | 544 | for (unsigned int j = 0; j < clist.count();++j) { |
546 | id+=(j>0?" ":""); | 545 | id+=(j>0?" ":""); |
547 | id+=QString("%1").arg(clist[j]); | 546 | id+=QString("%1").arg(clist[j]); |
548 | } | 547 | } |
549 | qDebug("ID= %s",id.latin1()); | 548 | qDebug("ID= %s",id.latin1()); |
550 | currentPart.setIdentifier(id); | 549 | currentPart.setIdentifier(id); |
551 | currentPart.setPositionlist(clist); | 550 | currentPart.setPositionlist(clist); |
552 | target_body.addPart(currentPart); | 551 | target_body.addPart(currentPart); |
553 | } | 552 | } |
554 | } | 553 | } |
555 | } | 554 | } |
556 | } | 555 | } |
557 | 556 | ||
558 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) | 557 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) |
559 | { | 558 | { |