summaryrefslogtreecommitdiff
path: root/noncore/net/mail/libmailwrapper
authoralwin <alwin>2003-12-24 02:00:34 (UTC)
committer alwin <alwin>2003-12-24 02:00:34 (UTC)
commitfa581423c0ffcf35cbc403645e2131e84342dae4 (patch) (unidiff)
tree53152de4b2213f858096141bb50e5ca2ec0e91ef /noncore/net/mail/libmailwrapper
parent242f7a04e3e4963a5606ac603d54a4f115de4a04 (diff)
downloadopie-fa581423c0ffcf35cbc403645e2131e84342dae4.zip
opie-fa581423c0ffcf35cbc403645e2131e84342dae4.tar.gz
opie-fa581423c0ffcf35cbc403645e2131e84342dae4.tar.bz2
ah, ok. I found the trick or better I found what I forgot :)
Means: When sending mail a progress dialog comes up.
Diffstat (limited to 'noncore/net/mail/libmailwrapper') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/sendmailprogress.cpp4
-rw-r--r--noncore/net/mail/libmailwrapper/sendmailprogressui.ui4
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.cpp15
3 files changed, 16 insertions, 7 deletions
diff --git a/noncore/net/mail/libmailwrapper/sendmailprogress.cpp b/noncore/net/mail/libmailwrapper/sendmailprogress.cpp
index 13ddd37..ef22750 100644
--- a/noncore/net/mail/libmailwrapper/sendmailprogress.cpp
+++ b/noncore/net/mail/libmailwrapper/sendmailprogress.cpp
@@ -1,48 +1,48 @@
1#include "sendmailprogress.h" 1#include "sendmailprogress.h"
2#include <qprogressbar.h> 2#include <qprogressbar.h>
3#include <qlabel.h> 3#include <qlabel.h>
4#include <qstring.h> 4#include <qstring.h>
5 5
6progressMailSend::progressMailSend(QWidget*parent, const char * name) 6progressMailSend::progressMailSend(QWidget*parent, const char * name)
7 :progressMailSendUI(parent,name,false),m_current_mail(0),m_current_single(0),m_max_mail(0),m_max_single(0) 7 :progressMailSendUI(parent,name,true),m_current_mail(0),m_current_single(0),m_max_mail(0),m_max_single(0)
8{ 8{
9} 9}
10 10
11progressMailSend::~progressMailSend() 11progressMailSend::~progressMailSend()
12{ 12{
13} 13}
14 14
15void progressMailSend::setMaxMails(unsigned int aMaxMails) 15void progressMailSend::setMaxMails(unsigned int aMaxMails)
16{ 16{
17 m_max_mail = aMaxMails; 17 m_max_mail = aMaxMails;
18 allMailProgressBar->setTotalSteps(aMaxMails); 18 allMailProgressBar->setTotalSteps(aMaxMails);
19 setMails(); 19 setMails();
20} 20}
21 21
22void progressMailSend::setCurrentMails(unsigned int aCurrent) 22void progressMailSend::setCurrentMails(unsigned int aCurrent)
23{ 23{
24 m_current_mail = aCurrent; 24 m_current_mail = aCurrent;
25 allMailProgressBar->setProgress(aCurrent); 25 allMailProgressBar->setProgress(aCurrent);
26 setMails(); 26 setMails();
27} 27}
28 28
29void progressMailSend::setSingleMail(unsigned int aCurrent,unsigned int aMax) 29void progressMailSend::setSingleMail(unsigned int aCurrent,unsigned int aMax)
30{ 30{
31 m_current_single = aCurrent; 31 m_current_single = aCurrent;
32 m_max_single = aMax; 32 m_max_single = aMax;
33 setSingle(); 33 setSingle();
34} 34}
35 35
36void progressMailSend::setSingle() 36void progressMailSend::setSingle()
37{ 37{
38 QString text = QString(tr("%1 of %2 bytes send")).arg(m_current_single).arg(m_max_single); 38 QString text = QString(tr("%1 of %2 bytes send")).arg(m_current_single).arg(m_max_single);
39 singleMailLabel->setText(text); 39 singleMailLabel->setText(text);
40 singleMailProgressBar->setTotalSteps(m_max_single); 40 singleMailProgressBar->setTotalSteps(m_max_single);
41 singleMailProgressBar->setProgress(m_current_single); 41 singleMailProgressBar->setProgress(m_current_single);
42} 42}
43 43
44void progressMailSend::setMails() 44void progressMailSend::setMails()
45{ 45{
46 QString text = QString(tr("Sending mail %1 of %2")).arg(m_current_single+1).arg(m_max_single); 46 QString text = QString(tr("Sending mail %1 of %2")).arg(m_current_mail+1).arg(m_max_mail);
47 allMailLabel->setText(text); 47 allMailLabel->setText(text);
48} 48}
diff --git a/noncore/net/mail/libmailwrapper/sendmailprogressui.ui b/noncore/net/mail/libmailwrapper/sendmailprogressui.ui
index b90b088..287ab5e 100644
--- a/noncore/net/mail/libmailwrapper/sendmailprogressui.ui
+++ b/noncore/net/mail/libmailwrapper/sendmailprogressui.ui
@@ -1,39 +1,39 @@
1<!DOCTYPE UI><UI> 1<!DOCTYPE UI><UI>
2<class>progressMailSendUI</class> 2<class>progressMailSendUI</class>
3<widget> 3<widget>
4 <class>QDialog</class> 4 <class>QDialog</class>
5 <property stdset="1"> 5 <property stdset="1">
6 <name>name</name> 6 <name>name</name>
7 <cstring>progressMailSendUI</cstring> 7 <cstring>progressMailSendUI</cstring>
8 </property> 8 </property>
9 <property stdset="1"> 9 <property stdset="1">
10 <name>geometry</name> 10 <name>geometry</name>
11 <rect> 11 <rect>
12 <x>0</x> 12 <x>0</x>
13 <y>0</y> 13 <y>0</y>
14 <width>316</width> 14 <width>221</width>
15 <height>266</height> 15 <height>127</height>
16 </rect> 16 </rect>
17 </property> 17 </property>
18 <property stdset="1"> 18 <property stdset="1">
19 <name>caption</name> 19 <name>caption</name>
20 <string>Sending mail</string> 20 <string>Sending mail</string>
21 </property> 21 </property>
22 <property> 22 <property>
23 <name>layoutMargin</name> 23 <name>layoutMargin</name>
24 </property> 24 </property>
25 <property> 25 <property>
26 <name>layoutSpacing</name> 26 <name>layoutSpacing</name>
27 </property> 27 </property>
28 <vbox> 28 <vbox>
29 <property stdset="1"> 29 <property stdset="1">
30 <name>margin</name> 30 <name>margin</name>
31 <number>4</number> 31 <number>4</number>
32 </property> 32 </property>
33 <property stdset="1"> 33 <property stdset="1">
34 <name>spacing</name> 34 <name>spacing</name>
35 <number>2</number> 35 <number>2</number>
36 </property> 36 </property>
37 <widget> 37 <widget>
38 <class>QLabel</class> 38 <class>QLabel</class>
39 <property stdset="1"> 39 <property stdset="1">
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
index 53c0af5..770e2b8 100644
--- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
@@ -504,49 +504,49 @@ void SMTPwrapper::writeToFile(const QString&file, mailmime *mail )
504 504
505void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size ) 505void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size )
506{ 506{
507 507
508 QFile msg_cache(file); 508 QFile msg_cache(file);
509 QString msg = ""; 509 QString msg = "";
510 msg_cache.open(IO_ReadOnly); 510 msg_cache.open(IO_ReadOnly);
511 char*message = new char[4096]; 511 char*message = new char[4096];
512 memset(message,0,4096); 512 memset(message,0,4096);
513 while (msg_cache.readBlock(message,4095)>0) { 513 while (msg_cache.readBlock(message,4095)>0) {
514 msg+=message; 514 msg+=message;
515 memset(message,0,4096); 515 memset(message,0,4096);
516 } 516 }
517 delete message; 517 delete message;
518 *data = (char*)malloc(msg.length()+1*sizeof(char)); 518 *data = (char*)malloc(msg.length()+1*sizeof(char));
519 memset(*data,0,msg.length()+1); 519 memset(*data,0,msg.length()+1);
520 memcpy(*data,msg.ascii(),msg.length()); 520 memcpy(*data,msg.ascii(),msg.length());
521 *size=msg.length(); 521 *size=msg.length();
522} 522}
523 523
524void SMTPwrapper::progress( size_t current, size_t maximum ) 524void SMTPwrapper::progress( size_t current, size_t maximum )
525{ 525{
526 if (SMTPwrapper::sendProgress) { 526 if (SMTPwrapper::sendProgress) {
527 SMTPwrapper::sendProgress->setSingleMail(current, maximum ); 527 SMTPwrapper::sendProgress->setSingleMail(current, maximum );
528 qDebug("%u of %u",current,maximum); 528 qApp->processEvents();
529 } 529 }
530} 530}
531 531
532void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) 532void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box)
533{ 533{
534 if (!mail) return; 534 if (!mail) return;
535 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); 535 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/");
536 MBOXwrapper*wrap = new MBOXwrapper(localfolders); 536 MBOXwrapper*wrap = new MBOXwrapper(localfolders);
537 wrap->storeMessage(mail,length,box); 537 wrap->storeMessage(mail,length,box);
538 delete wrap; 538 delete wrap;
539} 539}
540 540
541void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) 541void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp )
542{ 542{
543 clist *rcpts = 0; 543 clist *rcpts = 0;
544 char *from, *data; 544 char *from, *data;
545 size_t size; 545 size_t size;
546 546
547 if ( smtp == NULL ) { 547 if ( smtp == NULL ) {
548 return; 548 return;
549 } 549 }
550 from = data = 0; 550 from = data = 0;
551 551
552 QString file = getTmpFile(); 552 QString file = getTmpFile();
@@ -631,51 +631,51 @@ free_mem_session:
631 mailsmtp_free( session ); 631 mailsmtp_free( session );
632free_mem: 632free_mem:
633 if (rcpts) smtp_address_list_free( rcpts ); 633 if (rcpts) smtp_address_list_free( rcpts );
634 if (data) free( data ); 634 if (data) free( data );
635 if (server) free( server ); 635 if (server) free( server );
636 if (from) free( from ); 636 if (from) free( from );
637 if ( smtp->getLogin() ) { 637 if ( smtp->getLogin() ) {
638 free( user ); 638 free( user );
639 free( pass ); 639 free( pass );
640 } 640 }
641 return result; 641 return result;
642} 642}
643 643
644void SMTPwrapper::sendMail(const Mail&mail,bool later ) 644void SMTPwrapper::sendMail(const Mail&mail,bool later )
645{ 645{
646 mailmime * mimeMail; 646 mailmime * mimeMail;
647 647
648 SMTPaccount *smtp = getAccount(mail.getName()); 648 SMTPaccount *smtp = getAccount(mail.getName());
649 649
650 mimeMail = createMimeMail(mail ); 650 mimeMail = createMimeMail(mail );
651 if ( mimeMail == NULL ) { 651 if ( mimeMail == NULL ) {
652 qDebug( "sendMail: error creating mime mail" ); 652 qDebug( "sendMail: error creating mime mail" );
653 } else { 653 } else {
654 sendProgress = new progressMailSend(); 654 sendProgress = new progressMailSend();
655 sendProgress->showMaximized(); 655// sendProgress->showMaximized();
656 sendProgress->show(); 656 sendProgress->show();
657 qApp->processEvents(10); 657 sendProgress->setMaxMails(1);
658 smtpSend( mimeMail,later,smtp); 658 smtpSend( mimeMail,later,smtp);
659 mailmime_free( mimeMail ); 659 mailmime_free( mimeMail );
660 qDebug("Clean up done"); 660 qDebug("Clean up done");
661 sendProgress->hide(); 661 sendProgress->hide();
662 delete sendProgress; 662 delete sendProgress;
663 sendProgress = 0; 663 sendProgress = 0;
664 } 664 }
665} 665}
666 666
667int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which) 667int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which)
668{ 668{
669 char*data = 0; 669 char*data = 0;
670 size_t length = 0; 670 size_t length = 0;
671 size_t curTok = 0; 671 size_t curTok = 0;
672 mailimf_fields *fields = 0; 672 mailimf_fields *fields = 0;
673 mailimf_field*ffrom = 0; 673 mailimf_field*ffrom = 0;
674 clist *rcpts = 0; 674 clist *rcpts = 0;
675 char*from = 0; 675 char*from = 0;
676 676
677 wrap->fetchRawBody(*which,&data,&length); 677 wrap->fetchRawBody(*which,&data,&length);
678 if (!data) return 0; 678 if (!data) return 0;
679 int err = mailimf_fields_parse( data, length, &curTok, &fields ); 679 int err = mailimf_fields_parse( data, length, &curTok, &fields );
680 if (err != MAILIMF_NO_ERROR) { 680 if (err != MAILIMF_NO_ERROR) {
681 free(data); 681 free(data);
@@ -692,37 +692,46 @@ int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which)
692 return smtpSend(from,rcpts,data,strlen(data),smtp ); 692 return smtpSend(from,rcpts,data,strlen(data),smtp );
693 } 693 }
694 return 0; 694 return 0;
695} 695}
696 696
697/* this is a special fun */ 697/* this is a special fun */
698void SMTPwrapper::flushOutbox(SMTPaccount*smtp) 698void SMTPwrapper::flushOutbox(SMTPaccount*smtp)
699{ 699{
700 if (!smtp) return; 700 if (!smtp) return;
701 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); 701 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/");
702 MBOXwrapper*wrap = new MBOXwrapper(localfolders); 702 MBOXwrapper*wrap = new MBOXwrapper(localfolders);
703 if (!wrap) { 703 if (!wrap) {
704 qDebug("memory error"); 704 qDebug("memory error");
705 return; 705 return;
706 } 706 }
707 QList<RecMail> mailsToSend; 707 QList<RecMail> mailsToSend;
708 QList<RecMail> mailsToRemove; 708 QList<RecMail> mailsToRemove;
709 QString mbox("Outgoing"); 709 QString mbox("Outgoing");
710 wrap->listMessages(mbox,mailsToSend); 710 wrap->listMessages(mbox,mailsToSend);
711 if (mailsToSend.count()==0) { 711 if (mailsToSend.count()==0) {
712 delete wrap; 712 delete wrap;
713 return; 713 return;
714 } 714 }
715 mailsToSend.setAutoDelete(false); 715 mailsToSend.setAutoDelete(false);
716 sendProgress = new progressMailSend();
717// sendProgress->showMaximized();
718 sendProgress->show();
719 sendProgress->setMaxMails(mailsToSend.count());
720
716 while (mailsToSend.count()>0) { 721 while (mailsToSend.count()>0) {
717 if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { 722 if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) {
718 QMessageBox::critical(0,tr("Error sending mail"), 723 QMessageBox::critical(0,tr("Error sending mail"),
719 tr("Error sending queued mail - breaking")); 724 tr("Error sending queued mail - breaking"));
720 break; 725 break;
721 } 726 }
722 mailsToRemove.append(mailsToSend.at(0)); 727 mailsToRemove.append(mailsToSend.at(0));
723 mailsToSend.removeFirst(); 728 mailsToSend.removeFirst();
729 sendProgress->setCurrentMails(mailsToRemove.count());
724 } 730 }
731 sendProgress->hide();
732 delete sendProgress;
733 sendProgress = 0;
725 wrap->deleteMails(mbox,mailsToRemove); 734 wrap->deleteMails(mbox,mailsToRemove);
726 mailsToSend.setAutoDelete(true); 735 mailsToSend.setAutoDelete(true);
727 delete wrap; 736 delete wrap;
728} 737}