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