summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show 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
-rw-r--r--noncore/net/mail/sendmailprogress.cpp4
-rw-r--r--noncore/net/mail/sendmailprogressui.ui4
-rw-r--r--noncore/net/mail/smtpwrapper.cpp15
6 files changed, 32 insertions, 14 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 @@
#include "sendmailprogress.h"
#include <qprogressbar.h>
#include <qlabel.h>
#include <qstring.h>
progressMailSend::progressMailSend(QWidget*parent, const char * name)
- :progressMailSendUI(parent,name,false),m_current_mail(0),m_current_single(0),m_max_mail(0),m_max_single(0)
+ :progressMailSendUI(parent,name,true),m_current_mail(0),m_current_single(0),m_max_mail(0),m_max_single(0)
{
}
progressMailSend::~progressMailSend()
{
}
void progressMailSend::setMaxMails(unsigned int aMaxMails)
{
m_max_mail = aMaxMails;
allMailProgressBar->setTotalSteps(aMaxMails);
setMails();
}
void progressMailSend::setCurrentMails(unsigned int aCurrent)
{
m_current_mail = aCurrent;
allMailProgressBar->setProgress(aCurrent);
setMails();
}
void progressMailSend::setSingleMail(unsigned int aCurrent,unsigned int aMax)
{
m_current_single = aCurrent;
m_max_single = aMax;
setSingle();
}
void progressMailSend::setSingle()
{
QString text = QString(tr("%1 of %2 bytes send")).arg(m_current_single).arg(m_max_single);
singleMailLabel->setText(text);
singleMailProgressBar->setTotalSteps(m_max_single);
singleMailProgressBar->setProgress(m_current_single);
}
void progressMailSend::setMails()
{
- QString text = QString(tr("Sending mail %1 of %2")).arg(m_current_single+1).arg(m_max_single);
+ QString text = QString(tr("Sending mail %1 of %2")).arg(m_current_mail+1).arg(m_max_mail);
allMailLabel->setText(text);
}
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,63 +1,63 @@
<!DOCTYPE UI><UI>
<class>progressMailSendUI</class>
<widget>
<class>QDialog</class>
<property stdset="1">
<name>name</name>
<cstring>progressMailSendUI</cstring>
</property>
<property stdset="1">
<name>geometry</name>
<rect>
<x>0</x>
<y>0</y>
- <width>316</width>
- <height>266</height>
+ <width>221</width>
+ <height>127</height>
</rect>
</property>
<property stdset="1">
<name>caption</name>
<string>Sending mail</string>
</property>
<property>
<name>layoutMargin</name>
</property>
<property>
<name>layoutSpacing</name>
</property>
<vbox>
<property stdset="1">
<name>margin</name>
<number>4</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>2</number>
</property>
<widget>
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>singleMailLabel</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>Progress of mail</string>
</property>
<property stdset="1">
<name>alignment</name>
<set>AlignCenter</set>
</property>
<property>
<name>hAlign</name>
</property>
</widget>
<widget>
<class>QProgressBar</class>
<property stdset="1">
<name>name</name>
<cstring>singleMailProgressBar</cstring>
</property>
</widget>
<widget>
<class>QLabel</class>
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
@@ -480,97 +480,97 @@ QString SMTPwrapper::getTmpFile() {
return "/tmp/opiemail-tmp-" + unique;
}
void SMTPwrapper::writeToFile(const QString&file, mailmime *mail )
{
FILE *f;
int err, col = 0;
f = fopen( file.latin1(), "w" );
if ( f == NULL ) {
qDebug( "writeToFile: error opening file" );
return;
}
err = mailmime_write( f, &col, mail );
if ( err != MAILIMF_NO_ERROR ) {
fclose( f );
qDebug( "writeToFile: error writing mailmime" );
return;
}
fclose( f );
}
void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size )
{
QFile msg_cache(file);
QString msg = "";
msg_cache.open(IO_ReadOnly);
char*message = new char[4096];
memset(message,0,4096);
while (msg_cache.readBlock(message,4095)>0) {
msg+=message;
memset(message,0,4096);
}
delete message;
*data = (char*)malloc(msg.length()+1*sizeof(char));
memset(*data,0,msg.length()+1);
memcpy(*data,msg.ascii(),msg.length());
*size=msg.length();
}
void SMTPwrapper::progress( size_t current, size_t maximum )
{
if (SMTPwrapper::sendProgress) {
SMTPwrapper::sendProgress->setSingleMail(current, maximum );
- qDebug("%u of %u",current,maximum);
+ qApp->processEvents();
}
}
void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box)
{
if (!mail) return;
QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/");
MBOXwrapper*wrap = new MBOXwrapper(localfolders);
wrap->storeMessage(mail,length,box);
delete wrap;
}
void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp )
{
clist *rcpts = 0;
char *from, *data;
size_t size;
if ( smtp == NULL ) {
return;
}
from = data = 0;
QString file = getTmpFile();
writeToFile( file, mail );
readFromFile( file, &data, &size );
QFile f( file );
f.remove();
if (later) {
storeMail(data,size,"Outgoing");
if (data) free( data );
return;
}
from = getFrom( mail );
rcpts = createRcptList( mail->mm_data.mm_message.mm_fields );
smtpSend(from,rcpts,data,size,smtp);
}
int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp )
{
char *server, *user, *pass;
bool ssl;
uint16_t port;
mailsmtp *session;
int err,result;
result = 1;
@@ -607,122 +607,131 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccou
user = strdup( login.getUser().latin1() );
pass = strdup( login.getPassword().latin1() );
} else {
result = 0; goto free_con_session;
}
} else {
user = strdup( smtp->getUser().latin1() );
pass = strdup( smtp->getPassword().latin1() );
}
qDebug( "session->auth: %i", session->auth);
err = mailsmtp_auth( session, user, pass );
if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok");
qDebug( "Done auth!" );
}
err = mailsmtp_send( session, from, rcpts, data, size );
if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;}
qDebug( "Mail sent." );
storeMail(data,size,"Sent");
free_con_session:
mailsmtp_quit( session );
free_mem_session:
mailsmtp_free( session );
free_mem:
if (rcpts) smtp_address_list_free( rcpts );
if (data) free( data );
if (server) free( server );
if (from) free( from );
if ( smtp->getLogin() ) {
free( user );
free( pass );
}
return result;
}
void SMTPwrapper::sendMail(const Mail&mail,bool later )
{
mailmime * mimeMail;
SMTPaccount *smtp = getAccount(mail.getName());
mimeMail = createMimeMail(mail );
if ( mimeMail == NULL ) {
qDebug( "sendMail: error creating mime mail" );
} else {
sendProgress = new progressMailSend();
- sendProgress->showMaximized();
+// sendProgress->showMaximized();
sendProgress->show();
- qApp->processEvents(10);
+ sendProgress->setMaxMails(1);
smtpSend( mimeMail,later,smtp);
mailmime_free( mimeMail );
qDebug("Clean up done");
sendProgress->hide();
delete sendProgress;
sendProgress = 0;
}
}
int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which)
{
char*data = 0;
size_t length = 0;
size_t curTok = 0;
mailimf_fields *fields = 0;
mailimf_field*ffrom = 0;
clist *rcpts = 0;
char*from = 0;
wrap->fetchRawBody(*which,&data,&length);
if (!data) return 0;
int err = mailimf_fields_parse( data, length, &curTok, &fields );
if (err != MAILIMF_NO_ERROR) {
free(data);
delete wrap;
return 0;
}
rcpts = createRcptList( fields );
ffrom = getField(fields, MAILIMF_FIELD_FROM );
from = getFrom(ffrom);
qDebug("Size: %i vs. %i",length,strlen(data));
if (rcpts && from) {
return smtpSend(from,rcpts,data,strlen(data),smtp );
}
return 0;
}
/* this is a special fun */
void SMTPwrapper::flushOutbox(SMTPaccount*smtp)
{
if (!smtp) return;
QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/");
MBOXwrapper*wrap = new MBOXwrapper(localfolders);
if (!wrap) {
qDebug("memory error");
return;
}
QList<RecMail> mailsToSend;
QList<RecMail> mailsToRemove;
QString mbox("Outgoing");
wrap->listMessages(mbox,mailsToSend);
if (mailsToSend.count()==0) {
delete wrap;
return;
}
mailsToSend.setAutoDelete(false);
+ sendProgress = new progressMailSend();
+// sendProgress->showMaximized();
+ sendProgress->show();
+ sendProgress->setMaxMails(mailsToSend.count());
+
while (mailsToSend.count()>0) {
if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) {
QMessageBox::critical(0,tr("Error sending mail"),
tr("Error sending queued mail - breaking"));
break;
}
mailsToRemove.append(mailsToSend.at(0));
mailsToSend.removeFirst();
+ sendProgress->setCurrentMails(mailsToRemove.count());
}
+ sendProgress->hide();
+ delete sendProgress;
+ sendProgress = 0;
wrap->deleteMails(mbox,mailsToRemove);
mailsToSend.setAutoDelete(true);
delete wrap;
}
diff --git a/noncore/net/mail/sendmailprogress.cpp b/noncore/net/mail/sendmailprogress.cpp
index 13ddd37..ef22750 100644
--- a/noncore/net/mail/sendmailprogress.cpp
+++ b/noncore/net/mail/sendmailprogress.cpp
@@ -1,48 +1,48 @@
#include "sendmailprogress.h"
#include <qprogressbar.h>
#include <qlabel.h>
#include <qstring.h>
progressMailSend::progressMailSend(QWidget*parent, const char * name)
- :progressMailSendUI(parent,name,false),m_current_mail(0),m_current_single(0),m_max_mail(0),m_max_single(0)
+ :progressMailSendUI(parent,name,true),m_current_mail(0),m_current_single(0),m_max_mail(0),m_max_single(0)
{
}
progressMailSend::~progressMailSend()
{
}
void progressMailSend::setMaxMails(unsigned int aMaxMails)
{
m_max_mail = aMaxMails;
allMailProgressBar->setTotalSteps(aMaxMails);
setMails();
}
void progressMailSend::setCurrentMails(unsigned int aCurrent)
{
m_current_mail = aCurrent;
allMailProgressBar->setProgress(aCurrent);
setMails();
}
void progressMailSend::setSingleMail(unsigned int aCurrent,unsigned int aMax)
{
m_current_single = aCurrent;
m_max_single = aMax;
setSingle();
}
void progressMailSend::setSingle()
{
QString text = QString(tr("%1 of %2 bytes send")).arg(m_current_single).arg(m_max_single);
singleMailLabel->setText(text);
singleMailProgressBar->setTotalSteps(m_max_single);
singleMailProgressBar->setProgress(m_current_single);
}
void progressMailSend::setMails()
{
- QString text = QString(tr("Sending mail %1 of %2")).arg(m_current_single+1).arg(m_max_single);
+ QString text = QString(tr("Sending mail %1 of %2")).arg(m_current_mail+1).arg(m_max_mail);
allMailLabel->setText(text);
}
diff --git a/noncore/net/mail/sendmailprogressui.ui b/noncore/net/mail/sendmailprogressui.ui
index b90b088..287ab5e 100644
--- a/noncore/net/mail/sendmailprogressui.ui
+++ b/noncore/net/mail/sendmailprogressui.ui
@@ -1,63 +1,63 @@
<!DOCTYPE UI><UI>
<class>progressMailSendUI</class>
<widget>
<class>QDialog</class>
<property stdset="1">
<name>name</name>
<cstring>progressMailSendUI</cstring>
</property>
<property stdset="1">
<name>geometry</name>
<rect>
<x>0</x>
<y>0</y>
- <width>316</width>
- <height>266</height>
+ <width>221</width>
+ <height>127</height>
</rect>
</property>
<property stdset="1">
<name>caption</name>
<string>Sending mail</string>
</property>
<property>
<name>layoutMargin</name>
</property>
<property>
<name>layoutSpacing</name>
</property>
<vbox>
<property stdset="1">
<name>margin</name>
<number>4</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>2</number>
</property>
<widget>
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>singleMailLabel</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>Progress of mail</string>
</property>
<property stdset="1">
<name>alignment</name>
<set>AlignCenter</set>
</property>
<property>
<name>hAlign</name>
</property>
</widget>
<widget>
<class>QProgressBar</class>
<property stdset="1">
<name>name</name>
<cstring>singleMailProgressBar</cstring>
</property>
</widget>
<widget>
<class>QLabel</class>
diff --git a/noncore/net/mail/smtpwrapper.cpp b/noncore/net/mail/smtpwrapper.cpp
index 53c0af5..770e2b8 100644
--- a/noncore/net/mail/smtpwrapper.cpp
+++ b/noncore/net/mail/smtpwrapper.cpp
@@ -480,97 +480,97 @@ QString SMTPwrapper::getTmpFile() {
return "/tmp/opiemail-tmp-" + unique;
}
void SMTPwrapper::writeToFile(const QString&file, mailmime *mail )
{
FILE *f;
int err, col = 0;
f = fopen( file.latin1(), "w" );
if ( f == NULL ) {
qDebug( "writeToFile: error opening file" );
return;
}
err = mailmime_write( f, &col, mail );
if ( err != MAILIMF_NO_ERROR ) {
fclose( f );
qDebug( "writeToFile: error writing mailmime" );
return;
}
fclose( f );
}
void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size )
{
QFile msg_cache(file);
QString msg = "";
msg_cache.open(IO_ReadOnly);
char*message = new char[4096];
memset(message,0,4096);
while (msg_cache.readBlock(message,4095)>0) {
msg+=message;
memset(message,0,4096);
}
delete message;
*data = (char*)malloc(msg.length()+1*sizeof(char));
memset(*data,0,msg.length()+1);
memcpy(*data,msg.ascii(),msg.length());
*size=msg.length();
}
void SMTPwrapper::progress( size_t current, size_t maximum )
{
if (SMTPwrapper::sendProgress) {
SMTPwrapper::sendProgress->setSingleMail(current, maximum );
- qDebug("%u of %u",current,maximum);
+ qApp->processEvents();
}
}
void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box)
{
if (!mail) return;
QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/");
MBOXwrapper*wrap = new MBOXwrapper(localfolders);
wrap->storeMessage(mail,length,box);
delete wrap;
}
void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp )
{
clist *rcpts = 0;
char *from, *data;
size_t size;
if ( smtp == NULL ) {
return;
}
from = data = 0;
QString file = getTmpFile();
writeToFile( file, mail );
readFromFile( file, &data, &size );
QFile f( file );
f.remove();
if (later) {
storeMail(data,size,"Outgoing");
if (data) free( data );
return;
}
from = getFrom( mail );
rcpts = createRcptList( mail->mm_data.mm_message.mm_fields );
smtpSend(from,rcpts,data,size,smtp);
}
int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp )
{
char *server, *user, *pass;
bool ssl;
uint16_t port;
mailsmtp *session;
int err,result;
result = 1;
@@ -607,122 +607,131 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccou
user = strdup( login.getUser().latin1() );
pass = strdup( login.getPassword().latin1() );
} else {
result = 0; goto free_con_session;
}
} else {
user = strdup( smtp->getUser().latin1() );
pass = strdup( smtp->getPassword().latin1() );
}
qDebug( "session->auth: %i", session->auth);
err = mailsmtp_auth( session, user, pass );
if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok");
qDebug( "Done auth!" );
}
err = mailsmtp_send( session, from, rcpts, data, size );
if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;}
qDebug( "Mail sent." );
storeMail(data,size,"Sent");
free_con_session:
mailsmtp_quit( session );
free_mem_session:
mailsmtp_free( session );
free_mem:
if (rcpts) smtp_address_list_free( rcpts );
if (data) free( data );
if (server) free( server );
if (from) free( from );
if ( smtp->getLogin() ) {
free( user );
free( pass );
}
return result;
}
void SMTPwrapper::sendMail(const Mail&mail,bool later )
{
mailmime * mimeMail;
SMTPaccount *smtp = getAccount(mail.getName());
mimeMail = createMimeMail(mail );
if ( mimeMail == NULL ) {
qDebug( "sendMail: error creating mime mail" );
} else {
sendProgress = new progressMailSend();
- sendProgress->showMaximized();
+// sendProgress->showMaximized();
sendProgress->show();
- qApp->processEvents(10);
+ sendProgress->setMaxMails(1);
smtpSend( mimeMail,later,smtp);
mailmime_free( mimeMail );
qDebug("Clean up done");
sendProgress->hide();
delete sendProgress;
sendProgress = 0;
}
}
int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which)
{
char*data = 0;
size_t length = 0;
size_t curTok = 0;
mailimf_fields *fields = 0;
mailimf_field*ffrom = 0;
clist *rcpts = 0;
char*from = 0;
wrap->fetchRawBody(*which,&data,&length);
if (!data) return 0;
int err = mailimf_fields_parse( data, length, &curTok, &fields );
if (err != MAILIMF_NO_ERROR) {
free(data);
delete wrap;
return 0;
}
rcpts = createRcptList( fields );
ffrom = getField(fields, MAILIMF_FIELD_FROM );
from = getFrom(ffrom);
qDebug("Size: %i vs. %i",length,strlen(data));
if (rcpts && from) {
return smtpSend(from,rcpts,data,strlen(data),smtp );
}
return 0;
}
/* this is a special fun */
void SMTPwrapper::flushOutbox(SMTPaccount*smtp)
{
if (!smtp) return;
QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/");
MBOXwrapper*wrap = new MBOXwrapper(localfolders);
if (!wrap) {
qDebug("memory error");
return;
}
QList<RecMail> mailsToSend;
QList<RecMail> mailsToRemove;
QString mbox("Outgoing");
wrap->listMessages(mbox,mailsToSend);
if (mailsToSend.count()==0) {
delete wrap;
return;
}
mailsToSend.setAutoDelete(false);
+ sendProgress = new progressMailSend();
+// sendProgress->showMaximized();
+ sendProgress->show();
+ sendProgress->setMaxMails(mailsToSend.count());
+
while (mailsToSend.count()>0) {
if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) {
QMessageBox::critical(0,tr("Error sending mail"),
tr("Error sending queued mail - breaking"));
break;
}
mailsToRemove.append(mailsToSend.at(0));
mailsToSend.removeFirst();
+ sendProgress->setCurrentMails(mailsToRemove.count());
}
+ sendProgress->hide();
+ delete sendProgress;
+ sendProgress = 0;
wrap->deleteMails(mbox,mailsToRemove);
mailsToSend.setAutoDelete(true);
delete wrap;
}