kmail Library API Documentation

kmtransport.cpp

00001 
00020 #include <config.h>
00021 #include <assert.h>
00022 
00023 #include <qbuttongroup.h>
00024 #include <qcheckbox.h>
00025 #include <qlayout.h>
00026 #include <klineedit.h>
00027 #include <qradiobutton.h>
00028 #include <qtabwidget.h>
00029 #include <qvalidator.h>
00030 #include <qlabel.h>
00031 #include <qpushbutton.h>
00032 #include <qwhatsthis.h>
00033 
00034 #include <kfiledialog.h>
00035 #include <klocale.h>
00036 #include <kmessagebox.h>
00037 #include <kseparator.h>
00038 #include <kdebug.h>
00039 
00040 #include "kmservertest.h"
00041 #include "kmtransport.h"
00042 #include "kmaccount.h"
00043 #include "kmkernel.h"
00044 
00045 
00046 KMTransportInfo::KMTransportInfo()
00047 {
00048   name = i18n("Unnamed");
00049   port = "25";
00050   auth = FALSE;
00051   storePass = FALSE;
00052   specifyHostname = false;
00053 }
00054 
00055 
00056 KMTransportInfo::~KMTransportInfo()
00057 {
00058 }
00059 
00060 
00061 void KMTransportInfo::readConfig(int id)
00062 {
00063   KConfig *config = KMKernel::config();
00064   KConfigGroupSaver saver(config, "Transport " + QString::number(id));
00065   type = config->readEntry("type", "smtp");
00066   name = config->readEntry("name", i18n("Unnamed"));
00067   host = config->readEntry("host", "localhost");
00068   port = config->readEntry("port", "25");
00069   user = config->readEntry("user");
00070   pass = KMAccount::decryptStr(config->readEntry("pass"));
00071   precommand = config->readPathEntry("precommand");
00072   encryption = config->readEntry("encryption");
00073   authType = config->readEntry("authtype");
00074   auth = config->readBoolEntry("auth");
00075   storePass = config->readBoolEntry("storepass");
00076   specifyHostname = config->readBoolEntry("specifyHostname", false);
00077   localHostname = config->readEntry("localHostname");
00078 }
00079 
00080 
00081 void KMTransportInfo::writeConfig(int id)
00082 {
00083   KConfig *config = KMKernel::config();
00084   KConfigGroupSaver saver(config, "Transport " + QString::number(id));
00085   config->writeEntry("type", type);
00086   config->writeEntry("name", name);
00087   config->writeEntry("host", host);
00088   config->writeEntry("port", port);
00089   config->writeEntry("user", user);
00090   config->writeEntry("pass", (storePass) ? KMAccount::encryptStr(pass) :
00091                                            QString("") );
00092   config->writePathEntry("precommand", precommand);
00093   config->writeEntry("encryption", encryption);
00094   config->writeEntry("authtype", authType);
00095   config->writeEntry("auth", auth);
00096   config->writeEntry("storepass", storePass);
00097   config->writeEntry("specifyHostname", specifyHostname);
00098   config->writeEntry("localHostname", localHostname);
00099 }
00100 
00101 
00102 int KMTransportInfo::findTransport(const QString &name)
00103 {
00104   KConfig *config = KMKernel::config();
00105   KConfigGroupSaver saver(config, "General");
00106   int numTransports = config->readNumEntry("transports", 0);
00107   for (int i = 1; i <= numTransports; i++)
00108   {
00109     KConfigGroupSaver saver(config, "Transport " + QString::number(i));
00110     if (config->readEntry("name") == name) return i;
00111   }
00112   return 0;
00113 }
00114 
00115 
00116 QStringList KMTransportInfo::availableTransports()
00117 {
00118   QStringList result;
00119   KConfig *config = KMKernel::config();
00120   KConfigGroupSaver saver(config, "General");
00121   int numTransports = config->readNumEntry("transports", 0);
00122   for (int i = 1; i <= numTransports; i++)
00123   {
00124     KConfigGroupSaver saver(config, "Transport " + QString::number(i));
00125     result.append(config->readEntry("name"));
00126   }
00127   return result;
00128 }
00129 
00130 
00131 KMTransportSelDlg::KMTransportSelDlg( QWidget *parent, const char *name,
00132   bool modal )
00133   : KDialogBase( parent, name, modal, i18n("Add Transport"), Ok|Cancel, Ok )
00134 {
00135   QFrame *page = makeMainWidget();
00136   QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() );
00137 
00138   QButtonGroup *group = new QButtonGroup( i18n("Transport"), page );
00139   connect(group, SIGNAL(clicked(int)), SLOT(buttonClicked(int)) );
00140 
00141   topLayout->addWidget( group, 10 );
00142   QVBoxLayout *vlay = new QVBoxLayout( group, spacingHint()*2, spacingHint() );
00143   vlay->addSpacing( fontMetrics().lineSpacing() );
00144 
00145   QRadioButton *radioButton1 = new QRadioButton( i18n("SM&TP"), group );
00146   vlay->addWidget( radioButton1 );
00147   QRadioButton *radioButton2 = new QRadioButton( i18n("&Sendmail"), group );
00148   vlay->addWidget( radioButton2 );
00149 
00150   vlay->addStretch( 10 );
00151 
00152   radioButton1->setChecked(true); // Pop is most common ?
00153   buttonClicked(0);
00154 }
00155 
00156 void KMTransportSelDlg::buttonClicked( int id )
00157 {
00158   mSelectedButton = id;
00159 }
00160 
00161 
00162 int KMTransportSelDlg::selected( void ) const
00163 {
00164   return mSelectedButton;
00165 }
00166 
00167 
00168 KMTransportDialog::KMTransportDialog( const QString & caption,
00169                       KMTransportInfo *transportInfo,
00170                       QWidget *parent, const char *name,
00171                       bool modal )
00172   : KDialogBase( parent, name, modal, caption, Ok|Cancel, Ok, true ),
00173     mServerTest( 0 ),
00174     mTransportInfo( transportInfo ),
00175     mAuthNone( AllAuth ), mAuthSSL( AllAuth ), mAuthTLS( AllAuth )
00176 {
00177   assert(transportInfo != 0);
00178 
00179   if( transportInfo->type == QString::fromLatin1("sendmail") )
00180   {
00181     makeSendmailPage();
00182   } else {
00183     makeSmtpPage();
00184   }
00185 
00186   setupSettings();
00187 }
00188 
00189 
00190 KMTransportDialog::~KMTransportDialog()
00191 {
00192 }
00193 
00194 
00195 void KMTransportDialog::makeSendmailPage()
00196 {
00197   QFrame *page = makeMainWidget();
00198   QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() );
00199 
00200   mSendmail.titleLabel = new QLabel( page );
00201   mSendmail.titleLabel->setText( i18n("Transport: Sendmail") );
00202   QFont titleFont( mSendmail.titleLabel->font() );
00203   titleFont.setBold( true );
00204   mSendmail.titleLabel->setFont( titleFont );
00205   topLayout->addWidget( mSendmail.titleLabel );
00206   KSeparator *hline = new KSeparator( KSeparator::HLine, page);
00207   topLayout->addWidget( hline );
00208 
00209   QGridLayout *grid = new QGridLayout( topLayout, 3, 3, spacingHint() );
00210   grid->addColSpacing( 1, fontMetrics().maxWidth()*15 );
00211   grid->setRowStretch( 2, 10 );
00212   grid->setColStretch( 1, 10 );
00213 
00214   QLabel *label = new QLabel( i18n("&Name:"), page );
00215   grid->addWidget( label, 0, 0 );
00216   mSendmail.nameEdit = new KLineEdit( page );
00217   label->setBuddy( mSendmail.nameEdit );
00218   grid->addWidget( mSendmail.nameEdit, 0, 1 );
00219 
00220   label = new QLabel( i18n("&Location:"), page );
00221   grid->addWidget( label, 1, 0 );
00222   mSendmail.locationEdit = new KLineEdit( page );
00223   label->setBuddy(mSendmail.locationEdit);
00224   grid->addWidget( mSendmail.locationEdit, 1, 1 );
00225   mSendmail.chooseButton =
00226     new QPushButton( i18n("Choos&e..."), page );
00227   connect( mSendmail.chooseButton, SIGNAL(clicked()),
00228            this, SLOT(slotSendmailChooser()) );
00229 
00230   connect( mSendmail.locationEdit, SIGNAL(textChanged ( const QString & )),
00231            this, SLOT(slotSendmailEditPath(const QString &)) );
00232 
00233   mSendmail.chooseButton->setAutoDefault( false );
00234   grid->addWidget( mSendmail.chooseButton, 1, 2 );
00235   slotSendmailEditPath(mSendmail.locationEdit->text());
00236 }
00237 
00238 void KMTransportDialog::slotSendmailEditPath(const QString & _text)
00239 {
00240   enableButtonOK( !_text.isEmpty() );
00241 }
00242 
00243 void KMTransportDialog::makeSmtpPage()
00244 {
00245   QFrame *page = makeMainWidget();
00246   QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() );
00247 
00248   mSmtp.titleLabel = new QLabel( page );
00249   mSmtp.titleLabel->setText( i18n("Transport: SMTP") );
00250   QFont titleFont( mSmtp.titleLabel->font() );
00251   titleFont.setBold( true );
00252   mSmtp.titleLabel->setFont( titleFont );
00253   topLayout->addWidget( mSmtp.titleLabel );
00254   KSeparator *hline = new KSeparator( KSeparator::HLine, page);
00255   topLayout->addWidget( hline );
00256 
00257   QTabWidget *tabWidget = new QTabWidget(page);
00258   topLayout->addWidget( tabWidget );
00259 
00260   QWidget *page1 = new QWidget( tabWidget );
00261   tabWidget->addTab( page1, i18n("&General") );
00262 
00263   QGridLayout *grid = new QGridLayout( page1, 14, 2, spacingHint() );
00264   grid->addColSpacing( 1, fontMetrics().maxWidth()*15 );
00265   grid->setRowStretch( 13, 10 );
00266   grid->setColStretch( 1, 10 );
00267 
00268   QLabel *label = new QLabel( i18n("&Name:"), page1 );
00269   grid->addWidget( label, 0, 0 );
00270   mSmtp.nameEdit = new KLineEdit( page1 );
00271   QWhatsThis::add(mSmtp.nameEdit,
00272                   i18n("The name that KMail will use when "
00273                        "referring to this server."));
00274   label->setBuddy( mSmtp.nameEdit );
00275   grid->addWidget( mSmtp.nameEdit, 0, 1 );
00276 
00277   label = new QLabel( i18n("&Host:"), page1 );
00278   grid->addWidget( label, 3, 0 );
00279   mSmtp.hostEdit = new KLineEdit( page1 );
00280   QWhatsThis::add(mSmtp.hostEdit,
00281                   i18n("The domain name or numerical address "
00282                        "of the SMTP server."));
00283   label->setBuddy( mSmtp.hostEdit );
00284   grid->addWidget( mSmtp.hostEdit, 3, 1 );
00285 
00286   label = new QLabel( i18n("&Port:"), page1 );
00287   grid->addWidget( label, 4, 0 );
00288   mSmtp.portEdit = new KLineEdit( page1 );
00289   mSmtp.portEdit->setValidator( new QIntValidator(this) );
00290   QWhatsThis::add(mSmtp.portEdit,
00291                   i18n("The port number that the SMTP server "
00292                        "is listening on. The default port is 25."));
00293   label->setBuddy( mSmtp.portEdit );
00294   grid->addWidget( mSmtp.portEdit, 4, 1 );
00295 
00296   label = new QLabel( i18n("Preco&mmand:"), page1 );
00297   grid->addWidget( label, 5, 0 );
00298   mSmtp.precommand = new KLineEdit( page1 );
00299   QWhatsThis::add(mSmtp.precommand,
00300                   i18n("A command to run locally, prior "
00301                        "to sending email. This can be used "
00302                        "to set up ssh tunnels, for example. "
00303                        "Leave it empty if no command should be run."));
00304   label->setBuddy(mSmtp.precommand);
00305   grid->addWidget( mSmtp.precommand, 5, 1 );
00306 
00307   QFrame* line = new QFrame( page1 );
00308   line->setFrameStyle( QFrame::HLine | QFrame::Plain );
00309   grid->addMultiCellWidget( line, 6, 6, 0, 1 );
00310 
00311   mSmtp.authCheck =
00312     new QCheckBox( i18n("Server &requires authentication"), page1 );
00313   QWhatsThis::add(mSmtp.authCheck,
00314                   i18n("Check this option if your SMTP server "
00315                        "requires authentication before accepting "
00316                        "mail. This is known as "
00317                        "'Authenticated SMTP' or simply ASMTP."));
00318   connect(mSmtp.authCheck, SIGNAL(clicked()),
00319           SLOT(slotRequiresAuthClicked()));
00320   grid->addMultiCellWidget( mSmtp.authCheck, 7, 7, 0, 1 );
00321 
00322   mSmtp.loginLabel = new QLabel( i18n("&Login:"), page1 );
00323   grid->addWidget( mSmtp.loginLabel, 8, 0 );
00324   mSmtp.loginEdit = new KLineEdit( page1 );
00325   mSmtp.loginLabel->setBuddy( mSmtp.loginEdit );
00326   QWhatsThis::add(mSmtp.loginEdit,
00327                   i18n("The user name to send to the server "
00328                        "for authorization"));
00329   grid->addWidget( mSmtp.loginEdit, 8, 1 );
00330 
00331   mSmtp.passwordLabel = new QLabel( i18n("P&assword:"), page1 );
00332   grid->addWidget( mSmtp.passwordLabel, 9, 0 );
00333   mSmtp.passwordEdit = new KLineEdit( page1 );
00334   mSmtp.passwordEdit->setEchoMode( QLineEdit::Password );
00335   mSmtp.passwordLabel->setBuddy( mSmtp.passwordEdit );
00336   QWhatsThis::add(mSmtp.passwordEdit,
00337                   i18n("The password to send to the server "
00338                        "for authorization"));
00339   grid->addWidget( mSmtp.passwordEdit, 9, 1 );
00340 
00341   mSmtp.storePasswordCheck =
00342     new QCheckBox( i18n("&Store SMTP password in configuration file"), page1 );
00343   QWhatsThis::add(mSmtp.storePasswordCheck,
00344                   i18n("Check this option to have KMail store "
00345                   "the SMTP password in its configuration "
00346                   "file. The password is stored in an "
00347                   "obfuscated format, but should not be "
00348                   "considered secure from decryption efforts "
00349                   "if access to the configuration file is obtained."));
00350   grid->addMultiCellWidget( mSmtp.storePasswordCheck, 10, 10, 0, 1 );
00351 
00352   line = new QFrame( page1 );
00353   line->setFrameStyle( QFrame::HLine | QFrame::Plain );
00354   grid->addMultiCellWidget( line, 11, 11, 0, 1 );
00355 
00356   mSmtp.specifyHostnameCheck =
00357     new QCheckBox( i18n("Sen&d custom hostname to server"), page1 );
00358   grid->addMultiCellWidget( mSmtp.specifyHostnameCheck, 12, 12, 0, 1 );
00359   QWhatsThis::add(mSmtp.specifyHostnameCheck,
00360                   i18n("Check this option to have KMail use "
00361                        "a custom hostname when identifying itself "
00362                        "to the mail server."
00363                        "<p>This is useful when your system's hostname "
00364                        "may not be set correctly or to mask your "
00365                        "system's true hostname."));
00366 
00367   mSmtp.localHostnameLabel = new QLabel( i18n("Hos&tname:"), page1 );
00368   grid->addWidget( mSmtp.localHostnameLabel, 13, 0);
00369   mSmtp.localHostnameEdit = new KLineEdit( page1 );
00370   QWhatsThis::add(mSmtp.localHostnameEdit,
00371                   i18n("Enter the hostname KMail should use when "
00372                        "identifying itself to the server."));
00373   mSmtp.localHostnameLabel->setBuddy( mSmtp.localHostnameEdit );
00374   grid->addWidget( mSmtp.localHostnameEdit, 13, 1 );
00375   connect( mSmtp.specifyHostnameCheck, SIGNAL(toggled(bool)),
00376            mSmtp.localHostnameEdit, SLOT(setEnabled(bool)));
00377   connect( mSmtp.specifyHostnameCheck, SIGNAL(toggled(bool)),
00378            mSmtp.localHostnameLabel, SLOT(setEnabled(bool)));
00379 
00380   QWidget *page2 = new QWidget( tabWidget );
00381   tabWidget->addTab( page2, i18n("S&ecurity") );
00382   QVBoxLayout *vlay = new QVBoxLayout( page2, spacingHint() );
00383   mSmtp.encryptionGroup = new QButtonGroup( 1, Qt::Horizontal,
00384     i18n("Encryption"), page2 );
00385   mSmtp.encryptionNone =
00386     new QRadioButton( i18n("&None"), mSmtp.encryptionGroup );
00387   mSmtp.encryptionSSL =
00388     new QRadioButton( i18n("&SSL"), mSmtp.encryptionGroup );
00389   mSmtp.encryptionTLS =
00390     new QRadioButton( i18n("&TLS"), mSmtp.encryptionGroup );
00391   connect(mSmtp.encryptionGroup, SIGNAL(clicked(int)),
00392     SLOT(slotSmtpEncryptionChanged(int)));
00393   vlay->addWidget( mSmtp.encryptionGroup );
00394 
00395   mSmtp.authGroup = new QButtonGroup( 1, Qt::Horizontal,
00396     i18n("Authentication Method"), page2 );
00397   mSmtp.authLogin = new QRadioButton( i18n("Please translate this "
00398     "authentication method only if you have a good reason", "&LOGIN"),
00399     mSmtp.authGroup );
00400   mSmtp.authPlain = new QRadioButton( i18n("Please translate this "
00401     "authentication method only if you have a good reason", "&PLAIN"),
00402     mSmtp.authGroup  );
00403   mSmtp.authCramMd5 = new QRadioButton( i18n("CRAM-MD&5"), mSmtp.authGroup );
00404   mSmtp.authDigestMd5 = new QRadioButton( i18n("&DIGEST-MD5"), mSmtp.authGroup );
00405   vlay->addWidget( mSmtp.authGroup );
00406 
00407   vlay->addStretch();
00408 
00409   QHBoxLayout *buttonLay = new QHBoxLayout( vlay );
00410   mSmtp.checkCapabilities =
00411     new QPushButton( i18n("Check &What the Server Supports"), page2 );
00412   connect(mSmtp.checkCapabilities, SIGNAL(clicked()),
00413     SLOT(slotCheckSmtpCapabilities()));
00414   buttonLay->addStretch();
00415   buttonLay->addWidget( mSmtp.checkCapabilities );
00416 }
00417 
00418 
00419 void KMTransportDialog::setupSettings()
00420 {
00421   if (mTransportInfo->type == "sendmail")
00422   {
00423     mSendmail.nameEdit->setText(mTransportInfo->name);
00424     mSendmail.locationEdit->setText(mTransportInfo->host);
00425   } else {
00426     mSmtp.nameEdit->setText(mTransportInfo->name);
00427     mSmtp.hostEdit->setText(mTransportInfo->host);
00428     mSmtp.portEdit->setText(mTransportInfo->port);
00429     mSmtp.authCheck->setChecked(mTransportInfo->auth);
00430     mSmtp.loginEdit->setText(mTransportInfo->user);
00431     mSmtp.passwordEdit->setText(mTransportInfo->pass);
00432     mSmtp.storePasswordCheck->setChecked(mTransportInfo->storePass);
00433     mSmtp.precommand->setText(mTransportInfo->precommand);
00434     mSmtp.specifyHostnameCheck->setChecked(mTransportInfo->specifyHostname);
00435     mSmtp.localHostnameEdit->setText(mTransportInfo->localHostname);
00436 
00437     if (mTransportInfo->encryption == "TLS")
00438       mSmtp.encryptionTLS->setChecked(TRUE);
00439     else if (mTransportInfo->encryption == "SSL")
00440       mSmtp.encryptionSSL->setChecked(TRUE);
00441     else mSmtp.encryptionNone->setChecked(TRUE);
00442 
00443     if (mTransportInfo->authType == "LOGIN")
00444       mSmtp.authLogin->setChecked(TRUE);
00445     else if (mTransportInfo->authType == "CRAM-MD5")
00446       mSmtp.authCramMd5->setChecked(TRUE);
00447     else if (mTransportInfo->authType == "DIGEST-MD5")
00448       mSmtp.authDigestMd5->setChecked(TRUE);
00449     else mSmtp.authPlain->setChecked(TRUE);
00450 
00451     slotRequiresAuthClicked();
00452     mSmtp.localHostnameEdit->setEnabled(mTransportInfo->specifyHostname);
00453     mSmtp.localHostnameLabel->setEnabled(mTransportInfo->specifyHostname);
00454   }
00455 }
00456 
00457 
00458 void KMTransportDialog::saveSettings()
00459 {
00460   if (mTransportInfo->type == "sendmail")
00461   {
00462     mTransportInfo->name = mSendmail.nameEdit->text().stripWhiteSpace();
00463     mTransportInfo->host = mSendmail.locationEdit->text().stripWhiteSpace();
00464   } else {
00465     mTransportInfo->name = mSmtp.nameEdit->text();
00466     mTransportInfo->host = mSmtp.hostEdit->text().stripWhiteSpace();
00467     mTransportInfo->port = mSmtp.portEdit->text().stripWhiteSpace();
00468     mTransportInfo->auth = mSmtp.authCheck->isChecked();
00469     mTransportInfo->user = mSmtp.loginEdit->text().stripWhiteSpace();
00470     mTransportInfo->pass = mSmtp.passwordEdit->text();
00471     mTransportInfo->storePass = mSmtp.storePasswordCheck->isChecked();
00472     mTransportInfo->precommand = mSmtp.precommand->text().stripWhiteSpace();
00473     mTransportInfo->specifyHostname = mSmtp.specifyHostnameCheck->isChecked();
00474     mTransportInfo->localHostname = mSmtp.localHostnameEdit->text().stripWhiteSpace();
00475 
00476     mTransportInfo->encryption = (mSmtp.encryptionTLS->isChecked()) ? "TLS" :
00477     (mSmtp.encryptionSSL->isChecked()) ? "SSL" : "NONE";
00478 
00479     mTransportInfo->authType = (mSmtp.authLogin->isChecked()) ? "LOGIN" :
00480     (mSmtp.authCramMd5->isChecked()) ? "CRAM-MD5" :
00481     (mSmtp.authDigestMd5->isChecked()) ? "DIGEST-MD5" : "PLAIN";
00482   }
00483 }
00484 
00485 
00486 void KMTransportDialog::slotSendmailChooser()
00487 {
00488   KFileDialog dialog("/", QString::null, this, 0, true );
00489   dialog.setCaption(i18n("Choose sendmail Location") );
00490 
00491   if( dialog.exec() == QDialog::Accepted )
00492   {
00493     KURL url = dialog.selectedURL();
00494     if( url.isEmpty() == true )
00495     {
00496       return;
00497     }
00498 
00499     if( url.isLocalFile() == false )
00500     {
00501       KMessageBox::sorry( 0, i18n( "Only local files allowed." ) );
00502       return;
00503     }
00504 
00505     mSendmail.locationEdit->setText( url.path() );
00506   }
00507 }
00508 
00509 
00510 void KMTransportDialog::slotRequiresAuthClicked()
00511 {
00512   bool b = mSmtp.authCheck->isChecked();
00513   mSmtp.loginLabel->setEnabled(b);
00514   mSmtp.loginEdit->setEnabled(b);
00515   mSmtp.passwordLabel->setEnabled(b);
00516   mSmtp.passwordEdit->setEnabled(b);
00517   mSmtp.storePasswordCheck->setEnabled(b);
00518   mSmtp.authGroup->setEnabled(b);
00519 }
00520 
00521 
00522 void KMTransportDialog::slotSmtpEncryptionChanged(int id)
00523 {
00524   kdDebug() << "KMTransportDialog::slotSmtpEncryptionChanged( " << id << " )" << endl;
00525   // adjust SSL port:
00526   if (id == SSL || mSmtp.portEdit->text() == "465")
00527     mSmtp.portEdit->setText((id == SSL) ? "465" : "25");
00528 
00529   // switch supported auth methods:
00530   QButton * old = mSmtp.authGroup->selected();
00531   int authMethods = id == TLS ? mAuthTLS : id == SSL ? mAuthSSL : mAuthNone ;
00532   enableAuthMethods( authMethods );
00533   if ( !old->isEnabled() )
00534     checkHighest( mSmtp.authGroup );
00535 }
00536 
00537 void KMTransportDialog::enableAuthMethods( unsigned int auth ) {
00538   kdDebug() << "KMTransportDislaog::enableAuthMethods( " << auth << " )" << endl;
00539   mSmtp.authPlain->setEnabled( auth & PLAIN );
00540   // LOGIN doesn't offer anything over PLAIN, requires more server
00541   // roundtrips and is not an official SASL mechanism, but a MS-ism,
00542   // so only enable it if PLAIN isn't available:
00543   mSmtp.authLogin->setEnabled( auth & LOGIN && !(auth & PLAIN));
00544   mSmtp.authCramMd5->setEnabled( auth & CRAM_MD5 );
00545   mSmtp.authDigestMd5->setEnabled( auth & DIGEST_MD5 );
00546 }
00547 
00548 unsigned int KMTransportDialog::authMethodsFromString( const QString & s ) {
00549   unsigned int result = 0;
00550   QStringList sl = QStringList::split( '\n', s.upper() );
00551   for ( QStringList::const_iterator it = sl.begin() ; it != sl.end() ; ++it )
00552     if (  *it == "SASL/LOGIN" )
00553       result |= LOGIN;
00554     else if ( *it == "SASL/PLAIN" )
00555       result |= PLAIN;
00556     else if ( *it == "SASL/CRAM-MD5" )
00557       result |= CRAM_MD5;
00558     else if ( *it == "SASL/DIGEST-MD5" )
00559       result |= DIGEST_MD5;
00560   return result;
00561 }
00562 
00563 unsigned int KMTransportDialog::authMethodsFromStringList( const QStringList & sl ) {
00564   unsigned int result = 0;
00565   for ( QStringList::const_iterator it = sl.begin() ; it != sl.end() ; ++it )
00566     if ( *it == "LOGIN" )
00567       result |= LOGIN;
00568     else if ( *it == "PLAIN" )
00569       result |= PLAIN;
00570     else if ( *it == "CRAM-MD5" )
00571       result |= CRAM_MD5;
00572     else if ( *it == "DIGEST-MD5" )
00573       result |= DIGEST_MD5;
00574   return result;
00575 }
00576 
00577 void KMTransportDialog::slotCheckSmtpCapabilities()
00578 {
00579   delete mServerTest;
00580   mServerTest = new KMServerTest("smtp", mSmtp.hostEdit->text(),
00581     mSmtp.portEdit->text().toInt());
00582   connect(mServerTest, SIGNAL(capabilities(const QStringList&,const QString&,const QString&,const QString&)),
00583     SLOT(slotSmtpCapabilities(const QStringList&,const QString&,const QString&, const QString&)));
00584   mSmtp.checkCapabilities->setEnabled(FALSE);
00585 }
00586 
00587 
00588 void KMTransportDialog::checkHighest(QButtonGroup *btnGroup)
00589 {
00590   for ( int i = btnGroup->count() - 1; i >= 0 ; --i )
00591   {
00592     QButton * btn = btnGroup->find(i);
00593     if (btn && btn->isEnabled())
00594     {
00595       btn->animateClick();
00596       return;
00597     }
00598   }
00599 }
00600 
00601 
00602 void KMTransportDialog::slotSmtpCapabilities(const QStringList & list,
00603     const QString & authNone, const QString & authSSL, const QString & authTLS )
00604 {
00605   kdDebug() << "KMTransportDialog::slotSmtpCapabilities( ..., "
00606         << authNone << ", " << authSSL << ", " << authTLS << " )" << endl;
00607   mSmtp.checkCapabilities->setEnabled(TRUE);
00608   bool nc = list.findIndex("NORMAL-CONNECTION") != -1;
00609   mSmtp.encryptionNone->setEnabled(nc);
00610   mSmtp.encryptionSSL->setEnabled(list.findIndex("SSL") != -1);
00611   mSmtp.encryptionTLS->setEnabled(list.findIndex("STARTTLS") != -1 && nc);
00612   if ( authNone.isEmpty() && authSSL.isEmpty() && authTLS.isEmpty() )
00613     // slave doesn't seem to support "* AUTH METHODS" metadata (or server can't do AUTH)
00614     mAuthNone = mAuthSSL = mAuthTLS = authMethodsFromStringList( list );
00615   else {
00616     mAuthNone = authMethodsFromString( authNone );
00617     mAuthSSL = authMethodsFromString( authSSL );
00618     mAuthTLS = authMethodsFromString( authTLS );
00619     kdDebug() << "mAuthNone = " << mAuthNone
00620           << "; mAuthSSL = " << mAuthSSL
00621           << "; mAuthTLS = " << mAuthTLS << endl;
00622   }
00623   checkHighest(mSmtp.encryptionGroup);
00624   delete mServerTest;
00625   mServerTest = 0;
00626 }
00627 
00628 
00629 void KMTransportDialog::slotOk()
00630 {
00631   saveSettings();
00632   accept();
00633 }
00634 
00635 
00636 #include "kmtransport.moc"
KDE Logo
This file is part of the documentation for kmail Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:37:34 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003