summaryrefslogtreecommitdiff
authoralwin <alwin>2003-12-22 02:37:35 (UTC)
committer alwin <alwin>2003-12-22 02:37:35 (UTC)
commit9e7aafdb7c76d29fee742d53131a73dd60aded2b (patch) (unidiff)
treee98f9fe1233455f458738acbfd29bac78dd03342
parent7c016e1a75970cb7c28d70398ad20c708cdb452b (diff)
downloadopie-9e7aafdb7c76d29fee742d53131a73dd60aded2b.zip
opie-9e7aafdb7c76d29fee742d53131a73dd60aded2b.tar.gz
opie-9e7aafdb7c76d29fee742d53131a73dd60aded2b.tar.bz2
- storing mails send in outgoing (if queued) or sent (if sent) folder
TODO: flush queue, cleanup SMTP code, select smtp-account if more than one when flush the outgoing queue
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/composemail.cpp3
-rw-r--r--noncore/net/mail/libmailwrapper/mboxwrapper.cpp26
-rw-r--r--noncore/net/mail/libmailwrapper/mboxwrapper.h2
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.cpp61
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.h6
-rw-r--r--noncore/net/mail/mboxwrapper.cpp26
-rw-r--r--noncore/net/mail/mboxwrapper.h2
-rw-r--r--noncore/net/mail/smtpwrapper.cpp61
-rw-r--r--noncore/net/mail/smtpwrapper.h6
9 files changed, 162 insertions, 31 deletions
diff --git a/noncore/net/mail/composemail.cpp b/noncore/net/mail/composemail.cpp
index f680f5c..f532815 100644
--- a/noncore/net/mail/composemail.cpp
+++ b/noncore/net/mail/composemail.cpp
@@ -159,24 +159,25 @@ void ComposeMail::removeAttachment()
159 159
160void ComposeMail::accept() 160void ComposeMail::accept()
161{ 161{
162 if ( checkBoxLater->isChecked() ) { 162 if ( checkBoxLater->isChecked() ) {
163 qDebug( "Send later" ); 163 qDebug( "Send later" );
164 } 164 }
165 165
166 166
167 qDebug( "Sending Mail with " + 167 qDebug( "Sending Mail with " +
168 smtpAccounts.at( fromBox->currentItem() )->getAccountName() ); 168 smtpAccounts.at( fromBox->currentItem() )->getAccountName() );
169 Mail *mail = new Mail(); 169 Mail *mail = new Mail();
170 SMTPaccount *smtp = smtpAccounts.at( fromBox->currentItem() ); 170 SMTPaccount *smtp = smtpAccounts.at( fromBox->currentItem() );
171
171 mail->setMail( smtp->getMail() ); 172 mail->setMail( smtp->getMail() );
172 mail->setName( smtp->getName() ); 173 mail->setName( smtp->getName() );
173 174
174 if ( !toLine->text().isEmpty() ) { 175 if ( !toLine->text().isEmpty() ) {
175 mail->setTo( toLine->text() ); 176 mail->setTo( toLine->text() );
176 } else { 177 } else {
177 qDebug( "No Reciever spezified -> returning" ); 178 qDebug( "No Reciever spezified -> returning" );
178 return; 179 return;
179 } 180 }
180 181
181 mail->setCC( ccLine->text() ); 182 mail->setCC( ccLine->text() );
182 mail->setBCC( bccLine->text() ); 183 mail->setBCC( bccLine->text() );
@@ -186,25 +187,25 @@ void ComposeMail::accept()
186 if ( !sigMultiLine->text().isEmpty() ) { 187 if ( !sigMultiLine->text().isEmpty() ) {
187 txt.append( "\n--\n" ); 188 txt.append( "\n--\n" );
188 txt.append( sigMultiLine->text() ); 189 txt.append( sigMultiLine->text() );
189 } 190 }
190 mail->setMessage( txt ); 191 mail->setMessage( txt );
191 AttachViewItem *it = (AttachViewItem *) attList->firstChild(); 192 AttachViewItem *it = (AttachViewItem *) attList->firstChild();
192 while ( it != NULL ) { 193 while ( it != NULL ) {
193 mail->addAttachment( it->getAttachment() ); 194 mail->addAttachment( it->getAttachment() );
194 it = (AttachViewItem *) it->itemBelow(); 195 it = (AttachViewItem *) it->itemBelow();
195 } 196 }
196 197
197 SMTPwrapper wrapper( settings ); 198 SMTPwrapper wrapper( settings );
198 wrapper.sendMail( *mail ); 199 wrapper.sendMail( *mail,checkBoxLater->isChecked() );
199 200
200 QDialog::accept(); 201 QDialog::accept();
201} 202}
202 203
203AttachViewItem::AttachViewItem( QListView *parent, Attachment *att ) 204AttachViewItem::AttachViewItem( QListView *parent, Attachment *att )
204 : QListViewItem( parent ) 205 : QListViewItem( parent )
205{ 206{
206 attachment = att; 207 attachment = att;
207 qDebug( att->getMimeType() ); 208 qDebug( att->getMimeType() );
208 setPixmap( 0, attachment->getDocLnk().pixmap().isNull() ? 209 setPixmap( 0, attachment->getDocLnk().pixmap().isNull() ?
209 Resource::loadPixmap( "UnknownDocument-14" ) : 210 Resource::loadPixmap( "UnknownDocument-14" ) :
210 attachment->getDocLnk().pixmap() ); 211 attachment->getDocLnk().pixmap() );
diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp
index 7581715..8117cef 100644
--- a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp
@@ -1,17 +1,17 @@
1#include "mboxwrapper.h" 1#include "mboxwrapper.h"
2#include "mailtypes.h" 2#include "mailtypes.h"
3#include "mailwrapper.h" 3#include "mailwrapper.h"
4#include "libetpan/libetpan.h" 4#include <libetpan/libetpan.h>
5#include "libetpan/mailstorage.h" 5#include <libetpan/mailstorage.h>
6#include <qdir.h> 6#include <qdir.h>
7 7
8MBOXwrapper::MBOXwrapper(const QString & mbox_dir) 8MBOXwrapper::MBOXwrapper(const QString & mbox_dir)
9 : Genericwrapper(),MBOXPath(mbox_dir) 9 : Genericwrapper(),MBOXPath(mbox_dir)
10{ 10{
11 QDir dir(MBOXPath); 11 QDir dir(MBOXPath);
12 if (!dir.exists()) { 12 if (!dir.exists()) {
13 dir.mkdir(MBOXPath); 13 dir.mkdir(MBOXPath);
14 } 14 }
15} 15}
16 16
17MBOXwrapper::~MBOXwrapper() 17MBOXwrapper::~MBOXwrapper()
@@ -58,25 +58,24 @@ void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target )
58 mailmessage * msg; 58 mailmessage * msg;
59 QBitArray mFlags(7); 59 QBitArray mFlags(7);
60 msg = (mailmessage*)carray_get(env_list->msg_tab, i); 60 msg = (mailmessage*)carray_get(env_list->msg_tab, i);
61 if (msg->msg_fields == NULL) { 61 if (msg->msg_fields == NULL) {
62 qDebug("could not fetch envelope of message %i", i); 62 qDebug("could not fetch envelope of message %i", i);
63 continue; 63 continue;
64 } 64 }
65 RecMail * mail = new RecMail(); 65 RecMail * mail = new RecMail();
66 mail->setWrapper(this); 66 mail->setWrapper(this);
67 mail_flags * flag_result = 0; 67 mail_flags * flag_result = 0;
68 r = mailmessage_get_flags(msg,&flag_result); 68 r = mailmessage_get_flags(msg,&flag_result);
69 if (r == MAIL_ERROR_NOT_IMPLEMENTED) { 69 if (r == MAIL_ERROR_NOT_IMPLEMENTED) {
70 qDebug("flag fetching not implemented");
71 mFlags.setBit(FLAG_SEEN); 70 mFlags.setBit(FLAG_SEEN);
72 } 71 }
73 mailimf_single_fields single_fields; 72 mailimf_single_fields single_fields;
74 mailimf_single_fields_init(&single_fields, msg->msg_fields); 73 mailimf_single_fields_init(&single_fields, msg->msg_fields);
75 mail->setMsgsize(msg->msg_size); 74 mail->setMsgsize(msg->msg_size);
76 mail->setFlags(mFlags); 75 mail->setFlags(mFlags);
77 mail->setMbox(mailbox); 76 mail->setMbox(mailbox);
78 mail->setNumber(i+1); 77 mail->setNumber(i+1);
79 if (single_fields.fld_subject) 78 if (single_fields.fld_subject)
80 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); 79 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value));
81 if (single_fields.fld_from) 80 if (single_fields.fld_from)
82 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); 81 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list));
@@ -188,12 +187,33 @@ RecBody MBOXwrapper::fetchBody( const RecMail &mail )
188 body = parseMail(msg); 187 body = parseMail(msg);
189 mailmessage_fetch_result_free(msg,data); 188 mailmessage_fetch_result_free(msg,data);
190 mailfolder_free(folder); 189 mailfolder_free(folder);
191 mailstorage_free(storage); 190 mailstorage_free(storage);
192 191
193 return body; 192 return body;
194} 193}
195 194
196void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) 195void MBOXwrapper::mbox_progress( size_t current, size_t maximum )
197{ 196{
198 qDebug("MBOX %i von %i",current,maximum); 197 qDebug("MBOX %i von %i",current,maximum);
199} 198}
199
200void MBOXwrapper::createFolder(const QString&)
201{
202}
203
204void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
205{
206 QString p = MBOXPath+"/";
207 p+=folder;
208 mailmbox_folder*f = 0;
209 int r = mailmbox_init(p.latin1(),0,1,0,&f);
210 if (r != MAIL_NO_ERROR) {
211 qDebug("Error init folder");
212 return;
213 }
214 r = mailmbox_append_message(f,msg,length);
215 if (r != MAIL_NO_ERROR) {
216 qDebug("Error writing message folder");
217 }
218 mailmbox_done(f);
219}
diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.h b/noncore/net/mail/libmailwrapper/mboxwrapper.h
index 779dbc8..1bbaf79 100644
--- a/noncore/net/mail/libmailwrapper/mboxwrapper.h
+++ b/noncore/net/mail/libmailwrapper/mboxwrapper.h
@@ -10,21 +10,23 @@ class RecBody;
10class MBOXwrapper : public Genericwrapper 10class MBOXwrapper : public Genericwrapper
11{ 11{
12 Q_OBJECT 12 Q_OBJECT
13public: 13public:
14 MBOXwrapper(const QString & dir); 14 MBOXwrapper(const QString & dir);
15 virtual ~MBOXwrapper(); 15 virtual ~MBOXwrapper();
16 16
17 virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); 17 virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
18 virtual QList<Folder>* listFolders(); 18 virtual QList<Folder>* listFolders();
19 19
20 virtual void deleteMail(const RecMail&mail); 20 virtual void deleteMail(const RecMail&mail);
21 virtual void answeredMail(const RecMail&mail); 21 virtual void answeredMail(const RecMail&mail);
22 virtual void createFolder(const QString&aFolder);
23 virtual void storeMessage(const char*msg,size_t length, const QString&folder);
22 24
23 virtual RecBody fetchBody( const RecMail &mail ); 25 virtual RecBody fetchBody( const RecMail &mail );
24 static void mbox_progress( size_t current, size_t maximum ); 26 static void mbox_progress( size_t current, size_t maximum );
25 27
26protected: 28protected:
27 QString MBOXPath; 29 QString MBOXPath;
28}; 30};
29 31
30#endif 32#endif
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
index 162b1b9..a6a46ba 100644
--- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
@@ -1,28 +1,31 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <sys/stat.h> 2#include <sys/stat.h>
3#include <sys/types.h> 3#include <sys/types.h>
4#include <unistd.h> 4#include <unistd.h>
5#include <fcntl.h> 5#include <fcntl.h>
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
20SMTPwrapper::SMTPwrapper( Settings *s ) 23SMTPwrapper::SMTPwrapper( Settings *s )
21 : QObject() 24 : QObject()
22{ 25{
23 settings = s; 26 settings = s;
24} 27}
25 28
26QString SMTPwrapper::mailsmtpError( int errnum ) 29QString SMTPwrapper::mailsmtpError( int errnum )
27{ 30{
28 switch ( errnum ) { 31 switch ( errnum ) {
@@ -456,24 +459,41 @@ void SMTPwrapper::writeToFile(const QString&file, mailmime *mail )
456 err = mailmime_write( f, &col, mail ); 459 err = mailmime_write( f, &col, mail );
457 if ( err != MAILIMF_NO_ERROR ) { 460 if ( err != MAILIMF_NO_ERROR ) {
458 fclose( f ); 461 fclose( f );
459 qDebug( "writeToFile: error writing mailmime" ); 462 qDebug( "writeToFile: error writing mailmime" );
460 return; 463 return;
461 } 464 }
462 465
463 fclose( f ); 466 fclose( f );
464} 467}
465 468
466void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size ) 469void 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;
471 491
472 fd = open( file.latin1(), O_RDONLY, 0 ); 492 fd = open( file.latin1(), O_RDONLY, 0 );
473 if ( fd == -1 ) return; 493 if ( fd == -1 ) return;
474 494
475 if ( fstat( fd, &st ) != 0 ) goto err_close; 495 if ( fstat( fd, &st ) != 0 ) goto err_close;
476 if ( !st.st_size ) goto err_close; 496 if ( !st.st_size ) goto err_close;
477 497
478 buf = (char *) malloc( st.st_size ); 498 buf = (char *) malloc( st.st_size );
479 if ( !buf ) goto err_close; 499 if ( !buf ) goto err_close;
@@ -486,59 +506,79 @@ void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size )
486 506
487 *data = buf; 507 *data = buf;
488 *size = st.st_size; 508 *size = st.st_size;
489 509
490 close( fd ); 510 close( fd );
491 511
492 return; // Success :) 512 return; // Success :)
493 513
494err_free: 514err_free:
495 free( buf ); 515 free( buf );
496err_close: 516err_close:
497 close( fd ); 517 close( fd );
518#endif
498} 519}
499 520
500void SMTPwrapper::progress( size_t current, size_t maximum ) 521void SMTPwrapper::progress( size_t current, size_t maximum )
501{ 522{
502 qDebug( "Current: %i of %i", current, maximum ); 523 qDebug( "Current: %i of %i", current, maximum );
503} 524}
504 525
505void SMTPwrapper::smtpSend( mailmime *mail ) 526void 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
535void SMTPwrapper::smtpSend( mailmime *mail,bool later )
506{ 536{
507 mailsmtp *session; 537 mailsmtp *session;
508 clist *rcpts; 538 clist *rcpts;
509 char *from, *data, *server, *user = NULL, *pass = NULL; 539 char *from, *data, *server, *user = NULL, *pass = NULL;
510 size_t size; 540 size_t size;
511 int err; 541 int err;
512 bool ssl; 542 bool ssl;
513 uint16_t port; 543 uint16_t port;
514 544
515 545
516 from = getFrom( mail ); 546 from = getFrom( mail );
517 SMTPaccount *smtp = getAccount( from ); 547 SMTPaccount *smtp = getAccount( from );
518 if ( smtp == NULL ) { 548 if ( smtp == NULL ) {
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();
560
561 storeMail(data,size,(later?"Outgoing":"Sent"));
532 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
536 qDebug( "Servername %s at port %i", server, port ); 576 qDebug( "Servername %s at port %i", server, port );
537 if ( ssl ) { 577 if ( ssl ) {
538 qDebug( "SSL session" ); 578 qDebug( "SSL session" );
539 err = mailsmtp_ssl_connect( session, server, port ); 579 err = mailsmtp_ssl_connect( session, server, port );
540 } else { 580 } else {
541 qDebug( "No SSL session" ); 581 qDebug( "No SSL session" );
542 err = mailsmtp_socket_connect( session, server, port ); 582 err = mailsmtp_socket_connect( session, server, port );
543 } 583 }
544 if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session; 584 if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session;
@@ -572,33 +612,34 @@ void SMTPwrapper::smtpSend( mailmime *mail )
572 612
573 err = mailsmtp_send( session, from, rcpts, data, size ); 613 err = mailsmtp_send( session, from, rcpts, data, size );
574 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; 614 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session;
575 615
576 qDebug( "Mail sent." ); 616 qDebug( "Mail sent." );
577 617
578free_con_session: 618free_con_session:
579 mailsmtp_quit( session ); 619 mailsmtp_quit( session );
580free_mem_session: 620free_mem_session:
581 mailsmtp_free( session ); 621 mailsmtp_free( session );
582free_mem: 622free_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 );
589 } 630 }
590 free( from ); 631 free( from );
591} 632}
592 633
593void SMTPwrapper::sendMail(const Mail&mail ) 634void SMTPwrapper::sendMail(const Mail&mail,bool later )
594{ 635{
595 mailmime *mimeMail; 636 mailmime * mimeMail;
596 637
597 mimeMail = createMimeMail(mail ); 638 mimeMail = createMimeMail(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}
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.h b/noncore/net/mail/libmailwrapper/smtpwrapper.h
index 8fdb07d..41e9a8c 100644
--- a/noncore/net/mail/libmailwrapper/smtpwrapper.h
+++ b/noncore/net/mail/libmailwrapper/smtpwrapper.h
@@ -15,39 +15,41 @@ struct mailimf_fields;
15struct mailimf_field; 15struct mailimf_field;
16struct mailimf_mailbox; 16struct mailimf_mailbox;
17struct mailmime; 17struct mailmime;
18struct mailimf_address_list; 18struct mailimf_address_list;
19 19
20class SMTPwrapper : public QObject 20class SMTPwrapper : public QObject
21{ 21{
22 Q_OBJECT 22 Q_OBJECT
23 23
24public: 24public:
25 SMTPwrapper( Settings *s ); 25 SMTPwrapper( Settings *s );
26 virtual ~SMTPwrapper(){} 26 virtual ~SMTPwrapper(){}
27 void sendMail(const Mail& mail ); 27 void sendMail(const Mail& mail,bool later=false );
28 28
29protected: 29protected:
30 mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); 30 mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
31 mailimf_fields *createImfFields(const Mail &mail ); 31 mailimf_fields *createImfFields(const Mail &mail );
32 mailmime *createMimeMail(const Mail&mail ); 32 mailmime *createMimeMail(const Mail&mail );
33 33
34 mailimf_address_list *parseAddresses(const QString&addr ); 34 mailimf_address_list *parseAddresses(const QString&addr );
35 void addFileParts( mailmime *message,const QList<Attachment>&files ); 35 void addFileParts( mailmime *message,const QList<Attachment>&files );
36 mailmime *buildTxtPart(const QString&str ); 36 mailmime *buildTxtPart(const QString&str );
37 mailmime *buildFilePart(const QString&filename,const QString&mimetype ); 37 mailmime *buildFilePart(const QString&filename,const QString&mimetype );
38 void smtpSend( mailmime *mail ); 38 void smtpSend( mailmime *mail,bool later );
39 mailimf_field *getField( mailimf_fields *fields, int type ); 39 mailimf_field *getField( mailimf_fields *fields, int type );
40 clist *createRcptList( mailimf_fields *fields ); 40 clist *createRcptList( mailimf_fields *fields );
41 char *getFrom( mailmime *mail ); 41 char *getFrom( mailmime *mail );
42 SMTPaccount *getAccount(const QString&from ); 42 SMTPaccount *getAccount(const QString&from );
43 void writeToFile(const QString&file, mailmime *mail ); 43 void writeToFile(const QString&file, mailmime *mail );
44 void readFromFile(const QString&file, char **data, size_t *size ); 44 void readFromFile(const QString&file, char **data, size_t *size );
45 void storeMail(char*mail, size_t length, const QString&box);
45 46
46 static QString mailsmtpError( int err ); 47 static QString mailsmtpError( int err );
47 static QString getTmpFile(); 48 static QString getTmpFile();
48 static void progress( size_t current, size_t maximum ); 49 static void progress( size_t current, size_t maximum );
49 static void addRcpts( clist *list, mailimf_address_list *addr_list ); 50 static void addRcpts( clist *list, mailimf_address_list *addr_list );
51 void storeMail(mailmime*mail, const QString&box);
50 Settings *settings; 52 Settings *settings;
51}; 53};
52 54
53#endif 55#endif
diff --git a/noncore/net/mail/mboxwrapper.cpp b/noncore/net/mail/mboxwrapper.cpp
index 7581715..8117cef 100644
--- a/noncore/net/mail/mboxwrapper.cpp
+++ b/noncore/net/mail/mboxwrapper.cpp
@@ -1,17 +1,17 @@
1#include "mboxwrapper.h" 1#include "mboxwrapper.h"
2#include "mailtypes.h" 2#include "mailtypes.h"
3#include "mailwrapper.h" 3#include "mailwrapper.h"
4#include "libetpan/libetpan.h" 4#include <libetpan/libetpan.h>
5#include "libetpan/mailstorage.h" 5#include <libetpan/mailstorage.h>
6#include <qdir.h> 6#include <qdir.h>
7 7
8MBOXwrapper::MBOXwrapper(const QString & mbox_dir) 8MBOXwrapper::MBOXwrapper(const QString & mbox_dir)
9 : Genericwrapper(),MBOXPath(mbox_dir) 9 : Genericwrapper(),MBOXPath(mbox_dir)
10{ 10{
11 QDir dir(MBOXPath); 11 QDir dir(MBOXPath);
12 if (!dir.exists()) { 12 if (!dir.exists()) {
13 dir.mkdir(MBOXPath); 13 dir.mkdir(MBOXPath);
14 } 14 }
15} 15}
16 16
17MBOXwrapper::~MBOXwrapper() 17MBOXwrapper::~MBOXwrapper()
@@ -58,25 +58,24 @@ void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target )
58 mailmessage * msg; 58 mailmessage * msg;
59 QBitArray mFlags(7); 59 QBitArray mFlags(7);
60 msg = (mailmessage*)carray_get(env_list->msg_tab, i); 60 msg = (mailmessage*)carray_get(env_list->msg_tab, i);
61 if (msg->msg_fields == NULL) { 61 if (msg->msg_fields == NULL) {
62 qDebug("could not fetch envelope of message %i", i); 62 qDebug("could not fetch envelope of message %i", i);
63 continue; 63 continue;
64 } 64 }
65 RecMail * mail = new RecMail(); 65 RecMail * mail = new RecMail();
66 mail->setWrapper(this); 66 mail->setWrapper(this);
67 mail_flags * flag_result = 0; 67 mail_flags * flag_result = 0;
68 r = mailmessage_get_flags(msg,&flag_result); 68 r = mailmessage_get_flags(msg,&flag_result);
69 if (r == MAIL_ERROR_NOT_IMPLEMENTED) { 69 if (r == MAIL_ERROR_NOT_IMPLEMENTED) {
70 qDebug("flag fetching not implemented");
71 mFlags.setBit(FLAG_SEEN); 70 mFlags.setBit(FLAG_SEEN);
72 } 71 }
73 mailimf_single_fields single_fields; 72 mailimf_single_fields single_fields;
74 mailimf_single_fields_init(&single_fields, msg->msg_fields); 73 mailimf_single_fields_init(&single_fields, msg->msg_fields);
75 mail->setMsgsize(msg->msg_size); 74 mail->setMsgsize(msg->msg_size);
76 mail->setFlags(mFlags); 75 mail->setFlags(mFlags);
77 mail->setMbox(mailbox); 76 mail->setMbox(mailbox);
78 mail->setNumber(i+1); 77 mail->setNumber(i+1);
79 if (single_fields.fld_subject) 78 if (single_fields.fld_subject)
80 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); 79 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value));
81 if (single_fields.fld_from) 80 if (single_fields.fld_from)
82 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); 81 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list));
@@ -188,12 +187,33 @@ RecBody MBOXwrapper::fetchBody( const RecMail &mail )
188 body = parseMail(msg); 187 body = parseMail(msg);
189 mailmessage_fetch_result_free(msg,data); 188 mailmessage_fetch_result_free(msg,data);
190 mailfolder_free(folder); 189 mailfolder_free(folder);
191 mailstorage_free(storage); 190 mailstorage_free(storage);
192 191
193 return body; 192 return body;
194} 193}
195 194
196void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) 195void MBOXwrapper::mbox_progress( size_t current, size_t maximum )
197{ 196{
198 qDebug("MBOX %i von %i",current,maximum); 197 qDebug("MBOX %i von %i",current,maximum);
199} 198}
199
200void MBOXwrapper::createFolder(const QString&)
201{
202}
203
204void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
205{
206 QString p = MBOXPath+"/";
207 p+=folder;
208 mailmbox_folder*f = 0;
209 int r = mailmbox_init(p.latin1(),0,1,0,&f);
210 if (r != MAIL_NO_ERROR) {
211 qDebug("Error init folder");
212 return;
213 }
214 r = mailmbox_append_message(f,msg,length);
215 if (r != MAIL_NO_ERROR) {
216 qDebug("Error writing message folder");
217 }
218 mailmbox_done(f);
219}
diff --git a/noncore/net/mail/mboxwrapper.h b/noncore/net/mail/mboxwrapper.h
index 779dbc8..1bbaf79 100644
--- a/noncore/net/mail/mboxwrapper.h
+++ b/noncore/net/mail/mboxwrapper.h
@@ -10,21 +10,23 @@ class RecBody;
10class MBOXwrapper : public Genericwrapper 10class MBOXwrapper : public Genericwrapper
11{ 11{
12 Q_OBJECT 12 Q_OBJECT
13public: 13public:
14 MBOXwrapper(const QString & dir); 14 MBOXwrapper(const QString & dir);
15 virtual ~MBOXwrapper(); 15 virtual ~MBOXwrapper();
16 16
17 virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); 17 virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
18 virtual QList<Folder>* listFolders(); 18 virtual QList<Folder>* listFolders();
19 19
20 virtual void deleteMail(const RecMail&mail); 20 virtual void deleteMail(const RecMail&mail);
21 virtual void answeredMail(const RecMail&mail); 21 virtual void answeredMail(const RecMail&mail);
22 virtual void createFolder(const QString&aFolder);
23 virtual void storeMessage(const char*msg,size_t length, const QString&folder);
22 24
23 virtual RecBody fetchBody( const RecMail &mail ); 25 virtual RecBody fetchBody( const RecMail &mail );
24 static void mbox_progress( size_t current, size_t maximum ); 26 static void mbox_progress( size_t current, size_t maximum );
25 27
26protected: 28protected:
27 QString MBOXPath; 29 QString MBOXPath;
28}; 30};
29 31
30#endif 32#endif
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
@@ -1,28 +1,31 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <sys/stat.h> 2#include <sys/stat.h>
3#include <sys/types.h> 3#include <sys/types.h>
4#include <unistd.h> 4#include <unistd.h>
5#include <fcntl.h> 5#include <fcntl.h>
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
20SMTPwrapper::SMTPwrapper( Settings *s ) 23SMTPwrapper::SMTPwrapper( Settings *s )
21 : QObject() 24 : QObject()
22{ 25{
23 settings = s; 26 settings = s;
24} 27}
25 28
26QString SMTPwrapper::mailsmtpError( int errnum ) 29QString SMTPwrapper::mailsmtpError( int errnum )
27{ 30{
28 switch ( errnum ) { 31 switch ( errnum ) {
@@ -456,24 +459,41 @@ void SMTPwrapper::writeToFile(const QString&file, mailmime *mail )
456 err = mailmime_write( f, &col, mail ); 459 err = mailmime_write( f, &col, mail );
457 if ( err != MAILIMF_NO_ERROR ) { 460 if ( err != MAILIMF_NO_ERROR ) {
458 fclose( f ); 461 fclose( f );
459 qDebug( "writeToFile: error writing mailmime" ); 462 qDebug( "writeToFile: error writing mailmime" );
460 return; 463 return;
461 } 464 }
462 465
463 fclose( f ); 466 fclose( f );
464} 467}
465 468
466void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size ) 469void 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;
471 491
472 fd = open( file.latin1(), O_RDONLY, 0 ); 492 fd = open( file.latin1(), O_RDONLY, 0 );
473 if ( fd == -1 ) return; 493 if ( fd == -1 ) return;
474 494
475 if ( fstat( fd, &st ) != 0 ) goto err_close; 495 if ( fstat( fd, &st ) != 0 ) goto err_close;
476 if ( !st.st_size ) goto err_close; 496 if ( !st.st_size ) goto err_close;
477 497
478 buf = (char *) malloc( st.st_size ); 498 buf = (char *) malloc( st.st_size );
479 if ( !buf ) goto err_close; 499 if ( !buf ) goto err_close;
@@ -486,59 +506,79 @@ void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size )
486 506
487 *data = buf; 507 *data = buf;
488 *size = st.st_size; 508 *size = st.st_size;
489 509
490 close( fd ); 510 close( fd );
491 511
492 return; // Success :) 512 return; // Success :)
493 513
494err_free: 514err_free:
495 free( buf ); 515 free( buf );
496err_close: 516err_close:
497 close( fd ); 517 close( fd );
518#endif
498} 519}
499 520
500void SMTPwrapper::progress( size_t current, size_t maximum ) 521void SMTPwrapper::progress( size_t current, size_t maximum )
501{ 522{
502 qDebug( "Current: %i of %i", current, maximum ); 523 qDebug( "Current: %i of %i", current, maximum );
503} 524}
504 525
505void SMTPwrapper::smtpSend( mailmime *mail ) 526void 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
535void SMTPwrapper::smtpSend( mailmime *mail,bool later )
506{ 536{
507 mailsmtp *session; 537 mailsmtp *session;
508 clist *rcpts; 538 clist *rcpts;
509 char *from, *data, *server, *user = NULL, *pass = NULL; 539 char *from, *data, *server, *user = NULL, *pass = NULL;
510 size_t size; 540 size_t size;
511 int err; 541 int err;
512 bool ssl; 542 bool ssl;
513 uint16_t port; 543 uint16_t port;
514 544
515 545
516 from = getFrom( mail ); 546 from = getFrom( mail );
517 SMTPaccount *smtp = getAccount( from ); 547 SMTPaccount *smtp = getAccount( from );
518 if ( smtp == NULL ) { 548 if ( smtp == NULL ) {
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();
560
561 storeMail(data,size,(later?"Outgoing":"Sent"));
532 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
536 qDebug( "Servername %s at port %i", server, port ); 576 qDebug( "Servername %s at port %i", server, port );
537 if ( ssl ) { 577 if ( ssl ) {
538 qDebug( "SSL session" ); 578 qDebug( "SSL session" );
539 err = mailsmtp_ssl_connect( session, server, port ); 579 err = mailsmtp_ssl_connect( session, server, port );
540 } else { 580 } else {
541 qDebug( "No SSL session" ); 581 qDebug( "No SSL session" );
542 err = mailsmtp_socket_connect( session, server, port ); 582 err = mailsmtp_socket_connect( session, server, port );
543 } 583 }
544 if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session; 584 if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session;
@@ -572,33 +612,34 @@ void SMTPwrapper::smtpSend( mailmime *mail )
572 612
573 err = mailsmtp_send( session, from, rcpts, data, size ); 613 err = mailsmtp_send( session, from, rcpts, data, size );
574 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; 614 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session;
575 615
576 qDebug( "Mail sent." ); 616 qDebug( "Mail sent." );
577 617
578free_con_session: 618free_con_session:
579 mailsmtp_quit( session ); 619 mailsmtp_quit( session );
580free_mem_session: 620free_mem_session:
581 mailsmtp_free( session ); 621 mailsmtp_free( session );
582free_mem: 622free_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 );
589 } 630 }
590 free( from ); 631 free( from );
591} 632}
592 633
593void SMTPwrapper::sendMail(const Mail&mail ) 634void SMTPwrapper::sendMail(const Mail&mail,bool later )
594{ 635{
595 mailmime *mimeMail; 636 mailmime * mimeMail;
596 637
597 mimeMail = createMimeMail(mail ); 638 mimeMail = createMimeMail(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}
diff --git a/noncore/net/mail/smtpwrapper.h b/noncore/net/mail/smtpwrapper.h
index 8fdb07d..41e9a8c 100644
--- a/noncore/net/mail/smtpwrapper.h
+++ b/noncore/net/mail/smtpwrapper.h
@@ -15,39 +15,41 @@ struct mailimf_fields;
15struct mailimf_field; 15struct mailimf_field;
16struct mailimf_mailbox; 16struct mailimf_mailbox;
17struct mailmime; 17struct mailmime;
18struct mailimf_address_list; 18struct mailimf_address_list;
19 19
20class SMTPwrapper : public QObject 20class SMTPwrapper : public QObject
21{ 21{
22 Q_OBJECT 22 Q_OBJECT
23 23
24public: 24public:
25 SMTPwrapper( Settings *s ); 25 SMTPwrapper( Settings *s );
26 virtual ~SMTPwrapper(){} 26 virtual ~SMTPwrapper(){}
27 void sendMail(const Mail& mail ); 27 void sendMail(const Mail& mail,bool later=false );
28 28
29protected: 29protected:
30 mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); 30 mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
31 mailimf_fields *createImfFields(const Mail &mail ); 31 mailimf_fields *createImfFields(const Mail &mail );
32 mailmime *createMimeMail(const Mail&mail ); 32 mailmime *createMimeMail(const Mail&mail );
33 33
34 mailimf_address_list *parseAddresses(const QString&addr ); 34 mailimf_address_list *parseAddresses(const QString&addr );
35 void addFileParts( mailmime *message,const QList<Attachment>&files ); 35 void addFileParts( mailmime *message,const QList<Attachment>&files );
36 mailmime *buildTxtPart(const QString&str ); 36 mailmime *buildTxtPart(const QString&str );
37 mailmime *buildFilePart(const QString&filename,const QString&mimetype ); 37 mailmime *buildFilePart(const QString&filename,const QString&mimetype );
38 void smtpSend( mailmime *mail ); 38 void smtpSend( mailmime *mail,bool later );
39 mailimf_field *getField( mailimf_fields *fields, int type ); 39 mailimf_field *getField( mailimf_fields *fields, int type );
40 clist *createRcptList( mailimf_fields *fields ); 40 clist *createRcptList( mailimf_fields *fields );
41 char *getFrom( mailmime *mail ); 41 char *getFrom( mailmime *mail );
42 SMTPaccount *getAccount(const QString&from ); 42 SMTPaccount *getAccount(const QString&from );
43 void writeToFile(const QString&file, mailmime *mail ); 43 void writeToFile(const QString&file, mailmime *mail );
44 void readFromFile(const QString&file, char **data, size_t *size ); 44 void readFromFile(const QString&file, char **data, size_t *size );
45 void storeMail(char*mail, size_t length, const QString&box);
45 46
46 static QString mailsmtpError( int err ); 47 static QString mailsmtpError( int err );
47 static QString getTmpFile(); 48 static QString getTmpFile();
48 static void progress( size_t current, size_t maximum ); 49 static void progress( size_t current, size_t maximum );
49 static void addRcpts( clist *list, mailimf_address_list *addr_list ); 50 static void addRcpts( clist *list, mailimf_address_list *addr_list );
51 void storeMail(mailmime*mail, const QString&box);
50 Settings *settings; 52 Settings *settings;
51}; 53};
52 54
53#endif 55#endif