author | harlekin <harlekin> | 2004-01-10 00:32:04 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2004-01-10 00:32:04 (UTC) |
commit | 76cf4990cb4171a747ac31e9832f4ee694ced2cc (patch) (unidiff) | |
tree | ce97c1b6b6e9f832cc09a71fe3e8e87551bb01bd /noncore/net/mail/libmailwrapper | |
parent | 241fb3509f6b62efda3c89f5bf9cec0dfba86b43 (diff) | |
download | opie-76cf4990cb4171a747ac31e9832f4ee694ced2cc.zip opie-76cf4990cb4171a747ac31e9832f4ee694ced2cc.tar.gz opie-76cf4990cb4171a747ac31e9832f4ee694ced2cc.tar.bz2 |
new connection setting stuff for imap too
Diffstat (limited to 'noncore/net/mail/libmailwrapper') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 36 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/settings.cpp | 2 |
2 files changed, 25 insertions, 13 deletions
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index 4b633ea..1c22c26 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -71,26 +71,36 @@ void IMAPwrapper::login() | |||
71 | } else { | 71 | } else { |
72 | // cancel | 72 | // cancel |
73 | qDebug( "IMAP: Login canceled" ); | 73 | qDebug( "IMAP: Login canceled" ); |
74 | return; | 74 | return; |
75 | } | 75 | } |
76 | } else { | 76 | } else { |
77 | user = account->getUser().latin1(); | 77 | user = account->getUser().latin1(); |
78 | pass = account->getPassword().latin1(); | 78 | pass = account->getPassword().latin1(); |
79 | } | 79 | } |
80 | 80 | ||
81 | m_imap = mailimap_new( 20, &imap_progress ); | 81 | m_imap = mailimap_new( 20, &imap_progress ); |
82 | 82 | ||
83 | |||
84 | |||
83 | /* connect */ | 85 | /* connect */ |
84 | if (account->getSSL()) { | 86 | |
87 | bool ssl = false; | ||
88 | |||
89 | if ( account->ConnectionType() == 2 ) { | ||
90 | ssl = true; | ||
91 | } | ||
92 | |||
93 | if ( ssl ) { | ||
94 | qDebug( "using ssl" ); | ||
85 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); | 95 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); |
86 | } else { | 96 | } else { |
87 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 97 | err = mailimap_socket_connect( m_imap, (char*)server, port ); |
88 | } | 98 | } |
89 | 99 | ||
90 | if ( err != MAILIMAP_NO_ERROR && | 100 | if ( err != MAILIMAP_NO_ERROR && |
91 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 101 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
92 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 102 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
93 | QString failure = ""; | 103 | QString failure = ""; |
94 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { | 104 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { |
95 | failure="Connection refused"; | 105 | failure="Connection refused"; |
96 | } else { | 106 | } else { |
@@ -360,25 +370,25 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | |||
360 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | 370 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); |
361 | if (addresslist.count()) { | 371 | if (addresslist.count()) { |
362 | m->setReplyto(addresslist.first()); | 372 | m->setReplyto(addresslist.first()); |
363 | } | 373 | } |
364 | } | 374 | } |
365 | m->setMsgid(QString(head->env_message_id)); | 375 | m->setMsgid(QString(head->env_message_id)); |
366 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 376 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
367 | #if 0 | 377 | #if 0 |
368 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | 378 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; |
369 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 379 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
370 | 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); | 380 | 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); |
371 | qDebug(da.toString()); | 381 | qDebug(da.toString()); |
372 | #endif | 382 | #endif |
373 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 383 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
374 | size = item->att_data.att_static->att_data.att_rfc822_size; | 384 | size = item->att_data.att_static->att_data.att_rfc822_size; |
375 | } | 385 | } |
376 | } | 386 | } |
377 | /* msg is already deleted */ | 387 | /* msg is already deleted */ |
378 | if (mFlags.testBit(FLAG_DELETED) && m) { | 388 | if (mFlags.testBit(FLAG_DELETED) && m) { |
379 | delete m; | 389 | delete m; |
380 | m = 0; | 390 | m = 0; |
381 | } | 391 | } |
382 | if (m) { | 392 | if (m) { |
383 | m->setFlags(mFlags); | 393 | m->setFlags(mFlags); |
384 | m->setMsgsize(size); | 394 | m->setMsgsize(size); |
@@ -399,25 +409,25 @@ RecBody IMAPwrapper::fetchBody(const RecMail&mail) | |||
399 | mailimap_body*body_desc = 0; | 409 | mailimap_body*body_desc = 0; |
400 | 410 | ||
401 | mb = mail.getMbox().latin1(); | 411 | mb = mail.getMbox().latin1(); |
402 | 412 | ||
403 | login(); | 413 | login(); |
404 | if (!m_imap) { | 414 | if (!m_imap) { |
405 | return body; | 415 | return body; |
406 | } | 416 | } |
407 | err = selectMbox(mail.getMbox()); | 417 | err = selectMbox(mail.getMbox()); |
408 | if ( err != MAILIMAP_NO_ERROR ) { | 418 | if ( err != MAILIMAP_NO_ERROR ) { |
409 | return body; | 419 | return body; |
410 | } | 420 | } |
411 | 421 | ||
412 | /* the range has to start at 1!!! not with 0!!!! */ | 422 | /* the range has to start at 1!!! not with 0!!!! */ |
413 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 423 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
414 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 424 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
415 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 425 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
416 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 426 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
417 | mailimap_set_free( set ); | 427 | mailimap_set_free( set ); |
418 | mailimap_fetch_type_free( fetchType ); | 428 | mailimap_fetch_type_free( fetchType ); |
419 | 429 | ||
420 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 430 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
421 | mailimap_msg_att * msg_att; | 431 | mailimap_msg_att * msg_att; |
422 | msg_att = (mailimap_msg_att*)current->data; | 432 | msg_att = (mailimap_msg_att*)current->data; |
423 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 433 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
@@ -486,65 +496,65 @@ encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int> | |||
486 | 496 | ||
487 | login(); | 497 | login(); |
488 | if (!m_imap) { | 498 | if (!m_imap) { |
489 | return res; | 499 | return res; |
490 | } | 500 | } |
491 | if (!internal_call) { | 501 | if (!internal_call) { |
492 | err = selectMbox(mail.getMbox()); | 502 | err = selectMbox(mail.getMbox()); |
493 | if ( err != MAILIMAP_NO_ERROR ) { | 503 | if ( err != MAILIMAP_NO_ERROR ) { |
494 | return res; | 504 | return res; |
495 | } | 505 | } |
496 | } | 506 | } |
497 | set = mailimap_set_new_single(mail.getNumber()); | 507 | set = mailimap_set_new_single(mail.getNumber()); |
498 | 508 | ||
499 | clist*id_list = 0; | 509 | clist*id_list = 0; |
500 | 510 | ||
501 | /* if path == empty then its a request for the whole rfc822 mail and generates | 511 | /* if path == empty then its a request for the whole rfc822 mail and generates |
502 | a "fetch <id> (body[])" statement on imap server */ | 512 | a "fetch <id> (body[])" statement on imap server */ |
503 | if (path.count()>0 ) { | 513 | if (path.count()>0 ) { |
504 | id_list = clist_new(); | 514 | id_list = clist_new(); |
505 | for (unsigned j=0; j < path.count();++j) { | 515 | for (unsigned j=0; j < path.count();++j) { |
506 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | 516 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); |
507 | *p_id = path[j]; | 517 | *p_id = path[j]; |
508 | clist_append(id_list,p_id); | 518 | clist_append(id_list,p_id); |
509 | } | 519 | } |
510 | section_part = mailimap_section_part_new(id_list); | 520 | section_part = mailimap_section_part_new(id_list); |
511 | section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 521 | section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
512 | } | 522 | } |
513 | 523 | ||
514 | section = mailimap_section_new(section_spec); | 524 | section = mailimap_section_new(section_spec); |
515 | fetch_att = mailimap_fetch_att_new_body_section(section); | 525 | fetch_att = mailimap_fetch_att_new_body_section(section); |
516 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 526 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
517 | 527 | ||
518 | clist*result = 0; | 528 | clist*result = 0; |
519 | 529 | ||
520 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 530 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
521 | mailimap_set_free( set ); | 531 | mailimap_set_free( set ); |
522 | mailimap_fetch_type_free( fetchType ); | 532 | mailimap_fetch_type_free( fetchType ); |
523 | 533 | ||
524 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 534 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
525 | mailimap_msg_att * msg_att; | 535 | mailimap_msg_att * msg_att; |
526 | msg_att = (mailimap_msg_att*)current->data; | 536 | msg_att = (mailimap_msg_att*)current->data; |
527 | mailimap_msg_att_item*msg_att_item; | 537 | mailimap_msg_att_item*msg_att_item; |
528 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 538 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
529 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 539 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
530 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 540 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
531 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 541 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
532 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 542 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
533 | /* detach - we take over the content */ | 543 | /* detach - we take over the content */ |
534 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 544 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
535 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); | 545 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); |
536 | } | 546 | } |
537 | } | 547 | } |
538 | } | 548 | } |
539 | } else { | 549 | } else { |
540 | qDebug("error fetching text: %s",m_imap->imap_response); | 550 | qDebug("error fetching text: %s",m_imap->imap_response); |
541 | } | 551 | } |
542 | if (result) mailimap_fetch_list_free(result); | 552 | if (result) mailimap_fetch_list_free(result); |
543 | return res; | 553 | return res; |
544 | } | 554 | } |
545 | 555 | ||
546 | /* current_recursion is for recursive calls. | 556 | /* current_recursion is for recursive calls. |
547 | current_count means the position inside the internal loop! */ | 557 | current_count means the position inside the internal loop! */ |
548 | void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body, | 558 | void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body, |
549 | int current_recursion,QValueList<int>recList,int current_count) | 559 | int current_recursion,QValueList<int>recList,int current_count) |
550 | { | 560 | { |
@@ -655,41 +665,41 @@ void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text | |||
655 | fillBodyFields(target_part,which->bd_fields); | 665 | fillBodyFields(target_part,which->bd_fields); |
656 | } | 666 | } |
657 | 667 | ||
658 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) | 668 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) |
659 | { | 669 | { |
660 | if (!which) { | 670 | if (!which) { |
661 | return; | 671 | return; |
662 | } | 672 | } |
663 | target_part.setSubtype("rfc822"); | 673 | target_part.setSubtype("rfc822"); |
664 | qDebug("Message part"); | 674 | qDebug("Message part"); |
665 | /* we set this type to text/plain */ | 675 | /* we set this type to text/plain */ |
666 | target_part.setLines(which->bd_lines); | 676 | target_part.setLines(which->bd_lines); |
667 | fillBodyFields(target_part,which->bd_fields); | 677 | fillBodyFields(target_part,which->bd_fields); |
668 | } | 678 | } |
669 | 679 | ||
670 | void IMAPwrapper::fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which) | 680 | void IMAPwrapper::fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which) |
671 | { | 681 | { |
672 | if (!which) return; | 682 | if (!which) return; |
673 | QString sub = which->bd_media_subtype; | 683 | QString sub = which->bd_media_subtype; |
674 | target_part.setSubtype(sub.lower()); | 684 | target_part.setSubtype(sub.lower()); |
675 | if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { | 685 | if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { |
676 | clistcell*cur = 0; | 686 | clistcell*cur = 0; |
677 | mailimap_single_body_fld_param*param=0; | 687 | mailimap_single_body_fld_param*param=0; |
678 | for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 688 | for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
679 | param = (mailimap_single_body_fld_param*)cur->data; | 689 | param = (mailimap_single_body_fld_param*)cur->data; |
680 | if (param) { | 690 | if (param) { |
681 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 691 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
682 | } | 692 | } |
683 | } | 693 | } |
684 | } | 694 | } |
685 | } | 695 | } |
686 | 696 | ||
687 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) | 697 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) |
688 | { | 698 | { |
689 | if (!which) { | 699 | if (!which) { |
690 | return; | 700 | return; |
691 | } | 701 | } |
692 | QString type,sub; | 702 | QString type,sub; |
693 | switch (which->bd_media_basic->med_type) { | 703 | switch (which->bd_media_basic->med_type) { |
694 | case MAILIMAP_MEDIA_BASIC_APPLICATION: | 704 | case MAILIMAP_MEDIA_BASIC_APPLICATION: |
695 | type = "application"; | 705 | type = "application"; |
diff --git a/noncore/net/mail/libmailwrapper/settings.cpp b/noncore/net/mail/libmailwrapper/settings.cpp index 7b6a58d..3279f39 100644 --- a/noncore/net/mail/libmailwrapper/settings.cpp +++ b/noncore/net/mail/libmailwrapper/settings.cpp | |||
@@ -155,46 +155,48 @@ QString IMAPaccount::getUniqueFileName() | |||
155 | } | 155 | } |
156 | 156 | ||
157 | void IMAPaccount::read() | 157 | void IMAPaccount::read() |
158 | { | 158 | { |
159 | Config *conf = new Config( getFileName(), Config::File ); | 159 | Config *conf = new Config( getFileName(), Config::File ); |
160 | conf->setGroup( "IMAP Account" ); | 160 | conf->setGroup( "IMAP Account" ); |
161 | accountName = conf->readEntry( "Account","" ); | 161 | accountName = conf->readEntry( "Account","" ); |
162 | if (accountName.isNull()) accountName = ""; | 162 | if (accountName.isNull()) accountName = ""; |
163 | server = conf->readEntry( "Server","" ); | 163 | server = conf->readEntry( "Server","" ); |
164 | if (server.isNull()) server=""; | 164 | if (server.isNull()) server=""; |
165 | port = conf->readEntry( "Port","" ); | 165 | port = conf->readEntry( "Port","" ); |
166 | if (port.isNull()) port="143"; | 166 | if (port.isNull()) port="143"; |
167 | connectionType = conf->readNumEntry( "ConnectionType" ); | ||
167 | ssl = conf->readBoolEntry( "SSL",false ); | 168 | ssl = conf->readBoolEntry( "SSL",false ); |
168 | user = conf->readEntry( "User","" ); | 169 | user = conf->readEntry( "User","" ); |
169 | if (user.isNull()) user = ""; | 170 | if (user.isNull()) user = ""; |
170 | password = conf->readEntryCrypt( "Password","" ); | 171 | password = conf->readEntryCrypt( "Password","" ); |
171 | if (password.isNull()) password = ""; | 172 | if (password.isNull()) password = ""; |
172 | prefix = conf->readEntry("MailPrefix",""); | 173 | prefix = conf->readEntry("MailPrefix",""); |
173 | if (prefix.isNull()) prefix = ""; | 174 | if (prefix.isNull()) prefix = ""; |
174 | offline = conf->readBoolEntry("Offline",false); | 175 | offline = conf->readBoolEntry("Offline",false); |
175 | delete conf; | 176 | delete conf; |
176 | } | 177 | } |
177 | 178 | ||
178 | void IMAPaccount::save() | 179 | void IMAPaccount::save() |
179 | { | 180 | { |
180 | qDebug( "saving " + getFileName() ); | 181 | qDebug( "saving " + getFileName() ); |
181 | Settings::checkDirectory(); | 182 | Settings::checkDirectory(); |
182 | 183 | ||
183 | Config *conf = new Config( getFileName(), Config::File ); | 184 | Config *conf = new Config( getFileName(), Config::File ); |
184 | conf->setGroup( "IMAP Account" ); | 185 | conf->setGroup( "IMAP Account" ); |
185 | conf->writeEntry( "Account", accountName ); | 186 | conf->writeEntry( "Account", accountName ); |
186 | conf->writeEntry( "Server", server ); | 187 | conf->writeEntry( "Server", server ); |
187 | conf->writeEntry( "Port", port ); | 188 | conf->writeEntry( "Port", port ); |
188 | conf->writeEntry( "SSL", ssl ); | 189 | conf->writeEntry( "SSL", ssl ); |
190 | conf->writeEntry( "ConnectionType", connectionType ); | ||
189 | conf->writeEntry( "User", user ); | 191 | conf->writeEntry( "User", user ); |
190 | conf->writeEntryCrypt( "Password", password ); | 192 | conf->writeEntryCrypt( "Password", password ); |
191 | conf->writeEntry( "MailPrefix",prefix); | 193 | conf->writeEntry( "MailPrefix",prefix); |
192 | conf->writeEntry( "Offline",offline); | 194 | conf->writeEntry( "Offline",offline); |
193 | conf->write(); | 195 | conf->write(); |
194 | delete conf; | 196 | delete conf; |
195 | } | 197 | } |
196 | 198 | ||
197 | 199 | ||
198 | QString IMAPaccount::getFileName() | 200 | QString IMAPaccount::getFileName() |
199 | { | 201 | { |
200 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/imap-" + file; | 202 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/imap-" + file; |