Diffstat (limited to 'noncore/net/mail/smtpwrapper.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/mail/smtpwrapper.cpp | 59 |
1 files changed, 50 insertions, 9 deletions
diff --git a/noncore/net/mail/smtpwrapper.cpp b/noncore/net/mail/smtpwrapper.cpp index 162b1b9..a6a46ba 100644 --- a/noncore/net/mail/smtpwrapper.cpp +++ b/noncore/net/mail/smtpwrapper.cpp | |||
@@ -6,14 +6,17 @@ | |||
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <qdir.h> | 7 | #include <qdir.h> |
8 | 8 | ||
9 | #include <libetpan/mailmime.h> | 9 | #include <libetpan/libetpan.h> |
10 | #if 0 | ||
10 | #include <libetpan/mailimf.h> | 11 | #include <libetpan/mailimf.h> |
11 | #include <libetpan/mailsmtp.h> | 12 | #include <libetpan/mailsmtp.h> |
12 | #include <libetpan/mailstorage.h> | 13 | #include <libetpan/mailstorage.h> |
13 | #include <libetpan/maildriver.h> | 14 | #include <libetpan/maildriver.h> |
15 | #endif | ||
14 | 16 | ||
15 | #include "smtpwrapper.h" | 17 | #include "smtpwrapper.h" |
16 | #include "mailwrapper.h" | 18 | #include "mailwrapper.h" |
19 | #include "mboxwrapper.h" | ||
17 | #include "logindialog.h" | 20 | #include "logindialog.h" |
18 | #include "defines.h" | 21 | #include "defines.h" |
19 | 22 | ||
@@ -465,6 +468,23 @@ void SMTPwrapper::writeToFile(const QString&file, mailmime *mail ) | |||
465 | 468 | ||
466 | void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size ) | 469 | void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size ) |
467 | { | 470 | { |
471 | |||
472 | QFile msg_cache(file); | ||
473 | QString msg = ""; | ||
474 | msg_cache.open(IO_ReadOnly); | ||
475 | char*message = new char[4096]; | ||
476 | memset(message,0,4096); | ||
477 | while (msg_cache.readBlock(message,4095)>0) { | ||
478 | msg+=message; | ||
479 | memset(message,0,4096); | ||
480 | } | ||
481 | delete message; | ||
482 | *data = (char*)malloc(msg.length()+1*sizeof(char)); | ||
483 | memset(*data,0,msg.length()+1); | ||
484 | memcpy(*data,msg.ascii(),msg.length()); | ||
485 | *size=msg.length(); | ||
486 | |||
487 | #if 0 | ||
468 | char *buf; | 488 | char *buf; |
469 | struct stat st; | 489 | struct stat st; |
470 | int fd, count = 0, total = 0; | 490 | int fd, count = 0, total = 0; |
@@ -495,6 +515,7 @@ err_free: | |||
495 | free( buf ); | 515 | free( buf ); |
496 | err_close: | 516 | err_close: |
497 | close( fd ); | 517 | close( fd ); |
518 | #endif | ||
498 | } | 519 | } |
499 | 520 | ||
500 | void SMTPwrapper::progress( size_t current, size_t maximum ) | 521 | void SMTPwrapper::progress( size_t current, size_t maximum ) |
@@ -502,7 +523,16 @@ void SMTPwrapper::progress( size_t current, size_t maximum ) | |||
502 | qDebug( "Current: %i of %i", current, maximum ); | 523 | qDebug( "Current: %i of %i", current, maximum ); |
503 | } | 524 | } |
504 | 525 | ||
505 | void SMTPwrapper::smtpSend( mailmime *mail ) | 526 | void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) |
527 | { | ||
528 | if (!mail) return; | ||
529 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); | ||
530 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); | ||
531 | wrap->storeMessage(mail,length,box); | ||
532 | delete wrap; | ||
533 | } | ||
534 | |||
535 | void SMTPwrapper::smtpSend( mailmime *mail,bool later ) | ||
506 | { | 536 | { |
507 | mailsmtp *session; | 537 | mailsmtp *session; |
508 | clist *rcpts; | 538 | clist *rcpts; |
@@ -519,17 +549,27 @@ void SMTPwrapper::smtpSend( mailmime *mail ) | |||
519 | free(from); | 549 | free(from); |
520 | return; | 550 | return; |
521 | } | 551 | } |
522 | server = strdup( smtp->getServer().latin1() ); | ||
523 | ssl = smtp->getSSL(); | ||
524 | port = smtp->getPort().toUInt(); | ||
525 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); | 552 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); |
526 | 553 | ||
527 | QString file = getTmpFile(); | 554 | QString file = getTmpFile(); |
528 | writeToFile( file, mail ); | 555 | writeToFile( file, mail ); |
556 | |||
529 | readFromFile( file, &data, &size ); | 557 | readFromFile( file, &data, &size ); |
530 | QFile f( file ); | 558 | QFile f( file ); |
531 | f.remove(); | 559 | f.remove(); |
532 | 560 | ||
561 | storeMail(data,size,(later?"Outgoing":"Sent")); | ||
562 | |||
563 | if (later) { | ||
564 | smtp_address_list_free( rcpts ); | ||
565 | if (data) free( data ); | ||
566 | if (from) free(from); | ||
567 | return; | ||
568 | } | ||
569 | server = strdup( smtp->getServer().latin1() ); | ||
570 | ssl = smtp->getSSL(); | ||
571 | port = smtp->getPort().toUInt(); | ||
572 | |||
533 | session = mailsmtp_new( 20, &progress ); | 573 | session = mailsmtp_new( 20, &progress ); |
534 | if ( session == NULL ) goto free_mem; | 574 | if ( session == NULL ) goto free_mem; |
535 | 575 | ||
@@ -581,8 +621,9 @@ free_mem_session: | |||
581 | mailsmtp_free( session ); | 621 | mailsmtp_free( session ); |
582 | free_mem: | 622 | free_mem: |
583 | smtp_address_list_free( rcpts ); | 623 | smtp_address_list_free( rcpts ); |
584 | free( data ); | 624 | if (data) free( data ); |
585 | free( server ); | 625 | if (from) free(from); |
626 | if (server) free( server ); | ||
586 | if ( smtp->getLogin() ) { | 627 | if ( smtp->getLogin() ) { |
587 | free( user ); | 628 | free( user ); |
588 | free( pass ); | 629 | free( pass ); |
@@ -590,7 +631,7 @@ free_mem: | |||
590 | free( from ); | 631 | free( from ); |
591 | } | 632 | } |
592 | 633 | ||
593 | void SMTPwrapper::sendMail(const Mail&mail ) | 634 | void SMTPwrapper::sendMail(const Mail&mail,bool later ) |
594 | { | 635 | { |
595 | mailmime *mimeMail; | 636 | mailmime *mimeMail; |
596 | 637 | ||
@@ -598,7 +639,7 @@ void SMTPwrapper::sendMail(const Mail&mail ) | |||
598 | if ( mimeMail == NULL ) { | 639 | if ( mimeMail == NULL ) { |
599 | qDebug( "sendMail: error creating mime mail" ); | 640 | qDebug( "sendMail: error creating mime mail" ); |
600 | } else { | 641 | } else { |
601 | smtpSend( mimeMail ); | 642 | smtpSend( mimeMail,later ); |
602 | mailmime_free( mimeMail ); | 643 | mailmime_free( mimeMail ); |
603 | } | 644 | } |
604 | } | 645 | } |