-rw-r--r-- | kmicromail/editaccounts.cpp | 24 | ||||
-rw-r--r-- | kmicromail/libetpan/tools/mailstream_socket.c | 2 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/smtpwrapper.cpp | 8 |
3 files changed, 20 insertions, 14 deletions
diff --git a/kmicromail/editaccounts.cpp b/kmicromail/editaccounts.cpp index f1075c0..49049f6 100644 --- a/kmicromail/editaccounts.cpp +++ b/kmicromail/editaccounts.cpp @@ -1,693 +1,697 @@ #include <qdialog.h> #include "kapplication.h" #include "defines.h" #include "editaccounts.h" /* OPIE */ #include <qpe/qpeapplication.h> /* QT */ #include <qstringlist.h> #include <qcombobox.h> #include <qcheckbox.h> #include <qmessagebox.h> #include <qpushbutton.h> #include <qlineedit.h> #include <qlabel.h> #include <qtabwidget.h> #include <qlistview.h> #include <qspinbox.h> #include <klocale.h> #include <kfiledialog.h> #include <libmailwrapper/nntpwrapper.h> using namespace Opie::Core; AccountListItem::AccountListItem( QListView *parent, Account *a) : QListViewItem( parent ) { account = a; setText( 0, account->getAccountName() ); QString ttext = ""; switch (account->getType()) { case MAILLIB::A_NNTP: ttext="NNTP"; break; case MAILLIB::A_POP3: ttext = "POP3"; break; case MAILLIB::A_IMAP: ttext = "IMAP"; break; case MAILLIB::A_SMTP: ttext = "SMTP"; break; default: ttext = "UNKNOWN"; break; } setText( 1, ttext); } EditAccounts::EditAccounts( Settings *s, QWidget *parent, const char *name, bool modal, WFlags flags ) : EditAccountsUI( parent, name, modal, flags ) { settings = s; mailList->addColumn( i18n( "Account" ) ); mailList->addColumn( i18n( "Type" ) ); newsList->addColumn( i18n( "Account" ) ); connect( newMail, SIGNAL( clicked() ), SLOT( slotNewMail() ) ); connect( editMail, SIGNAL( clicked() ), SLOT( slotEditMail() ) ); connect( deleteMail, SIGNAL( clicked() ), SLOT( slotDeleteMail() ) ); connect( newNews, SIGNAL( clicked() ), SLOT( slotNewNews() ) ); connect( editNews, SIGNAL( clicked() ), SLOT( slotEditNews() ) ); connect( deleteNews, SIGNAL( clicked() ), SLOT( slotDeleteNews() ) ); slotFillLists(); } void EditAccounts::slotFillLists() { mailList->clear(); newsList->clear(); QList<Account> accounts = settings->getAccounts(); Account *it; for ( it = accounts.first(); it; it = accounts.next() ) { if ( it->getType()==MAILLIB::A_NNTP ) { (void) new AccountListItem( newsList, it ); } else { (void) new AccountListItem( mailList, it ); } } } void EditAccounts::slotNewMail() { QString *selection = new QString(); SelectMailType selType( selection, this, 0, true ); selType.show(); if ( QDialog::Accepted == selType.exec() ) { slotNewAccount( *selection ); } } void EditAccounts::slotNewAccount( const QString &type ) { if ( type.compare( i18n("IMAP") ) == 0 ) { IMAPaccount *account = new IMAPaccount(); IMAPconfig imap( account, this, 0, true ); #ifndef DESKTOP_VERSION imap.showMaximized(); #endif if ( QDialog::Accepted == imap.exec() ) { settings->addAccount( account ); account->save(); slotFillLists(); } else { account->remove(); } } else if ( type.compare( i18n("POP3") ) == 0 ) { POP3account *account = new POP3account(); POP3config pop3( account, this, 0, true, WStyle_ContextHelp ); if ( QDialog::Accepted == KApplication::execDialog( &pop3 ) ) { settings->addAccount( account ); account->save(); slotFillLists(); } else { account->remove(); } } else if ( type.compare( i18n("SMTP") ) == 0 ) { SMTPaccount *account = new SMTPaccount(); SMTPconfig smtp( account, this, 0, true, WStyle_ContextHelp ); if ( QDialog::Accepted == KApplication::execDialog( &smtp ) ) { settings->addAccount( account ); account->save(); slotFillLists(); } else { account->remove(); } } else if ( type.compare( i18n("NNTP") ) == 0 ) { NNTPaccount *account = new NNTPaccount(); NNTPconfig nntp( account, this, 0, true, WStyle_ContextHelp ); if ( QDialog::Accepted == KApplication::execDialog( &nntp ) ) { settings->addAccount( account ); account->save(); slotFillLists(); } else { account->remove(); } } } void EditAccounts::slotEditAccount( Account *account ) { if ( account->getType() == MAILLIB::A_IMAP ) { IMAPaccount *imapAcc = static_cast<IMAPaccount *>(account); IMAPconfig imap( imapAcc, this, 0, true, WStyle_ContextHelp ); if ( QDialog::Accepted == KApplication::execDialog( &imap ) ) { slotFillLists(); } } else if ( account->getType()==MAILLIB::A_POP3 ) { POP3account *pop3Acc = static_cast<POP3account *>(account); POP3config pop3( pop3Acc, this, 0, true, WStyle_ContextHelp ); if ( QDialog::Accepted == KApplication::execDialog( &pop3 ) ) { slotFillLists(); } } else if ( account->getType()==MAILLIB::A_SMTP ) { SMTPaccount *smtpAcc = static_cast<SMTPaccount *>(account); SMTPconfig smtp( smtpAcc, this, 0, true, WStyle_ContextHelp ); if ( QDialog::Accepted == KApplication::execDialog( &smtp ) ) { slotFillLists(); } } else if ( account->getType()==MAILLIB::A_NNTP) { NNTPaccount *nntpAcc = static_cast<NNTPaccount *>(account); NNTPconfig nntp( nntpAcc, this, 0, true, WStyle_ContextHelp ); if ( QDialog::Accepted == KApplication::execDialog( &nntp ) ) { slotFillLists(); } } } void EditAccounts::slotDeleteAccount( Account *account ) { if ( QMessageBox::information( this, i18n( "Question" ), i18n( "<p>Do you really want to delete the selected Account?</p>" ), i18n( "Yes" ), i18n( "No" ) ) == 0 ) { settings->delAccount( account ); slotFillLists(); } } void EditAccounts::slotEditMail() { if ( !mailList->currentItem() ) { QMessageBox::information( this, i18n( "Error" ), i18n( "<p>Please select an account.</p>" ), i18n( "Ok" ) ); return; } Account *a = ((AccountListItem *) mailList->currentItem())->getAccount(); slotEditAccount( a ); } void EditAccounts::slotDeleteMail() { if ( !mailList->currentItem() ) { QMessageBox::information( this, i18n( "Error" ), i18n( "<p>Please select an account.</p>" ), i18n( "Ok" ) ); return; } Account *a = ((AccountListItem *) mailList->currentItem())->getAccount(); slotDeleteAccount( a ); } void EditAccounts::slotNewNews() { slotNewAccount( "NNTP" ); } void EditAccounts::slotEditNews() { if ( !newsList->currentItem() ) { QMessageBox::information( this, i18n( "Error" ), i18n( "<p>Please select an account.</p>" ), i18n( "Ok" ) ); return; } Account *a = ((AccountListItem *) newsList->currentItem())->getAccount(); slotEditAccount( a ); } void EditAccounts::slotDeleteNews() { if ( !newsList->currentItem() ) { QMessageBox::information( this, i18n( "Error" ), i18n( "<p>Please select an account.</p>" ), i18n( "Ok" ) ); return; } Account *a = ((AccountListItem *) newsList->currentItem())->getAccount(); slotDeleteAccount( a ); } void EditAccounts::slotAdjustColumns() { int currPage = configTab->currentPageIndex(); configTab->showPage( mailTab ); mailList->setColumnWidth( 0, mailList->visibleWidth() - 50 ); mailList->setColumnWidth( 1, 50 ); configTab->showPage( newsTab ); newsList->setColumnWidth( 0, newsList->visibleWidth() ); configTab->setCurrentPage( currPage ); } void EditAccounts::accept() { settings->saveAccounts(); QDialog::accept(); } /** * SelectMailType */ SelectMailType::SelectMailType( QString *selection, QWidget *parent, const char *name, bool modal, WFlags flags ) : SelectMailTypeUI( parent, name, modal, flags ) { selected = selection; selected->replace( 0, selected->length(), typeBox->currentText() ); connect( typeBox, SIGNAL( activated(const QString&) ), SLOT( slotSelection(const QString&) ) ); } void SelectMailType::slotSelection( const QString &sel ) { selected->replace( 0, selected->length(), sel ); } /** * IMAPconfig */ IMAPconfig::IMAPconfig( IMAPaccount *account, QWidget *parent, const char *name, bool modal, WFlags flags ) : IMAPconfigUI( parent, name, modal, flags ) { data = account; - fillValues(); + //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(); - ComboBox1->setCurrentItem( data->ConnectionType() ); + fillValues(); + // ComboBox1->setCurrentItem( data->ConnectionType() ); } void IMAPconfig::slotConnectionToggle( int index ) { if ( index == 2 ) { portLine->setText( IMAP_SSL_PORT ); } else if ( index == 3 ) { portLine->setText( IMAP_PORT ); CommandEdit->show(); } else { portLine->setText( IMAP_PORT ); } } 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() ); } void IMAPconfig::accept() { if ( localFolder->text().contains("/") ||localFolder->text().contains("\\") ) { QMessageBox::information( this, i18n( "Error" ), i18n( "No paths allowed in\nlocal folder settings.\nPlease specify a folder\nname or leave empty\nto create local folder\nwith account name\nautomatically." ), i18n( "Ok" ) ); return; } data->setAccountName( accountLine->text() ); data->setServer( serverLine->text() ); data->setPort( portLine->text() ); data->setConnectionType( ComboBox1->currentItem() ); data->setUser( userLine->text() ); data->setPassword( passLine->text() ); data->setPrefix(prefixLine->text()); data->setLocalFolder( localFolder->text() ); data->setMaxMailSize( CheckBoxDown->isChecked()?SpinBoxDown->value():0 ) ; data->setLeaveOnServer( CheckBoxLeaveOn->isChecked() ); QDialog::accept(); } /** * POP3config */ POP3config::POP3config( POP3account *account, QWidget *parent, const char *name, bool modal, WFlags flags ) : POP3configUI( parent, name, modal, flags ) { data = account; - fillValues(); + //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(); - ComboBox1->setCurrentItem( data->ConnectionType() ); + fillValues(); + //ComboBox1->setCurrentItem( data->ConnectionType() ); } void POP3config::slotConnectionToggle( int index ) { // 2 is ssl connection if ( index == 2 ) { portLine->setText( POP3_SSL_PORT ); } else if ( index == 3 ) { portLine->setText( POP3_PORT ); CommandEdit->show(); } else { portLine->setText( POP3_PORT ); } } 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() { if ( localFolder->text().contains("/") ||localFolder->text().contains("\\") ) { QMessageBox::information( this, i18n( "Error" ), i18n( "No paths allowed in\nlocal folder settings.\nPlease specify a folder\nname or leave empty\nto create local folder\nwith account name\nautomatically." ), i18n( "Ok" ) ); return; } data->setAccountName( accountLine->text() ); data->setServer( serverLine->text() ); data->setPort( portLine->text() ); data->setConnectionType( ComboBox1->currentItem() ); data->setUser( userLine->text() ); data->setPassword( passLine->text() ); data->setLocalFolder( localFolder->text() ); data->setMaxMailSize( CheckBoxDown->isChecked()?SpinBoxDown->value():0 ) ; data->setLeaveOnServer( CheckBoxLeaveOn->isChecked() ); QDialog::accept(); } /** * SMTPconfig */ SMTPconfig::SMTPconfig( SMTPaccount *account, QWidget *parent, const char *name, bool modal, WFlags flags ) : SMTPconfigUI( parent, name, modal, flags ) { data = account; connect( loginBox, SIGNAL( toggled(bool) ), userLine, SLOT( setEnabled(bool) ) ); connect( loginBox, SIGNAL( toggled(bool) ), passLine, SLOT( setEnabled(bool) ) ); - fillValues(); + // fillValues(); QIconSet icon; //icon = SmallIcon("fileexport"); 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( "Only if available", 0 ); - ComboBox1->insertItem( "Always, Negotiated", 1 ); - ComboBox1->insertItem( "Connect on secure port", 2 ); - ComboBox1->insertItem( "Run command instead", 3 ); + 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(); - ComboBox1->setCurrentItem( data->ConnectionType() ); + 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 ) { portLine->setText( SMTP_SSL_PORT ); } else if ( index == 3 ) { portLine->setText( SMTP_PORT ); CommandEdit->show(); } else { portLine->setText( SMTP_PORT ); } } 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() ); data->setSigFile( SignaturEdit->text() ); QDialog::accept(); } /** * NNTPconfig */ NNTPconfig::NNTPconfig( NNTPaccount *account, QWidget *parent, const char *name, bool modal, WFlags flags ) : NNTPconfigUI( parent, name, modal, flags ) { data = account; connect( loginBox, SIGNAL( toggled(bool) ), userLine, SLOT( setEnabled(bool) ) ); connect( loginBox, SIGNAL( toggled(bool) ), passLine, SLOT( setEnabled(bool) ) ); connect( GetNGButton, SIGNAL( clicked() ), this, SLOT( slotGetNG() ) ); connect( ShowSubcribed, SIGNAL( clicked() ), this, SLOT( slotShowSub() ) ); connect( FilterButton, SIGNAL( clicked() ), this, SLOT( slotShowFilter() ) ); fillValues(); connect( sslBox, SIGNAL( toggled(bool) ), SLOT( slotSSL(bool) ) ); } void NNTPconfig::slotShowSub() { save(); data->save(); ListViewGroups->clear(); for ( QStringList::Iterator it = subscribedGroups.begin(); it != subscribedGroups.end(); ++it ) { QCheckListItem *item; item = new QCheckListItem( ListViewGroups, (*it), QCheckListItem::CheckBox ); item->setOn( true ); } topLevelWidget()->setCaption( i18n("%1 groups subscribed").arg( subscribedGroups.count())); } void NNTPconfig::slotShowFilter() { save(); data->save(); ListViewGroups->clear(); int count = 0; for ( QStringList::Iterator it = allGroups.begin(); it != allGroups.end(); ++it ) { QCheckListItem *item; if ( GroupFilter->text().isEmpty() || (*it).find( GroupFilter->text() ) >= 0 ) { item = new QCheckListItem( ListViewGroups, (*it), QCheckListItem::CheckBox ); ++count; if ( subscribedGroups.contains( (*it) ) >= 1 ) { item->setOn( true ); } } } topLevelWidget()->setCaption( i18n("Filter found %1 groups").arg( count)); } void NNTPconfig::slotGetNG() { save(); data->save(); topLevelWidget()->setCaption( i18n("Fetching group list...")); qApp->processEvents(); NNTPwrapper* tmp = new NNTPwrapper( data ); allGroups = tmp->listAllNewsgroups(); topLevelWidget()->setCaption( i18n("Downloaded %1 group names").arg( allGroups.count())); ListViewGroups->clear(); for ( QStringList::Iterator it = allGroups.begin(); it != allGroups.end(); ++it ) { QCheckListItem *item; item = new QCheckListItem( ListViewGroups, (*it), QCheckListItem::CheckBox ); if ( subscribedGroups.contains( (*it) ) >= 1 ) { item->setOn( true ); } } delete tmp; } void NNTPconfig::slotSSL( bool enabled ) { if ( enabled ) { portLine->setText( NNTP_SSL_PORT ); } else { portLine->setText( NNTP_PORT ); } } void NNTPconfig::fillValues() { accountLine->setText( data->getAccountName() ); serverLine->setText( data->getServer() ); portLine->setText( data->getPort() ); sslBox->setChecked( data->getSSL() ); loginBox->setChecked( data->getLogin() ); userLine->setText( data->getUser() ); passLine->setText( data->getPassword() ); subscribedGroups = data->getGroups(); /* don't forget that - you will overwrite values if user clicks cancel! */ for ( QStringList::Iterator it = subscribedGroups.begin(); it != subscribedGroups.end(); ++it ) { QCheckListItem *item; item = new QCheckListItem( ListViewGroups, (*it), QCheckListItem::CheckBox ); item->setOn( true ); } } void NNTPconfig::save() { data->setAccountName( accountLine->text() ); data->setServer( serverLine->text() ); data->setPort( portLine->text() ); data->setSSL( sslBox->isChecked() ); data->setLogin( loginBox->isChecked() ); data->setUser( userLine->text() ); data->setPassword( passLine->text() ); QListViewItemIterator list_it( ListViewGroups ); for ( ; list_it.current(); ++list_it ) { if ( ( (QCheckListItem*)list_it.current() )->isOn() ) { if ( subscribedGroups.contains( list_it.current()->text(0) ) < 1 ) subscribedGroups.append( list_it.current()->text(0) ); } else { if ( subscribedGroups.contains( list_it.current()->text(0) ) >= 1 ) subscribedGroups.remove( list_it.current()->text(0) ); } } data->setGroups( subscribedGroups ); } void NNTPconfig::accept() { save(); QDialog::accept(); } diff --git a/kmicromail/libetpan/tools/mailstream_socket.c b/kmicromail/libetpan/tools/mailstream_socket.c index 04a6f48..fd2c758 100644 --- a/kmicromail/libetpan/tools/mailstream_socket.c +++ b/kmicromail/libetpan/tools/mailstream_socket.c @@ -1,246 +1,246 @@ /* * libEtPan! -- a mail stuff library * * Copyright (C) 2001, 2002 - DINH Viet Hoa * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the libEtPan! project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * $Id$ */ #include "mailstream_socket.h" #include <unistd.h> #include <stdlib.h> #include <fcntl.h> /* these 3 headers MUST be included before <sys/select.h> to insure compatibility with Mac OS X (this is true for 10.2) */ #include <sys/time.h> #include <sys/socket.h> #include <sys/types.h> #include <unistd.h> #include <sys/select.h> /* mailstream_low, socket */ static int mailstream_low_socket_close(mailstream_low * s); static ssize_t mailstream_low_socket_read(mailstream_low * s, void * buf, size_t count); static ssize_t mailstream_low_socket_write(mailstream_low * s, const void * buf, size_t count); static void mailstream_low_socket_free(mailstream_low * s); static int mailstream_low_socket_get_fd(mailstream_low * s); static mailstream_low_driver local_mailstream_socket_driver = { mailstream_read: mailstream_low_socket_read, mailstream_write: mailstream_low_socket_write, mailstream_close: mailstream_low_socket_close, mailstream_free: mailstream_low_socket_free, mailstream_get_fd: mailstream_low_socket_get_fd, }; mailstream_low_driver * mailstream_socket_driver = &local_mailstream_socket_driver; /* file descriptor must be given in (default) blocking-mode */ static struct mailstream_socket_data * socket_data_new(int fd) { struct mailstream_socket_data * socket_data; socket_data = malloc(sizeof(* socket_data)); if (socket_data == NULL) goto err; socket_data->fd = fd; return socket_data; err: return NULL; } static void socket_data_free(struct mailstream_socket_data * socket_data) { free(socket_data); } static void socket_data_close(struct mailstream_socket_data * socket_data) { close(socket_data->fd); socket_data->fd = -1; } mailstream_low * mailstream_low_socket_open(int fd) { mailstream_low * s; struct mailstream_socket_data * socket_data; socket_data = socket_data_new(fd); if (socket_data == NULL) goto err; s = mailstream_low_new(socket_data, mailstream_socket_driver); if (s == NULL) goto free_socket_data; return s; free_socket_data: socket_data_free(socket_data); err: return NULL; } static int mailstream_low_socket_close(mailstream_low * s) { struct mailstream_socket_data * socket_data; socket_data = (struct mailstream_socket_data *) s->data; socket_data_close(socket_data); return 0; } static void mailstream_low_socket_free(mailstream_low * s) { struct mailstream_socket_data * socket_data; socket_data = (struct mailstream_socket_data *) s->data; socket_data_free(socket_data); s->data = NULL; free(s); } static int mailstream_low_socket_get_fd(mailstream_low * s) { struct mailstream_socket_data * socket_data; socket_data = (struct mailstream_socket_data *) s->data; return socket_data->fd; } static ssize_t mailstream_low_socket_read(mailstream_low * s, void * buf, size_t count) { struct mailstream_socket_data * socket_data; socket_data = (struct mailstream_socket_data *) s->data; /* timeout */ { fd_set fds_read; fd_set fds_excp; struct timeval timeout; int r; timeout = mailstream_network_delay; FD_ZERO(&fds_read); FD_SET(socket_data->fd, &fds_read); FD_ZERO(&fds_excp); FD_SET(socket_data->fd, &fds_excp); // LUTZ for safety I insert here a max val as well if ( timeout.tv_sec > DEFAULT_NETWORK_TIMEOUT ) timeout.tv_sec = DEFAULT_NETWORK_TIMEOUT; r = select(socket_data->fd + 1, &fds_read, NULL, &fds_excp, &timeout); if (r < 1 ) return -1; if (FD_ISSET(socket_data->fd, &fds_excp)) return -1; if (!FD_ISSET(socket_data->fd, &fds_read)) return 0; } return recv(socket_data->fd,buf,count,MSG_NOSIGNAL); //return read(socket_data->fd, buf, count); } #include <stdio.h> static ssize_t mailstream_low_socket_write(mailstream_low * s, const void * buf, size_t count) { struct mailstream_socket_data * socket_data; socket_data = (struct mailstream_socket_data *) s->data; /* timeout */ { fd_set fds_write; fd_set fds_excp; struct timeval timeout; int r; timeout = mailstream_network_delay; FD_ZERO(&fds_write); FD_SET(socket_data->fd, &fds_write); FD_ZERO(&fds_excp); FD_SET(socket_data->fd, &fds_excp); // LUTZ next line blocks sometimes if ( timeout.tv_sec > DEFAULT_NETWORK_TIMEOUT ) timeout.tv_sec = DEFAULT_NETWORK_TIMEOUT; - fprintf(stderr,"fd %d to secs %d \n", socket_data->fd, timeout.tv_sec ); + //fprintf(stderr,"fd %d to secs %d \n", socket_data->fd, timeout.tv_sec ); r = select(socket_data->fd + 1, NULL, &fds_write, &fds_excp, &timeout); if (r < 1) return -1; if (FD_ISSET(socket_data->fd, &fds_excp)) return -1; if (!FD_ISSET(socket_data->fd, &fds_write)) return 0; } return send(socket_data->fd,buf,count,MSG_NOSIGNAL); //return write(socket_data->fd, buf, count); } /* mailstream */ mailstream * mailstream_socket_open(int fd) { mailstream_low * low; mailstream * s; low = mailstream_low_socket_open(fd); if (low == NULL) goto err; s = mailstream_new(low, 8192); if (s == NULL) goto free_low; return s; free_low: mailstream_low_close(low); err: return NULL; } diff --git a/kmicromail/libmailwrapper/smtpwrapper.cpp b/kmicromail/libmailwrapper/smtpwrapper.cpp index 5096f67..872a460 100644 --- a/kmicromail/libmailwrapper/smtpwrapper.cpp +++ b/kmicromail/libmailwrapper/smtpwrapper.cpp @@ -1,470 +1,472 @@ #include "smtpwrapper.h" #include "mailwrapper.h" #include "abstractmail.h" #include "logindialog.h" #include "mailtypes.h" #include "sendmailprogress.h" //#include <opie2/odebug.h> //#include <qt.h> #include <qapplication.h> #include <qmessagebox.h> #include <stdlib.h> #ifndef DESKTOP_VERSION //#include <qpe/config.h> #include <qpe/qcopenvelope_qws.h> #endif #include <libetpan/libetpan.h> #include <klocale.h> #include <kglobal.h> #include <kconfig.h> using namespace Opie::Core; progressMailSend*SMTPwrapper::sendProgress = 0; SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) : Generatemail() { m_SmtpAccount = aSmtp; KConfig cfg( locateLocal("config", "kopiemailrc" ) ); cfg.setGroup( "Status" ); m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); emit queuedMails( m_queuedMail ); connect( this, SIGNAL( queuedMails(int) ), this, SLOT( emitQCop(int) ) ); m_smtp = 0; } SMTPwrapper::~SMTPwrapper() { disc_server(); } void SMTPwrapper::emitQCop( int queued ) { #ifndef DESKTOP_VERSION // LR : not used in kde-pim //QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); //env << queued; #endif } QString SMTPwrapper::mailsmtpError( int errnum ) { switch ( errnum ) { case MAILSMTP_NO_ERROR: return i18n( "No error" ); case MAILSMTP_ERROR_UNEXPECTED_CODE: return i18n( "Unexpected error code" ); case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: return i18n( "Service not available" ); case MAILSMTP_ERROR_STREAM: return i18n( "Stream error" ); case MAILSMTP_ERROR_HOSTNAME: return i18n( "gethostname() failed" ); case MAILSMTP_ERROR_NOT_IMPLEMENTED: return i18n( "Not implemented" ); case MAILSMTP_ERROR_ACTION_NOT_TAKEN: return i18n( "Error, action not taken" ); case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: return i18n( "Data exceeds storage allocation" ); case MAILSMTP_ERROR_IN_PROCESSING: return i18n( "Error in processing" ); case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED: return i18n( "Starttls not supported" ); // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: // return i18n( "Insufficient system storage" ); case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: return i18n( "Mailbox unavailable" ); case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: return i18n( "Mailbox name not allowed" ); case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: return i18n( "Bad command sequence" ); case MAILSMTP_ERROR_USER_NOT_LOCAL: return i18n( "User not local" ); case MAILSMTP_ERROR_TRANSACTION_FAILED: return i18n( "Transaction failed" ); case MAILSMTP_ERROR_MEMORY: return i18n( "Memory error" ); case MAILSMTP_ERROR_CONNECTION_REFUSED: return i18n( "Connection refused" ); default: return i18n( "Unknown error code" ); } } void SMTPwrapper::progress( size_t current, size_t maximum ) { if (SMTPwrapper::sendProgress) { SMTPwrapper::sendProgress->setSingleMail(current, maximum ); qApp->processEvents(); } } void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { if (!mail) return; QString localfolders = AbstractMail::defaultLocalfolder(); AbstractMail*wrap = AbstractMail::getWrapper(localfolders); wrap->createMbox(box); wrap->storeMessage(mail,length,box); delete wrap; } bool SMTPwrapper::smtpSend( mailmime *mail,bool later) { clist *rcpts = 0; char *from, *data; size_t size; from = data = 0; mailmessage * msg = 0; msg = mime_message_init(mail); mime_message_set_tmpdir(msg,getenv( "HOME" )); int r = mailmessage_fetch(msg,&data,&size); mime_message_detach_mime(msg); mailmessage_free(msg); if (r != MAIL_NO_ERROR || !data) { if (data) free(data); qDebug("Error fetching mime... "); return false; } msg = 0; if (later) { storeMail(data,size,"Outgoing"); if (data) free( data ); KConfig cfg( locateLocal("config", "kopiemailrc" ) ); cfg.setGroup( "Status" ); cfg.writeEntry( "outgoing", ++m_queuedMail ); emit queuedMails( m_queuedMail ); return true; } from = getFrom( mail ); rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); bool result = smtpSend(from,rcpts,data,size); if (data) { free(data); } if (from) { free(from); } if (rcpts) smtp_address_list_free( rcpts ); return result; } void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage) { if (data) { storeMail(data,size,"Sendfailed"); } if (failuremessage) { QMessageBox::critical(0,i18n("Error sending mail"), failuremessage); } } int SMTPwrapper::start_smtp_tls() { if (!m_smtp) { return MAILSMTP_ERROR_IN_PROCESSING; } int err = mailesmtp_starttls(m_smtp); if (err != MAILSMTP_NO_ERROR) return err; mailstream_low * low; mailstream_low * new_low; low = mailstream_get_low(m_smtp->stream); if (!low) { return MAILSMTP_ERROR_IN_PROCESSING; } int fd = mailstream_low_get_fd(low); if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { mailstream_low_free(low); mailstream_set_low(m_smtp->stream, new_low); } else { return MAILSMTP_ERROR_IN_PROCESSING; } return err; } void SMTPwrapper::connect_server() { QString server, user, pass; bool ssl; uint16_t port; ssl = false; - bool try_tls = true; + bool try_tls = false; bool force_tls=false; QString failuretext = ""; if (m_smtp || !m_SmtpAccount) { return; } server = m_SmtpAccount->getServer(); - if ( m_SmtpAccount->ConnectionType() == 2 ) { + if ( m_SmtpAccount->ConnectionType() == 3 ) { ssl = true; try_tls = false; - } else if (m_SmtpAccount->ConnectionType() == 1) { + } else if (m_SmtpAccount->ConnectionType() == 2) { force_tls = true; + } else if (m_SmtpAccount->ConnectionType() == 1) { + try_tls = true; } int result = 1; port = m_SmtpAccount->getPort().toUInt(); m_smtp = mailsmtp_new( 20, &progress ); if ( m_smtp == NULL ) { /* no failure message cause this happens when problems with memory - than we we can not display any messagebox */ return; } int err = MAILSMTP_NO_ERROR; ; // 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) { 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); } } //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; } } } } 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)); result = 0; } } else { result = 0; } if (!result) { storeFailedMail(data,size,failuretext); } else { ; // 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 ); } 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 ); from = getFrom(ffrom); if (rcpts && from) { res = smtpSend(from,rcpts,data->Content(),data->Length()); } if (fields) { mailimf_fields_free(fields); fields = 0; } if (data) { delete data; } if (from) { free(from); } if (rcpts) { smtp_address_list_free( rcpts ); } return res; } /* this is a special fun */ bool SMTPwrapper::flushOutbox() { bool returnValue = true; ; // odebug << "Sending the queue" << oendl; if (!m_SmtpAccount) { ; // odebug << "No smtp account given" << oendl; return false; } bool reset_user_value = false; QString localfolders = AbstractMail::defaultLocalfolder(); AbstractMail*wrap = AbstractMail::getWrapper(localfolders); if (!wrap) { ; // odebug << "memory error" << oendl; return false; } QString oldPw, oldUser; QValueList<RecMailP> mailsToSend; QValueList<RecMailP> mailsToRemove; QString mbox("Outgoing"); wrap->listMessages(mbox,mailsToSend); if (mailsToSend.count()==0) { delete wrap; ; // odebug << "No mails to send" << oendl; return false; } oldPw = m_SmtpAccount->getPassword(); oldUser = m_SmtpAccount->getUser(); if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) { // get'em QString user,pass; LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true ); login.show(); if ( QDialog::Accepted == login.exec() ) { // ok user = login.getUser().latin1(); pass = login.getPassword().latin1(); reset_user_value = true; m_SmtpAccount->setUser(user); m_SmtpAccount->setPassword(pass); } 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; return returnValue; } |