-rw-r--r-- | noncore/net/mail/imapwrapper.cpp | 23 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 23 |
2 files changed, 22 insertions, 24 deletions
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp index 30eb678..853e4a2 100644 --- a/noncore/net/mail/imapwrapper.cpp +++ b/noncore/net/mail/imapwrapper.cpp | |||
@@ -1,52 +1,52 @@ | |||
1 | 1 | ||
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | 3 | ||
4 | #include <libetpan/mailimap.h> | 4 | #include <libetpan/libetpan.h> |
5 | 5 | ||
6 | #include "imapwrapper.h" | 6 | #include "imapwrapper.h" |
7 | #include "mailtypes.h" | 7 | #include "mailtypes.h" |
8 | #include "logindialog.h" | 8 | #include "logindialog.h" |
9 | 9 | ||
10 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 10 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
11 | : AbstractMail() | 11 | : AbstractMail() |
12 | { | 12 | { |
13 | account = a; | 13 | account = a; |
14 | m_imap = 0; | 14 | m_imap = 0; |
15 | } | 15 | } |
16 | 16 | ||
17 | IMAPwrapper::~IMAPwrapper() | 17 | IMAPwrapper::~IMAPwrapper() |
18 | { | 18 | { |
19 | logout(); | 19 | logout(); |
20 | } | 20 | } |
21 | 21 | ||
22 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 22 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) |
23 | { | 23 | { |
24 | qDebug( "IMAP: %i of %i", current, maximum ); | 24 | qDebug( "IMAP: %i of %i", current, maximum ); |
25 | } | 25 | } |
26 | 26 | ||
27 | void IMAPwrapper::login() | 27 | void IMAPwrapper::login() |
28 | { | 28 | { |
29 | const char *server, *user, *pass; | 29 | const char *server, *user, *pass; |
30 | uint16_t port; | 30 | uint16_t port; |
31 | int err = MAILIMAP_NO_ERROR; | 31 | int err = MAILIMAP_NO_ERROR; |
32 | 32 | ||
33 | /* we are connected this moment */ | 33 | /* we are connected this moment */ |
34 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 34 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
35 | if (m_imap) { | 35 | if (m_imap) { |
36 | mailstream_flush(m_imap->imap_stream); | 36 | mailstream_flush(m_imap->imap_stream); |
37 | return; | 37 | return; |
38 | } | 38 | } |
39 | server = account->getServer().latin1(); | 39 | server = account->getServer().latin1(); |
40 | port = account->getPort().toUInt(); | 40 | port = account->getPort().toUInt(); |
41 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 41 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
42 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 42 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
43 | login.show(); | 43 | login.show(); |
44 | if ( QDialog::Accepted == login.exec() ) { | 44 | if ( QDialog::Accepted == login.exec() ) { |
45 | // ok | 45 | // ok |
46 | user = strdup( login.getUser().latin1() ); | 46 | user = strdup( login.getUser().latin1() ); |
47 | pass = strdup( login.getPassword().latin1() ); | 47 | pass = strdup( login.getPassword().latin1() ); |
48 | } else { | 48 | } else { |
49 | // cancel | 49 | // cancel |
50 | qDebug( "IMAP: Login canceled" ); | 50 | qDebug( "IMAP: Login canceled" ); |
51 | return; | 51 | return; |
52 | } | 52 | } |
@@ -277,98 +277,97 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | |||
277 | break; | 277 | break; |
278 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 278 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
279 | mFlags.setBit(FLAG_DRAFT); | 279 | mFlags.setBit(FLAG_DRAFT); |
280 | break; | 280 | break; |
281 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 281 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
282 | break; | 282 | break; |
283 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 283 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
284 | break; | 284 | break; |
285 | default: | 285 | default: |
286 | break; | 286 | break; |
287 | } | 287 | } |
288 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | 288 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { |
289 | mFlags.setBit(FLAG_RECENT); | 289 | mFlags.setBit(FLAG_RECENT); |
290 | } | 290 | } |
291 | } | 291 | } |
292 | continue; | 292 | continue; |
293 | } | 293 | } |
294 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { | 294 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { |
295 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; | 295 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; |
296 | m->setDate(head->env_date); | 296 | m->setDate(head->env_date); |
297 | m->setSubject(convert_String((const char*)head->env_subject)); | 297 | m->setSubject(convert_String((const char*)head->env_subject)); |
298 | //m->setSubject(head->env_subject); | 298 | //m->setSubject(head->env_subject); |
299 | if (head->env_from!=NULL) { | 299 | if (head->env_from!=NULL) { |
300 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | 300 | addresslist = address_list_to_stringlist(head->env_from->frm_list); |
301 | if (addresslist.count()) { | 301 | if (addresslist.count()) { |
302 | m->setFrom(addresslist.first()); | 302 | m->setFrom(addresslist.first()); |
303 | } | 303 | } |
304 | } | 304 | } |
305 | if (head->env_to!=NULL) { | 305 | if (head->env_to!=NULL) { |
306 | addresslist = address_list_to_stringlist(head->env_to->to_list); | 306 | addresslist = address_list_to_stringlist(head->env_to->to_list); |
307 | m->setTo(addresslist); | 307 | m->setTo(addresslist); |
308 | } | 308 | } |
309 | if (head->env_cc!=NULL) { | 309 | if (head->env_cc!=NULL) { |
310 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); | 310 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); |
311 | m->setCC(addresslist); | 311 | m->setCC(addresslist); |
312 | } | 312 | } |
313 | if (head->env_bcc!=NULL) { | 313 | if (head->env_bcc!=NULL) { |
314 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); | 314 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); |
315 | m->setBcc(addresslist); | 315 | m->setBcc(addresslist); |
316 | } | 316 | } |
317 | if (head->env_reply_to!=NULL) { | 317 | if (head->env_reply_to!=NULL) { |
318 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | 318 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); |
319 | if (addresslist.count()) { | 319 | if (addresslist.count()) { |
320 | m->setReplyto(addresslist.first()); | 320 | m->setReplyto(addresslist.first()); |
321 | } | 321 | } |
322 | } | 322 | } |
323 | m->setMsgid(QString(head->env_message_id)); | 323 | m->setMsgid(QString(head->env_message_id)); |
324 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 324 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
325 | #if 0 | 325 | #if 0 |
326 | |||
327 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | 326 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; |
328 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 327 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
329 | 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); | 328 | 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); |
330 | qDebug(da.toString()); | 329 | qDebug(da.toString()); |
331 | #endif | 330 | #endif |
332 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 331 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
333 | size = item->att_data.att_static->att_data.att_rfc822_size; | 332 | size = item->att_data.att_static->att_data.att_rfc822_size; |
334 | } | 333 | } |
335 | } | 334 | } |
336 | /* msg is already deleted */ | 335 | /* msg is already deleted */ |
337 | if (mFlags.testBit(FLAG_DELETED) && m) { | 336 | if (mFlags.testBit(FLAG_DELETED) && m) { |
338 | delete m; | 337 | delete m; |
339 | m = 0; | 338 | m = 0; |
340 | } | 339 | } |
341 | if (m) { | 340 | if (m) { |
342 | m->setFlags(mFlags); | 341 | m->setFlags(mFlags); |
343 | m->setMsgsize(size); | 342 | m->setMsgsize(size); |
344 | } | 343 | } |
345 | return m; | 344 | return m; |
346 | } | 345 | } |
347 | 346 | ||
348 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) | 347 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) |
349 | { | 348 | { |
350 | RecBody body; | 349 | RecBody body; |
351 | const char *mb; | 350 | const char *mb; |
352 | int err = MAILIMAP_NO_ERROR; | 351 | int err = MAILIMAP_NO_ERROR; |
353 | clist *result; | 352 | clist *result; |
354 | clistcell *current; | 353 | clistcell *current; |
355 | mailimap_fetch_att *fetchAtt; | 354 | mailimap_fetch_att *fetchAtt; |
356 | mailimap_fetch_type *fetchType; | 355 | mailimap_fetch_type *fetchType; |
357 | mailimap_set *set; | 356 | mailimap_set *set; |
358 | mailimap_body*body_desc; | 357 | mailimap_body*body_desc; |
359 | 358 | ||
360 | mb = mail.getMbox().latin1(); | 359 | mb = mail.getMbox().latin1(); |
361 | 360 | ||
362 | login(); | 361 | login(); |
363 | if (!m_imap) { | 362 | if (!m_imap) { |
364 | return body; | 363 | return body; |
365 | } | 364 | } |
366 | 365 | ||
367 | err = mailimap_select( m_imap, (char*)mb); | 366 | err = mailimap_select( m_imap, (char*)mb); |
368 | if ( err != MAILIMAP_NO_ERROR ) { | 367 | if ( err != MAILIMAP_NO_ERROR ) { |
369 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 368 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
370 | return body; | 369 | return body; |
371 | } | 370 | } |
372 | 371 | ||
373 | result = clist_new(); | 372 | result = clist_new(); |
374 | /* the range has to start at 1!!! not with 0!!!! */ | 373 | /* the range has to start at 1!!! not with 0!!!! */ |
@@ -509,118 +508,118 @@ encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int> | |||
509 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 508 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
510 | mailimap_section * section = mailimap_section_new(section_spec); | 509 | mailimap_section * section = mailimap_section_new(section_spec); |
511 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); | 510 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); |
512 | 511 | ||
513 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 512 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
514 | 513 | ||
515 | clist*result = clist_new(); | 514 | clist*result = clist_new(); |
516 | 515 | ||
517 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 516 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
518 | mailimap_set_free( set ); | 517 | mailimap_set_free( set ); |
519 | mailimap_fetch_type_free( fetchType ); | 518 | mailimap_fetch_type_free( fetchType ); |
520 | 519 | ||
521 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 520 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
522 | mailimap_msg_att * msg_att; | 521 | mailimap_msg_att * msg_att; |
523 | msg_att = (mailimap_msg_att*)current->data; | 522 | msg_att = (mailimap_msg_att*)current->data; |
524 | mailimap_msg_att_item*msg_att_item; | 523 | mailimap_msg_att_item*msg_att_item; |
525 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 524 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
526 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 525 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
527 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 526 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
528 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 527 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
529 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 528 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
530 | /* detach - we take over the content */ | 529 | /* detach - we take over the content */ |
531 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 530 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
532 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); | 531 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); |
533 | } | 532 | } |
534 | } | 533 | } |
535 | } | 534 | } |
536 | } else { | 535 | } else { |
537 | qDebug("error fetching text: %s",m_imap->imap_response); | 536 | qDebug("error fetching text: %s",m_imap->imap_response); |
538 | } | 537 | } |
539 | mailimap_fetch_list_free(result); | 538 | mailimap_fetch_list_free(result); |
540 | return res; | 539 | return res; |
541 | } | 540 | } |
542 | 541 | ||
543 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) | 542 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) |
544 | { | 543 | { |
545 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ | 544 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ |
546 | if (!mailDescription||current_recursion==10) { | 545 | if (!mailDescription||current_recursion==10) { |
547 | return; | 546 | return; |
548 | } | 547 | } |
549 | clistcell*current; | 548 | clistcell*current; |
550 | mailimap_body*current_body; | 549 | mailimap_body*current_body; |
551 | unsigned int count = 0; | 550 | unsigned int count = 0; |
552 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 551 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { |
553 | /* the point in the message */ | 552 | /* the point in the message */ |
554 | ++count; | 553 | ++count; |
555 | current_body = (mailimap_body*)current->data; | 554 | current_body = (mailimap_body*)current->data; |
556 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 555 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
557 | QValueList<int>clist = recList; | 556 | QValueList<int>countlist = recList; |
558 | clist.append(count); | 557 | countlist.append(count); |
559 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); | 558 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,countlist); |
560 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ | 559 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ |
561 | RecPart currentPart; | 560 | RecPart currentPart; |
562 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); | 561 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); |
563 | QValueList<int>clist = recList; | 562 | QValueList<int>countlist = recList; |
564 | clist.append(count); | 563 | countlist.append(count); |
565 | /* important: Check for is NULL 'cause a body can be empty! */ | 564 | /* important: Check for is NULL 'cause a body can be empty! */ |
566 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { | 565 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { |
567 | QString body_text = fetchTextPart(mail,clist,true,currentPart.Encoding()); | 566 | QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); |
568 | target_body.setDescription(currentPart); | 567 | target_body.setDescription(currentPart); |
569 | target_body.setBodytext(body_text); | 568 | target_body.setBodytext(body_text); |
570 | } else { | 569 | } else { |
571 | QString id(""); | 570 | QString id(""); |
572 | for (unsigned int j = 0; j < clist.count();++j) { | 571 | for (unsigned int j = 0; j < countlist.count();++j) { |
573 | id+=(j>0?" ":""); | 572 | id+=(j>0?" ":""); |
574 | id+=QString("%1").arg(clist[j]); | 573 | id+=QString("%1").arg(countlist[j]); |
575 | } | 574 | } |
576 | qDebug("ID= %s",id.latin1()); | 575 | qDebug("ID= %s",id.latin1()); |
577 | currentPart.setIdentifier(id); | 576 | currentPart.setIdentifier(id); |
578 | currentPart.setPositionlist(clist); | 577 | currentPart.setPositionlist(countlist); |
579 | target_body.addPart(currentPart); | 578 | target_body.addPart(currentPart); |
580 | } | 579 | } |
581 | } | 580 | } |
582 | } | 581 | } |
583 | } | 582 | } |
584 | 583 | ||
585 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) | 584 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) |
586 | { | 585 | { |
587 | if (!Description) { | 586 | if (!Description) { |
588 | return; | 587 | return; |
589 | } | 588 | } |
590 | switch (Description->bd_type) { | 589 | switch (Description->bd_type) { |
591 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 590 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
592 | target_part.setType("text"); | 591 | target_part.setType("text"); |
593 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); | 592 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); |
594 | break; | 593 | break; |
595 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 594 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
596 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); | 595 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); |
597 | break; | 596 | break; |
598 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 597 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
599 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); | 598 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); |
600 | break; | 599 | break; |
601 | default: | 600 | default: |
602 | break; | 601 | break; |
603 | } | 602 | } |
604 | } | 603 | } |
605 | 604 | ||
606 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) | 605 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) |
607 | { | 606 | { |
608 | if (!which) { | 607 | if (!which) { |
609 | return; | 608 | return; |
610 | } | 609 | } |
611 | QString sub; | 610 | QString sub; |
612 | sub = which->bd_media_text; | 611 | sub = which->bd_media_text; |
613 | target_part.setSubtype(sub.lower()); | 612 | target_part.setSubtype(sub.lower()); |
614 | target_part.setLines(which->bd_lines); | 613 | target_part.setLines(which->bd_lines); |
615 | fillBodyFields(target_part,which->bd_fields); | 614 | fillBodyFields(target_part,which->bd_fields); |
616 | } | 615 | } |
617 | 616 | ||
618 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) | 617 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) |
619 | { | 618 | { |
620 | if (!which) { | 619 | if (!which) { |
621 | return; | 620 | return; |
622 | } | 621 | } |
623 | // QString sub; | 622 | // QString sub; |
624 | // sub = which->bd_media_text; | 623 | // sub = which->bd_media_text; |
625 | // target_part.setSubtype(sub.lower()); | 624 | // target_part.setSubtype(sub.lower()); |
626 | qDebug("Message part"); | 625 | qDebug("Message part"); |
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index 30eb678..853e4a2 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -1,52 +1,52 @@ | |||
1 | 1 | ||
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | 3 | ||
4 | #include <libetpan/mailimap.h> | 4 | #include <libetpan/libetpan.h> |
5 | 5 | ||
6 | #include "imapwrapper.h" | 6 | #include "imapwrapper.h" |
7 | #include "mailtypes.h" | 7 | #include "mailtypes.h" |
8 | #include "logindialog.h" | 8 | #include "logindialog.h" |
9 | 9 | ||
10 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 10 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
11 | : AbstractMail() | 11 | : AbstractMail() |
12 | { | 12 | { |
13 | account = a; | 13 | account = a; |
14 | m_imap = 0; | 14 | m_imap = 0; |
15 | } | 15 | } |
16 | 16 | ||
17 | IMAPwrapper::~IMAPwrapper() | 17 | IMAPwrapper::~IMAPwrapper() |
18 | { | 18 | { |
19 | logout(); | 19 | logout(); |
20 | } | 20 | } |
21 | 21 | ||
22 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 22 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) |
23 | { | 23 | { |
24 | qDebug( "IMAP: %i of %i", current, maximum ); | 24 | qDebug( "IMAP: %i of %i", current, maximum ); |
25 | } | 25 | } |
26 | 26 | ||
27 | void IMAPwrapper::login() | 27 | void IMAPwrapper::login() |
28 | { | 28 | { |
29 | const char *server, *user, *pass; | 29 | const char *server, *user, *pass; |
30 | uint16_t port; | 30 | uint16_t port; |
31 | int err = MAILIMAP_NO_ERROR; | 31 | int err = MAILIMAP_NO_ERROR; |
32 | 32 | ||
33 | /* we are connected this moment */ | 33 | /* we are connected this moment */ |
34 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 34 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
35 | if (m_imap) { | 35 | if (m_imap) { |
36 | mailstream_flush(m_imap->imap_stream); | 36 | mailstream_flush(m_imap->imap_stream); |
37 | return; | 37 | return; |
38 | } | 38 | } |
39 | server = account->getServer().latin1(); | 39 | server = account->getServer().latin1(); |
40 | port = account->getPort().toUInt(); | 40 | port = account->getPort().toUInt(); |
41 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 41 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
42 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 42 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
43 | login.show(); | 43 | login.show(); |
44 | if ( QDialog::Accepted == login.exec() ) { | 44 | if ( QDialog::Accepted == login.exec() ) { |
45 | // ok | 45 | // ok |
46 | user = strdup( login.getUser().latin1() ); | 46 | user = strdup( login.getUser().latin1() ); |
47 | pass = strdup( login.getPassword().latin1() ); | 47 | pass = strdup( login.getPassword().latin1() ); |
48 | } else { | 48 | } else { |
49 | // cancel | 49 | // cancel |
50 | qDebug( "IMAP: Login canceled" ); | 50 | qDebug( "IMAP: Login canceled" ); |
51 | return; | 51 | return; |
52 | } | 52 | } |
@@ -277,98 +277,97 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | |||
277 | break; | 277 | break; |
278 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 278 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
279 | mFlags.setBit(FLAG_DRAFT); | 279 | mFlags.setBit(FLAG_DRAFT); |
280 | break; | 280 | break; |
281 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 281 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
282 | break; | 282 | break; |
283 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 283 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
284 | break; | 284 | break; |
285 | default: | 285 | default: |
286 | break; | 286 | break; |
287 | } | 287 | } |
288 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | 288 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { |
289 | mFlags.setBit(FLAG_RECENT); | 289 | mFlags.setBit(FLAG_RECENT); |
290 | } | 290 | } |
291 | } | 291 | } |
292 | continue; | 292 | continue; |
293 | } | 293 | } |
294 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { | 294 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { |
295 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; | 295 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; |
296 | m->setDate(head->env_date); | 296 | m->setDate(head->env_date); |
297 | m->setSubject(convert_String((const char*)head->env_subject)); | 297 | m->setSubject(convert_String((const char*)head->env_subject)); |
298 | //m->setSubject(head->env_subject); | 298 | //m->setSubject(head->env_subject); |
299 | if (head->env_from!=NULL) { | 299 | if (head->env_from!=NULL) { |
300 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | 300 | addresslist = address_list_to_stringlist(head->env_from->frm_list); |
301 | if (addresslist.count()) { | 301 | if (addresslist.count()) { |
302 | m->setFrom(addresslist.first()); | 302 | m->setFrom(addresslist.first()); |
303 | } | 303 | } |
304 | } | 304 | } |
305 | if (head->env_to!=NULL) { | 305 | if (head->env_to!=NULL) { |
306 | addresslist = address_list_to_stringlist(head->env_to->to_list); | 306 | addresslist = address_list_to_stringlist(head->env_to->to_list); |
307 | m->setTo(addresslist); | 307 | m->setTo(addresslist); |
308 | } | 308 | } |
309 | if (head->env_cc!=NULL) { | 309 | if (head->env_cc!=NULL) { |
310 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); | 310 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); |
311 | m->setCC(addresslist); | 311 | m->setCC(addresslist); |
312 | } | 312 | } |
313 | if (head->env_bcc!=NULL) { | 313 | if (head->env_bcc!=NULL) { |
314 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); | 314 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); |
315 | m->setBcc(addresslist); | 315 | m->setBcc(addresslist); |
316 | } | 316 | } |
317 | if (head->env_reply_to!=NULL) { | 317 | if (head->env_reply_to!=NULL) { |
318 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | 318 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); |
319 | if (addresslist.count()) { | 319 | if (addresslist.count()) { |
320 | m->setReplyto(addresslist.first()); | 320 | m->setReplyto(addresslist.first()); |
321 | } | 321 | } |
322 | } | 322 | } |
323 | m->setMsgid(QString(head->env_message_id)); | 323 | m->setMsgid(QString(head->env_message_id)); |
324 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 324 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
325 | #if 0 | 325 | #if 0 |
326 | |||
327 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | 326 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; |
328 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 327 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
329 | 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); | 328 | 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); |
330 | qDebug(da.toString()); | 329 | qDebug(da.toString()); |
331 | #endif | 330 | #endif |
332 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 331 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
333 | size = item->att_data.att_static->att_data.att_rfc822_size; | 332 | size = item->att_data.att_static->att_data.att_rfc822_size; |
334 | } | 333 | } |
335 | } | 334 | } |
336 | /* msg is already deleted */ | 335 | /* msg is already deleted */ |
337 | if (mFlags.testBit(FLAG_DELETED) && m) { | 336 | if (mFlags.testBit(FLAG_DELETED) && m) { |
338 | delete m; | 337 | delete m; |
339 | m = 0; | 338 | m = 0; |
340 | } | 339 | } |
341 | if (m) { | 340 | if (m) { |
342 | m->setFlags(mFlags); | 341 | m->setFlags(mFlags); |
343 | m->setMsgsize(size); | 342 | m->setMsgsize(size); |
344 | } | 343 | } |
345 | return m; | 344 | return m; |
346 | } | 345 | } |
347 | 346 | ||
348 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) | 347 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) |
349 | { | 348 | { |
350 | RecBody body; | 349 | RecBody body; |
351 | const char *mb; | 350 | const char *mb; |
352 | int err = MAILIMAP_NO_ERROR; | 351 | int err = MAILIMAP_NO_ERROR; |
353 | clist *result; | 352 | clist *result; |
354 | clistcell *current; | 353 | clistcell *current; |
355 | mailimap_fetch_att *fetchAtt; | 354 | mailimap_fetch_att *fetchAtt; |
356 | mailimap_fetch_type *fetchType; | 355 | mailimap_fetch_type *fetchType; |
357 | mailimap_set *set; | 356 | mailimap_set *set; |
358 | mailimap_body*body_desc; | 357 | mailimap_body*body_desc; |
359 | 358 | ||
360 | mb = mail.getMbox().latin1(); | 359 | mb = mail.getMbox().latin1(); |
361 | 360 | ||
362 | login(); | 361 | login(); |
363 | if (!m_imap) { | 362 | if (!m_imap) { |
364 | return body; | 363 | return body; |
365 | } | 364 | } |
366 | 365 | ||
367 | err = mailimap_select( m_imap, (char*)mb); | 366 | err = mailimap_select( m_imap, (char*)mb); |
368 | if ( err != MAILIMAP_NO_ERROR ) { | 367 | if ( err != MAILIMAP_NO_ERROR ) { |
369 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 368 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
370 | return body; | 369 | return body; |
371 | } | 370 | } |
372 | 371 | ||
373 | result = clist_new(); | 372 | result = clist_new(); |
374 | /* the range has to start at 1!!! not with 0!!!! */ | 373 | /* the range has to start at 1!!! not with 0!!!! */ |
@@ -509,118 +508,118 @@ encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int> | |||
509 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 508 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
510 | mailimap_section * section = mailimap_section_new(section_spec); | 509 | mailimap_section * section = mailimap_section_new(section_spec); |
511 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); | 510 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); |
512 | 511 | ||
513 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 512 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
514 | 513 | ||
515 | clist*result = clist_new(); | 514 | clist*result = clist_new(); |
516 | 515 | ||
517 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 516 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
518 | mailimap_set_free( set ); | 517 | mailimap_set_free( set ); |
519 | mailimap_fetch_type_free( fetchType ); | 518 | mailimap_fetch_type_free( fetchType ); |
520 | 519 | ||
521 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 520 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
522 | mailimap_msg_att * msg_att; | 521 | mailimap_msg_att * msg_att; |
523 | msg_att = (mailimap_msg_att*)current->data; | 522 | msg_att = (mailimap_msg_att*)current->data; |
524 | mailimap_msg_att_item*msg_att_item; | 523 | mailimap_msg_att_item*msg_att_item; |
525 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 524 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
526 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 525 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
527 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 526 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
528 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 527 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
529 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 528 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
530 | /* detach - we take over the content */ | 529 | /* detach - we take over the content */ |
531 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 530 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
532 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); | 531 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); |
533 | } | 532 | } |
534 | } | 533 | } |
535 | } | 534 | } |
536 | } else { | 535 | } else { |
537 | qDebug("error fetching text: %s",m_imap->imap_response); | 536 | qDebug("error fetching text: %s",m_imap->imap_response); |
538 | } | 537 | } |
539 | mailimap_fetch_list_free(result); | 538 | mailimap_fetch_list_free(result); |
540 | return res; | 539 | return res; |
541 | } | 540 | } |
542 | 541 | ||
543 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) | 542 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) |
544 | { | 543 | { |
545 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ | 544 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ |
546 | if (!mailDescription||current_recursion==10) { | 545 | if (!mailDescription||current_recursion==10) { |
547 | return; | 546 | return; |
548 | } | 547 | } |
549 | clistcell*current; | 548 | clistcell*current; |
550 | mailimap_body*current_body; | 549 | mailimap_body*current_body; |
551 | unsigned int count = 0; | 550 | unsigned int count = 0; |
552 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 551 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { |
553 | /* the point in the message */ | 552 | /* the point in the message */ |
554 | ++count; | 553 | ++count; |
555 | current_body = (mailimap_body*)current->data; | 554 | current_body = (mailimap_body*)current->data; |
556 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 555 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
557 | QValueList<int>clist = recList; | 556 | QValueList<int>countlist = recList; |
558 | clist.append(count); | 557 | countlist.append(count); |
559 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); | 558 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,countlist); |
560 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ | 559 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ |
561 | RecPart currentPart; | 560 | RecPart currentPart; |
562 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); | 561 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); |
563 | QValueList<int>clist = recList; | 562 | QValueList<int>countlist = recList; |
564 | clist.append(count); | 563 | countlist.append(count); |
565 | /* important: Check for is NULL 'cause a body can be empty! */ | 564 | /* important: Check for is NULL 'cause a body can be empty! */ |
566 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { | 565 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { |
567 | QString body_text = fetchTextPart(mail,clist,true,currentPart.Encoding()); | 566 | QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); |
568 | target_body.setDescription(currentPart); | 567 | target_body.setDescription(currentPart); |
569 | target_body.setBodytext(body_text); | 568 | target_body.setBodytext(body_text); |
570 | } else { | 569 | } else { |
571 | QString id(""); | 570 | QString id(""); |
572 | for (unsigned int j = 0; j < clist.count();++j) { | 571 | for (unsigned int j = 0; j < countlist.count();++j) { |
573 | id+=(j>0?" ":""); | 572 | id+=(j>0?" ":""); |
574 | id+=QString("%1").arg(clist[j]); | 573 | id+=QString("%1").arg(countlist[j]); |
575 | } | 574 | } |
576 | qDebug("ID= %s",id.latin1()); | 575 | qDebug("ID= %s",id.latin1()); |
577 | currentPart.setIdentifier(id); | 576 | currentPart.setIdentifier(id); |
578 | currentPart.setPositionlist(clist); | 577 | currentPart.setPositionlist(countlist); |
579 | target_body.addPart(currentPart); | 578 | target_body.addPart(currentPart); |
580 | } | 579 | } |
581 | } | 580 | } |
582 | } | 581 | } |
583 | } | 582 | } |
584 | 583 | ||
585 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) | 584 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) |
586 | { | 585 | { |
587 | if (!Description) { | 586 | if (!Description) { |
588 | return; | 587 | return; |
589 | } | 588 | } |
590 | switch (Description->bd_type) { | 589 | switch (Description->bd_type) { |
591 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 590 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
592 | target_part.setType("text"); | 591 | target_part.setType("text"); |
593 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); | 592 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); |
594 | break; | 593 | break; |
595 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 594 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
596 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); | 595 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); |
597 | break; | 596 | break; |
598 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 597 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
599 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); | 598 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); |
600 | break; | 599 | break; |
601 | default: | 600 | default: |
602 | break; | 601 | break; |
603 | } | 602 | } |
604 | } | 603 | } |
605 | 604 | ||
606 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) | 605 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) |
607 | { | 606 | { |
608 | if (!which) { | 607 | if (!which) { |
609 | return; | 608 | return; |
610 | } | 609 | } |
611 | QString sub; | 610 | QString sub; |
612 | sub = which->bd_media_text; | 611 | sub = which->bd_media_text; |
613 | target_part.setSubtype(sub.lower()); | 612 | target_part.setSubtype(sub.lower()); |
614 | target_part.setLines(which->bd_lines); | 613 | target_part.setLines(which->bd_lines); |
615 | fillBodyFields(target_part,which->bd_fields); | 614 | fillBodyFields(target_part,which->bd_fields); |
616 | } | 615 | } |
617 | 616 | ||
618 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) | 617 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) |
619 | { | 618 | { |
620 | if (!which) { | 619 | if (!which) { |
621 | return; | 620 | return; |
622 | } | 621 | } |
623 | // QString sub; | 622 | // QString sub; |
624 | // sub = which->bd_media_text; | 623 | // sub = which->bd_media_text; |
625 | // target_part.setSubtype(sub.lower()); | 624 | // target_part.setSubtype(sub.lower()); |
626 | qDebug("Message part"); | 625 | qDebug("Message part"); |