summaryrefslogtreecommitdiffabout
path: root/kmicromail
Side-by-side diff
Diffstat (limited to 'kmicromail') (more/less context) (show whitespace changes)
-rw-r--r--kmicromail/editaccounts.cpp12
-rw-r--r--kmicromail/libmailwrapper/smtpwrapper.cpp17
2 files changed, 25 insertions, 4 deletions
diff --git a/kmicromail/editaccounts.cpp b/kmicromail/editaccounts.cpp
index 49049f6..2c0f2d8 100644
--- a/kmicromail/editaccounts.cpp
+++ b/kmicromail/editaccounts.cpp
@@ -326,57 +326,59 @@ void SelectMailType::slotSelection( const QString &sel )
*/
IMAPconfig::IMAPconfig( IMAPaccount *account, QWidget *parent, const char *name, bool modal, WFlags flags )
: IMAPconfigUI( parent, name, modal, flags )
{
data = account;
//fillValues();
connect( ComboBox1, SIGNAL( activated(int) ), SLOT( slotConnectionToggle(int) ) );
ComboBox1->insertItem( "Only if available", 0 );
ComboBox1->insertItem( "Always, Negotiated", 1 );
ComboBox1->insertItem( "Connect on secure port", 2 );
ComboBox1->insertItem( "Run command instead", 3 );
CommandEdit->hide();
fillValues();
// ComboBox1->setCurrentItem( data->ConnectionType() );
}
void IMAPconfig::slotConnectionToggle( int index )
{
if ( index == 2 )
{
portLine->setText( IMAP_SSL_PORT );
+ CommandEdit->hide();
}
else if ( index == 3 )
{
portLine->setText( IMAP_PORT );
CommandEdit->show();
}
else
{
portLine->setText( IMAP_PORT );
+ CommandEdit->hide();
}
}
void IMAPconfig::fillValues()
{
accountLine->setText( data->getAccountName() );
serverLine->setText( data->getServer() );
portLine->setText( data->getPort() );
ComboBox1->setCurrentItem( data->ConnectionType() );
userLine->setText( data->getUser() );
passLine->setText( data->getPassword() );
prefixLine->setText(data->getPrefix());
localFolder->setText( data->getLocalFolder() );
int max = data->getMaxMailSize() ;
if ( max ) {
CheckBoxDown->setChecked( true );
SpinBoxDown->setValue ( max );
} else {
CheckBoxDown->setChecked( false );
SpinBoxDown->setValue ( 5 );
}
CheckBoxLeaveOn->setChecked( data->getLeaveOnServer() );
}
@@ -407,57 +409,59 @@ void IMAPconfig::accept()
*/
POP3config::POP3config( POP3account *account, QWidget *parent, const char *name, bool modal, WFlags flags )
: POP3configUI( parent, name, modal, flags )
{
data = account;
//fillValues();
connect( ComboBox1, SIGNAL( activated(int) ), SLOT( slotConnectionToggle(int) ) );
ComboBox1->insertItem( "Only if available", 0 );
ComboBox1->insertItem( "Always, Negotiated", 1 );
ComboBox1->insertItem( "Connect on secure port", 2 );
ComboBox1->insertItem( "Run command instead", 3 );
CommandEdit->hide();
fillValues();
//ComboBox1->setCurrentItem( data->ConnectionType() );
}
void POP3config::slotConnectionToggle( int index )
{
// 2 is ssl connection
if ( index == 2 )
{
portLine->setText( POP3_SSL_PORT );
+ CommandEdit->hide();
}
else if ( index == 3 )
{
portLine->setText( POP3_PORT );
CommandEdit->show();
}
else
{
portLine->setText( POP3_PORT );
+ CommandEdit->hide();
}
}
void POP3config::fillValues()
{
accountLine->setText( data->getAccountName() );
serverLine->setText( data->getServer() );
portLine->setText( data->getPort() );
ComboBox1->setCurrentItem( data->ConnectionType() );
userLine->setText( data->getUser() );
passLine->setText( data->getPassword() );
localFolder->setText( data->getLocalFolder() );
int max = data->getMaxMailSize() ;
if ( max ) {
CheckBoxDown->setChecked( true );
SpinBoxDown->setValue ( max );
} else {
CheckBoxDown->setChecked( false );
SpinBoxDown->setValue ( 5 );
}
CheckBoxLeaveOn->setChecked( data->getLeaveOnServer() );
}
void POP3config::accept()
@@ -499,61 +503,63 @@ SMTPconfig::SMTPconfig( SMTPaccount *account, QWidget *parent, const char *name,
icon = SmallIcon("fileopen");
SignaturButton->setText("");
SignaturButton->setIconSet (icon ) ;
SignaturButton->setMaximumSize ( SignaturButton->sizeHint().height()+4,SignaturButton->sizeHint().height()) ;
connect( SignaturButton, SIGNAL( clicked() ), this, SLOT( chooseSig() ) );
connect( ComboBox1, SIGNAL( activated(int) ), SLOT( slotConnectionToggle(int) ) );
ComboBox1->insertItem( "No secure connection, no TLS", 0 );
ComboBox1->insertItem( "Only if available, try TLS", 1 );
ComboBox1->insertItem( "Always, use TLS", 2 );
ComboBox1->insertItem( "Connect on secure port (SSL)", 3 );
ComboBox1->insertItem( "Run command instead", 4 );
CommandEdit->hide();
fillValues();
//ComboBox1->setCurrentItem( data->ConnectionType() );
}
void SMTPconfig::chooseSig()
{
QString lnk = KFileDialog::getOpenFileName( "", "Choose Signatur File", this );
if ( !lnk.isEmpty() ) {
SignaturEdit->setText( lnk );
}
}
void SMTPconfig::slotConnectionToggle( int index )
{
- // 2 is ssl connection
- if ( index == 2 )
+ // 3 is ssl connection
+ if ( index == 3 )
{
portLine->setText( SMTP_SSL_PORT );
+ CommandEdit->hide();
}
- else if ( index == 3 )
+ else if ( index == 4 )
{
portLine->setText( SMTP_PORT );
CommandEdit->show();
}
else
{
portLine->setText( SMTP_PORT );
+ CommandEdit->hide();
}
}
void SMTPconfig::fillValues()
{
accountLine->setText( data->getAccountName() );
serverLine->setText( data->getServer() );
portLine->setText( data->getPort() );
ComboBox1->setCurrentItem( data->ConnectionType() );
loginBox->setChecked( data->getLogin() );
userLine->setText( data->getUser() );
passLine->setText( data->getPassword() );
SignaturEdit->setText( data->getSigFile() );
}
void SMTPconfig::accept()
{
data->setAccountName( accountLine->text() );
data->setServer( serverLine->text() );
data->setPort( portLine->text() );
data->setConnectionType( ComboBox1->currentItem() );
data->setLogin( loginBox->isChecked() );
data->setUser( userLine->text() );
data->setPassword( passLine->text() );
diff --git a/kmicromail/libmailwrapper/smtpwrapper.cpp b/kmicromail/libmailwrapper/smtpwrapper.cpp
index 872a460..845c71c 100644
--- a/kmicromail/libmailwrapper/smtpwrapper.cpp
+++ b/kmicromail/libmailwrapper/smtpwrapper.cpp
@@ -223,94 +223,100 @@ void SMTPwrapper::connect_server()
; // odebug << "Servername " << server << " at port " << port << "" << oendl;
if ( ssl ) {
qDebug("smtp: ssl_connect ");
err = mailsmtp_ssl_connect( m_smtp, server.latin1(), port );
} else {
; // odebug << "No SSL session" << oendl;
err = mailsmtp_socket_connect( m_smtp, server.latin1(), port );
}
if ( err != MAILSMTP_NO_ERROR ) {
qDebug("Error init SMTP connection" );
failuretext = i18n("Error init SMTP connection:\n%1").arg(mailsmtpError(err));
result = 0;
}
qDebug("SMTP connection inited ");
/* switch to tls after init 'cause there it will send the ehlo */
if (result) {
err = mailsmtp_init( m_smtp );
if (err != MAILSMTP_NO_ERROR) {
result = 0;
qDebug("Error init SMTP connection ");
failuretext = i18n("Error init SMTP connection:\n%1").arg(mailsmtpError(err));
}
}
- if (try_tls) {
+ if (result && try_tls) {
qDebug("Smpt: Try tls ");
err = start_smtp_tls();
if (err != MAILSMTP_NO_ERROR) {
try_tls = false;
qDebug("no tls ");
} else {
err = mailesmtp_ehlo(m_smtp);
+ if ( err != MAILSMTP_NO_ERROR )
+ result = 0;
}
}
//qDebug("mailesmtp_ehlo %d ",err );
if (!try_tls && force_tls) {
result = 0;
failuretext = i18n("Error init SMTP tls:%1").arg(mailsmtpError(err));
}
if (result==1 && m_SmtpAccount->getLogin() ) {
; // odebug << "smtp with auth" << oendl;
if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) {
// get'em
LoginDialog login( m_SmtpAccount->getUser(),
m_SmtpAccount->getPassword(), NULL, 0, true );
login.show();
if ( QDialog::Accepted == login.exec() ) {
// ok
user = login.getUser();
pass = login.getPassword();
} else {
result = 0;
failuretext=i18n("Login aborted - \nstoring mail to localfolder");
}
} else {
user = m_SmtpAccount->getUser();
pass = m_SmtpAccount->getPassword();
}
; // odebug << "session->auth: " << m_smtp->auth << "" << oendl;
if (result) {
err = mailsmtp_auth( m_smtp, (char*)user.latin1(), (char*)pass.latin1() );
if ( err == MAILSMTP_NO_ERROR ) {
qDebug("Smtp authentification ok ");
} else {
failuretext = i18n("Authentification failed");
result = 0;
}
}
}
+ if ( result == 0 ) {
+ mailsmtp_free(m_smtp);
+ m_smtp = 0;
+ }
}
void SMTPwrapper::disc_server()
{
if (m_smtp) {
mailsmtp_quit( m_smtp );
mailsmtp_free( m_smtp );
m_smtp = 0;
}
}
int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size )
{
int err,result;
QString failuretext = "";
connect_server();
result = 1;
if (m_smtp) {
err = mailsmtp_send( m_smtp, from, rcpts, data, size );
if ( err != MAILSMTP_NO_ERROR ) {
qDebug("Error sending mail");
failuretext=i18n("Error sending mail:\n%1").arg(mailsmtpError(err));
@@ -326,48 +332,52 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size )
; // odebug << "Mail sent." << oendl;
storeMail(data,size,"Sent");
}
return result;
}
bool SMTPwrapper::sendMail(const Opie::Core::OSmartPointer<Mail>&mail,bool later )
{
mailmime * mimeMail;
bool result = true;
mimeMail = createMimeMail(mail );
if ( mimeMail == 0 ) {
qDebug("SMTP wrapper:Error creating mail! ");
return false;
} else {
sendProgress = new progressMailSend();
sendProgress->show();
sendProgress->setMaxMails(1);
result = smtpSend( mimeMail,later);
; // odebug << "Clean up done" << oendl;
sendProgress->hide();
delete sendProgress;
sendProgress = 0;
mailmime_free( mimeMail );
+ if ( m_smtp ) {
+ mailsmtp_free(m_smtp);
+ m_smtp = 0;
+ }
}
return result;
}
int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,const RecMailP&which) {
size_t curTok = 0;
mailimf_fields *fields = 0;
mailimf_field*ffrom = 0;
clist *rcpts = 0;
char*from = 0;
int res = 0;
encodedString * data = wrap->fetchRawBody(which);
if (!data)
return 0;
int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields );
if (err != MAILIMF_NO_ERROR) {
delete data;
delete wrap;
return 0;
}
rcpts = createRcptList( fields );
ffrom = getField(fields, MAILIMF_FIELD_FROM );
@@ -437,36 +447,41 @@ bool SMTPwrapper::flushOutbox() {
} else {
return true;
}
}
sendProgress = new progressMailSend();
sendProgress->show();
sendProgress->setMaxMails(mailsToSend.count());
while (returnValue && mailsToSend.count()>0) {
if (sendQueuedMail(wrap, (*mailsToSend.begin()))==0) {
QMessageBox::critical(0,i18n("Error sending mail"),
i18n("Error sending queued mail.\nBreaking."));
returnValue = false;
}
mailsToRemove.append((*mailsToSend.begin()));
mailsToSend.remove(mailsToSend.begin());
sendProgress->setCurrentMails(mailsToRemove.count());
}
if (reset_user_value) {
m_SmtpAccount->setUser(oldUser);
m_SmtpAccount->setPassword(oldPw);
}
+
KConfig cfg( locateLocal("config", "kopiemailrc" ) );
cfg.setGroup( "Status" );
m_queuedMail = mailsToSend.count();
cfg.writeEntry( "outgoing", m_queuedMail );
emit queuedMails( m_queuedMail );
sendProgress->hide();
delete sendProgress;
sendProgress = 0;
wrap->deleteMails(mbox,mailsToRemove);
delete wrap;
+ if ( m_smtp ) {
+ mailsmtp_free(m_smtp);
+ m_smtp = 0;
+ }
return returnValue;
}