23#include "kmtransport.h" 
   25#include <tqbuttongroup.h> 
   26#include <tqcheckbox.h> 
   29#include <tqradiobutton.h> 
   30#include <tqtabwidget.h> 
   31#include <tqvalidator.h> 
   33#include <tqpushbutton.h> 
   34#include <tqwhatsthis.h> 
   36#include <tdefiledialog.h> 
   38#include <tdemessagebox.h> 
   39#include <kseparator.h> 
   42using TDEWallet::Wallet;
 
   43#include <kprotocolinfo.h> 
   46#include "kmservertest.h" 
   49#include "transportmanager.h" 
   52KMTransportInfo::KMTransportInfo() : mPasswdDirty( false ),
 
   53  mStorePasswd( false ), mStorePasswdInConfig( false ), mId( 0 )
 
   55  name = i18n(
"Unnamed");
 
   58  specifyHostname = 
false;
 
   62KMTransportInfo::~KMTransportInfo()
 
   67void KMTransportInfo::readConfig(
int id)
 
   69  TDEConfig *config = KMKernel::config();
 
   70  TDEConfigGroupSaver saver(config, 
"Transport " + TQString::number(
id));
 
   71  mId = config->readUnsignedNumEntry( 
"id", 0 );
 
   72  type = config->readEntry(
"type", 
"smtp");
 
   73  name = config->readEntry(
"name", i18n(
"Unnamed"));
 
   74  host = config->readEntry(
"host", 
"localhost");
 
   75  port = config->readEntry(
"port", 
"25");
 
   76  user = config->readEntry(
"user");
 
   77  mPasswd = KMAccount::decryptStr(config->readEntry(
"pass"));
 
   78  precommand = config->readPathEntry(
"precommand");
 
   79  encryption = config->readEntry(
"encryption");
 
   80  authType = config->readEntry(
"authtype");
 
   81  auth = config->readBoolEntry(
"auth");
 
   82  mStorePasswd = config->readBoolEntry(
"storepass");
 
   83  specifyHostname = config->readBoolEntry(
"specifyHostname", 
false);
 
   84  localHostname = config->readEntry(
"localHostname");
 
   89  if ( !mPasswd.isEmpty() ) {
 
   91    if ( Wallet::isEnabled() ) {
 
   92      config->deleteEntry( 
"pass" );
 
   94      mStorePasswdInConfig = 
false;
 
   97      mStorePasswdInConfig = 
true;
 
  100    if ( Wallet::isOpen( Wallet::NetworkWallet() ) )
 
  106void KMTransportInfo::writeConfig(
int id)
 
  108  TDEConfig *config = KMKernel::config();
 
  109  TDEConfigGroupSaver saver(config, 
"Transport " + TQString::number(
id));
 
  111    mId = TransportManager::createId();
 
  112  config->writeEntry(
"id", mId);
 
  113  config->writeEntry(
"type", type);
 
  114  config->writeEntry(
"name", name);
 
  115  config->writeEntry(
"host", host);
 
  116  config->writeEntry(
"port", port);
 
  117  config->writeEntry(
"user", user);
 
  118  config->writePathEntry(
"precommand", precommand);
 
  119  config->writeEntry(
"encryption", encryption);
 
  120  config->writeEntry(
"authtype", authType);
 
  121  config->writeEntry(
"auth", auth);
 
  122  config->writeEntry(
"storepass", storePasswd());
 
  123  config->writeEntry(
"specifyHostname", specifyHostname);
 
  124  config->writeEntry(
"localHostname", localHostname);
 
  126  if ( storePasswd() ) {
 
  128    bool passwdStored = 
false;
 
  129    Wallet *wallet = kmkernel->wallet();
 
  130    if ( mPasswdDirty ) {
 
  131      if ( wallet && wallet->writePassword( 
"transport-" + TQString::number(mId), passwd() ) == 0 ) {
 
  133        mPasswdDirty = 
false;
 
  134        mStorePasswdInConfig = 
false;
 
  137      passwdStored = wallet ? !mStorePasswdInConfig  : config->hasKey(
"pass");
 
  140    if ( !passwdStored && ( mStorePasswdInConfig ||  KMessageBox::warningYesNo( 0,
 
  141         i18n(
"TDEWallet is not available. It is strongly recommended to use " 
  142              "TDEWallet for managing your passwords.\n" 
  143              "However, KMail can store the password in its configuration " 
  144              "file instead. The password is stored in an obfuscated format, " 
  145              "but should not be considered secure from decryption efforts " 
  146              "if access to the configuration file is obtained.\n" 
  147              "Do you want to store the password for account '%1' in the " 
  148              "configuration file?").arg( name ),
 
  149         i18n(
"TDEWallet Not Available"),
 
  150         KGuiItem( i18n(
"Store Password") ),
 
  151         KGuiItem( i18n(
"Do Not Store Password") ) )
 
  152         == KMessageBox::Yes ) ) {
 
  153      config->writeEntry( 
"pass", KMAccount::encryptStr( passwd() ) );
 
  154      mStorePasswdInConfig = 
true;
 
  159  if ( !storePasswd() ) {
 
  160    if ( !Wallet::keyDoesNotExist(
 
  161          Wallet::NetworkWallet(), 
"kmail", 
"transport-" + TQString::number(mId) ) ) {
 
  162      Wallet *wallet = kmkernel->wallet();
 
  164        wallet->removeEntry( 
"transport-" + TQString::number(mId) );
 
  166    config->deleteEntry( 
"pass" );
 
  171int KMTransportInfo::findTransport(
const TQString &name)
 
  173  TDEConfig *config = KMKernel::config();
 
  174  TDEConfigGroupSaver saver(config, 
"General");
 
  175  int numTransports = config->readNumEntry(
"transports", 0);
 
  176  for (
int i = 1; i <= numTransports; i++)
 
  178    TDEConfigGroupSaver saver(config, 
"Transport " + TQString::number(i));
 
  179    if (config->readEntry(
"name") == name) 
return i;
 
  185TQStringList KMTransportInfo::availableTransports()
 
  188  TDEConfig *config = KMKernel::config();
 
  189  TDEConfigGroupSaver saver(config, 
"General");
 
  190  int numTransports = config->readNumEntry(
"transports", 0);
 
  191  for (
int i = 1; i <= numTransports; i++)
 
  193    TDEConfigGroupSaver saver(config, 
"Transport " + TQString::number(i));
 
  194    result.append(config->readEntry(
"name"));
 
  200TQString KMTransportInfo::passwd()
 const 
  202  if ( auth && storePasswd() && mPasswd.isEmpty() )
 
  208void KMTransportInfo::setPasswd( 
const TQString &passwd )
 
  210  if ( passwd != mPasswd ) {
 
  217void KMTransportInfo::setStorePasswd( 
bool store )
 
  219  if ( mStorePasswd != store && store )
 
  221  mStorePasswd = store;
 
  225void KMTransportInfo::readPassword()
 const 
  227  if ( !storePasswd() || !auth )
 
  232  if ( Wallet::isOpen( Wallet::NetworkWallet() ) ) {
 
  233    Wallet* wallet = kmkernel->wallet();
 
  234    if ( !wallet || !wallet->hasEntry( 
"transport-" + TQString::number(mId) ) )
 
  237    if ( Wallet::keyDoesNotExist( Wallet::NetworkWallet(), 
"kmail", 
"transport-" + TQString::number(mId) ) )
 
  241  if ( kmkernel->wallet() )
 
  242    kmkernel->wallet()->readPassword( 
"transport-" + TQString::number(mId), mPasswd );
 
  246KMTransportSelDlg::KMTransportSelDlg( TQWidget *parent, 
const char *name,
 
  248  : KDialogBase( parent, name, modal, i18n(
"Add Transport"), 
Ok|Cancel, 
Ok )
 
  250  TQFrame *page = makeMainWidget();
 
  251  TQVBoxLayout *topLayout = 
new TQVBoxLayout( page, 0, spacingHint() );
 
  253  TQButtonGroup *group = 
new TQButtonGroup( i18n(
"Transport"), page );
 
  254  connect(group, TQ_SIGNAL(clicked(
int)), TQ_SLOT(buttonClicked(
int)) );
 
  256  topLayout->addWidget( group, 10 );
 
  257  TQVBoxLayout *vlay = 
new TQVBoxLayout( group, spacingHint()*2, spacingHint() );
 
  258  vlay->addSpacing( fontMetrics().lineSpacing() );
 
  260  TQRadioButton *radioButton1 = 
new TQRadioButton( i18n(
"SM&TP"), group );
 
  261  vlay->addWidget( radioButton1 );
 
  262  TQRadioButton *radioButton2 = 
new TQRadioButton( i18n(
"&Sendmail"), group );
 
  263  vlay->addWidget( radioButton2 );
 
  265  vlay->addStretch( 10 );
 
  267  radioButton1->setChecked(
true); 
 
  271void KMTransportSelDlg::buttonClicked( 
int id )
 
  273  mSelectedButton = id;
 
  277int KMTransportSelDlg::selected( 
void )
 const 
  279  return mSelectedButton;
 
  283KMTransportDialog::KMTransportDialog( 
const TQString & caption,
 
  284                      KMTransportInfo *transportInfo,
 
  285                      TQWidget *parent, 
const char *name,
 
  287  : KDialogBase( parent, name, modal, caption, 
Ok|Cancel, 
Ok, true ),
 
  289    mTransportInfo( transportInfo ),
 
  290    mAuthNone( AllAuth ), mAuthSSL( AllAuth ), mAuthTLS( AllAuth )
 
  292  assert(transportInfo != 0);
 
  294  if( transportInfo->type == TQString::fromLatin1(
"sendmail") )
 
  305KMTransportDialog::~KMTransportDialog()
 
  310void KMTransportDialog::makeSendmailPage()
 
  312  TQFrame *page = makeMainWidget();
 
  313  TQVBoxLayout *topLayout = 
new TQVBoxLayout( page, 0, spacingHint() );
 
  315  mSendmail.titleLabel = 
new TQLabel( page );
 
  316  mSendmail.titleLabel->setText( i18n(
"Transport: Sendmail") );
 
  317  TQFont titleFont( mSendmail.titleLabel->font() );
 
  318  titleFont.setBold( 
true );
 
  319  mSendmail.titleLabel->setFont( titleFont );
 
  320  topLayout->addWidget( mSendmail.titleLabel );
 
  321  KSeparator *hline = 
new KSeparator( KSeparator::HLine, page);
 
  322  topLayout->addWidget( hline );
 
  324  TQGridLayout *grid = 
new TQGridLayout( topLayout, 3, 3, spacingHint() );
 
  325  grid->addColSpacing( 1, fontMetrics().maxWidth()*15 );
 
  326  grid->setRowStretch( 2, 10 );
 
  327  grid->setColStretch( 1, 10 );
 
  329  TQLabel *label = 
new TQLabel( i18n(
"&Name:"), page );
 
  330  grid->addWidget( label, 0, 0 );
 
  331  mSendmail.nameEdit = 
new KLineEdit( page );
 
  332  label->setBuddy( mSendmail.nameEdit );
 
  333  grid->addWidget( mSendmail.nameEdit, 0, 1 );
 
  335  label = 
new TQLabel( i18n(
"&Location:"), page );
 
  336  grid->addWidget( label, 1, 0 );
 
  337  mSendmail.locationEdit = 
new KLineEdit( page );
 
  338  label->setBuddy(mSendmail.locationEdit);
 
  339  grid->addWidget( mSendmail.locationEdit, 1, 1 );
 
  340  mSendmail.chooseButton =
 
  341    new TQPushButton( i18n(
"Choos&e..."), page );
 
  342  connect( mSendmail.chooseButton, TQ_SIGNAL(clicked()),
 
  343           this, TQ_SLOT(slotSendmailChooser()) );
 
  345  connect( mSendmail.locationEdit, TQ_SIGNAL(textChanged ( 
const TQString & )),
 
  346           this, TQ_SLOT(slotSendmailEditPath(
const TQString &)) );
 
  348  mSendmail.chooseButton->setAutoDefault( 
false );
 
  349  grid->addWidget( mSendmail.chooseButton, 1, 2 );
 
  350  slotSendmailEditPath(mSendmail.locationEdit->text());
 
  353void KMTransportDialog::slotSendmailEditPath(
const TQString & _text)
 
  355  enableButtonOK( !_text.isEmpty() );
 
  358void KMTransportDialog::makeSmtpPage()
 
  360  TQFrame *page = makeMainWidget();
 
  361  TQVBoxLayout *topLayout = 
new TQVBoxLayout( page, 0, spacingHint() );
 
  363  mSmtp.titleLabel = 
new TQLabel( page );
 
  364  mSmtp.titleLabel->setText( i18n(
"Transport: SMTP") );
 
  365  TQFont titleFont( mSmtp.titleLabel->font() );
 
  366  titleFont.setBold( 
true );
 
  367  mSmtp.titleLabel->setFont( titleFont );
 
  368  topLayout->addWidget( mSmtp.titleLabel );
 
  369  KSeparator *hline = 
new KSeparator( KSeparator::HLine, page);
 
  370  topLayout->addWidget( hline );
 
  372  TQTabWidget *tabWidget = 
new TQTabWidget(page);
 
  373  topLayout->addWidget( tabWidget );
 
  375  TQWidget *page1 = 
new TQWidget( tabWidget );
 
  376  tabWidget->addTab( page1, i18n(
"&General") );
 
  378  TQGridLayout *grid = 
new TQGridLayout( page1, 14, 2, spacingHint() );
 
  379  grid->addColSpacing( 1, fontMetrics().maxWidth()*15 );
 
  380  grid->setRowStretch( 13, 10 );
 
  381  grid->setColStretch( 1, 10 );
 
  383  TQLabel *label = 
new TQLabel( i18n(
"&Name:"), page1 );
 
  384  grid->addWidget( label, 0, 0 );
 
  385  mSmtp.nameEdit = 
new KLineEdit( page1 );
 
  386  TQWhatsThis::add(mSmtp.nameEdit,
 
  387                  i18n(
"The name that KMail will use when " 
  388                       "referring to this server."));
 
  389  label->setBuddy( mSmtp.nameEdit );
 
  390  grid->addWidget( mSmtp.nameEdit, 0, 1 );
 
  392  label = 
new TQLabel( i18n(
"&Host:"), page1 );
 
  393  grid->addWidget( label, 3, 0 );
 
  394  mSmtp.hostEdit = 
new KLineEdit( page1 );
 
  395  TQWhatsThis::add(mSmtp.hostEdit,
 
  396                  i18n(
"The domain name or numerical address " 
  397                       "of the SMTP server."));
 
  398  label->setBuddy( mSmtp.hostEdit );
 
  399  grid->addWidget( mSmtp.hostEdit, 3, 1 );
 
  401  label = 
new TQLabel( i18n(
"&Port:"), page1 );
 
  402  grid->addWidget( label, 4, 0 );
 
  403  mSmtp.portEdit = 
new KLineEdit( page1 );
 
  404  mSmtp.portEdit->setValidator( 
new TQIntValidator(
this) );
 
  405  TQWhatsThis::add(mSmtp.portEdit,
 
  406                  i18n(
"The port number that the SMTP server " 
  407                       "is listening on. The default port is 25."));
 
  408  label->setBuddy( mSmtp.portEdit );
 
  409  grid->addWidget( mSmtp.portEdit, 4, 1 );
 
  411  label = 
new TQLabel( i18n(
"Preco&mmand:"), page1 );
 
  412  grid->addWidget( label, 5, 0 );
 
  413  mSmtp.precommand = 
new KLineEdit( page1 );
 
  414  TQWhatsThis::add(mSmtp.precommand,
 
  415                  i18n(
"A command to run locally, prior " 
  416                       "to sending email. This can be used " 
  417                       "to set up ssh tunnels, for example. " 
  418                       "Leave it empty if no command should be run."));
 
  419  label->setBuddy(mSmtp.precommand);
 
  420  grid->addWidget( mSmtp.precommand, 5, 1 );
 
  422  TQFrame* line = 
new TQFrame( page1 );
 
  423  line->setFrameStyle( TQFrame::HLine | TQFrame::Plain );
 
  424  grid->addMultiCellWidget( line, 6, 6, 0, 1 );
 
  427    new TQCheckBox( i18n(
"Server &requires authentication"), page1 );
 
  428  TQWhatsThis::add(mSmtp.authCheck,
 
  429                  i18n(
"Check this option if your SMTP server " 
  430                       "requires authentication before accepting " 
  431                       "mail. This is known as " 
  432                       "'Authenticated SMTP' or simply ASMTP."));
 
  433  connect(mSmtp.authCheck, TQ_SIGNAL(clicked()),
 
  434          TQ_SLOT(slotRequiresAuthClicked()));
 
  435  grid->addMultiCellWidget( mSmtp.authCheck, 7, 7, 0, 1 );
 
  437  mSmtp.loginLabel = 
new TQLabel( i18n(
"&Login:"), page1 );
 
  438  grid->addWidget( mSmtp.loginLabel, 8, 0 );
 
  439  mSmtp.loginEdit = 
new KLineEdit( page1 );
 
  440  mSmtp.loginLabel->setBuddy( mSmtp.loginEdit );
 
  441  TQWhatsThis::add(mSmtp.loginEdit,
 
  442                  i18n(
"The user name to send to the server " 
  443                       "for authorization"));
 
  444  grid->addWidget( mSmtp.loginEdit, 8, 1 );
 
  446  mSmtp.passwordLabel = 
new TQLabel( i18n(
"P&assword:"), page1 );
 
  447  grid->addWidget( mSmtp.passwordLabel, 9, 0 );
 
  448  mSmtp.passwordEdit = 
new KLineEdit( page1 );
 
  449  mSmtp.passwordEdit->setEchoMode( TQLineEdit::Password );
 
  450  mSmtp.passwordLabel->setBuddy( mSmtp.passwordEdit );
 
  451  TQWhatsThis::add(mSmtp.passwordEdit,
 
  452                  i18n(
"The password to send to the server " 
  453                       "for authorization"));
 
  454  grid->addWidget( mSmtp.passwordEdit, 9, 1 );
 
  456  mSmtp.storePasswordCheck =
 
  457    new TQCheckBox( i18n(
"&Store SMTP password"), page1 );
 
  458  TQWhatsThis::add(mSmtp.storePasswordCheck,
 
  459                  i18n(
"Check this option to have KMail store " 
  460                  "the password.\nIf TDEWallet is available " 
  461                  "the password will be stored there which is considered " 
  462                  "safe.\nHowever, if TDEWallet is not available, " 
  463                  "the password will be stored in KMail's configuration " 
  464                  "file. The password is stored in an " 
  465                  "obfuscated format, but should not be " 
  466                  "considered secure from decryption efforts " 
  467                  "if access to the configuration file is obtained."));
 
  468  grid->addMultiCellWidget( mSmtp.storePasswordCheck, 10, 10, 0, 1 );
 
  470  line = 
new TQFrame( page1 );
 
  471  line->setFrameStyle( TQFrame::HLine | TQFrame::Plain );
 
  472  grid->addMultiCellWidget( line, 11, 11, 0, 1 );
 
  474  mSmtp.specifyHostnameCheck =
 
  475    new TQCheckBox( i18n(
"Sen&d custom hostname to server"), page1 );
 
  476  grid->addMultiCellWidget( mSmtp.specifyHostnameCheck, 12, 12, 0, 1 );
 
  477  TQWhatsThis::add(mSmtp.specifyHostnameCheck,
 
  478                  i18n(
"Check this option to have KMail use " 
  479                       "a custom hostname when identifying itself " 
  480                       "to the mail server." 
  481                       "<p>This is useful when your system's hostname " 
  482                       "may not be set correctly or to mask your " 
  483                       "system's true hostname."));
 
  485  mSmtp.localHostnameLabel = 
new TQLabel( i18n(
"Hos&tname:"), page1 );
 
  486  grid->addWidget( mSmtp.localHostnameLabel, 13, 0);
 
  487  mSmtp.localHostnameEdit = 
new KLineEdit( page1 );
 
  488  TQWhatsThis::add(mSmtp.localHostnameEdit,
 
  489                  i18n(
"Enter the hostname KMail should use when " 
  490                       "identifying itself to the server."));
 
  491  mSmtp.localHostnameLabel->setBuddy( mSmtp.localHostnameEdit );
 
  492  grid->addWidget( mSmtp.localHostnameEdit, 13, 1 );
 
  493  connect( mSmtp.specifyHostnameCheck, TQ_SIGNAL(toggled(
bool)),
 
  494           mSmtp.localHostnameEdit, TQ_SLOT(setEnabled(
bool)));
 
  495  connect( mSmtp.specifyHostnameCheck, TQ_SIGNAL(toggled(
bool)),
 
  496           mSmtp.localHostnameLabel, TQ_SLOT(setEnabled(
bool)));
 
  498  TQWidget *page2 = 
new TQWidget( tabWidget );
 
  499  tabWidget->addTab( page2, i18n(
"S&ecurity") );
 
  500  TQVBoxLayout *vlay = 
new TQVBoxLayout( page2, spacingHint() );
 
  501  mSmtp.encryptionGroup = 
new TQButtonGroup( 1, TQt::Horizontal,
 
  502    i18n(
"Encryption"), page2 );
 
  503  mSmtp.encryptionNone =
 
  504    new TQRadioButton( i18n(
"&None"), mSmtp.encryptionGroup );
 
  505  mSmtp.encryptionTLS =
 
  506    new TQRadioButton( i18n(
"Use &StartTLS"), mSmtp.encryptionGroup );
 
  507  mSmtp.encryptionSSL =
 
  508    new TQRadioButton( i18n(
"Enforce SSL/&TLS"), mSmtp.encryptionGroup );
 
  509  connect(mSmtp.encryptionGroup, TQ_SIGNAL(clicked(
int)),
 
  510    TQ_SLOT(slotSmtpEncryptionChanged(
int)));
 
  511  vlay->addWidget( mSmtp.encryptionGroup );
 
  513  mSmtp.authGroup = 
new TQButtonGroup( 1, TQt::Horizontal,
 
  514    i18n(
"Authentication Method"), page2 );
 
  515  mSmtp.authLogin = 
new TQRadioButton( i18n(
"Please translate this " 
  516    "authentication method only if you have a good reason", 
"&LOGIN"),
 
  518  mSmtp.authPlain = 
new TQRadioButton( i18n(
"Please translate this " 
  519    "authentication method only if you have a good reason", 
"&PLAIN"),
 
  521  mSmtp.authCramMd5 = 
new TQRadioButton( i18n(
"CRAM-MD&5"), mSmtp.authGroup );
 
  522  mSmtp.authDigestMd5 = 
new TQRadioButton( i18n(
"&DIGEST-MD5"), mSmtp.authGroup );
 
  523  mSmtp.authNTLM = 
new TQRadioButton( i18n(
"&NTLM"), mSmtp.authGroup );
 
  524  mSmtp.authGSSAPI = 
new TQRadioButton( i18n(
"&GSSAPI"), mSmtp.authGroup );
 
  525  if ( KProtocolInfo::capabilities(
"smtp").contains(
"SASL") == 0 ) {
 
  526    mSmtp.authNTLM->hide();
 
  527    mSmtp.authGSSAPI->hide();
 
  529  vlay->addWidget( mSmtp.authGroup );
 
  533  TQHBoxLayout *buttonLay = 
new TQHBoxLayout( vlay );
 
  534  mSmtp.checkCapabilities =
 
  535    new TQPushButton( i18n(
"Check &What the Server Supports"), page2 );
 
  536  connect(mSmtp.checkCapabilities, TQ_SIGNAL(clicked()),
 
  537    TQ_SLOT(slotCheckSmtpCapabilities()));
 
  538  buttonLay->addStretch();
 
  539  buttonLay->addWidget( mSmtp.checkCapabilities );
 
  543void KMTransportDialog::setupSettings()
 
  545  if (mTransportInfo->type == 
"sendmail")
 
  547    mSendmail.nameEdit->setText(mTransportInfo->name);
 
  548    mSendmail.locationEdit->setText(mTransportInfo->host);
 
  550    mSmtp.nameEdit->setText(mTransportInfo->name);
 
  551    mSmtp.hostEdit->setText(mTransportInfo->host);
 
  552    mSmtp.portEdit->setText(mTransportInfo->port);
 
  553    mSmtp.authCheck->setChecked(mTransportInfo->auth);
 
  554    mSmtp.loginEdit->setText(mTransportInfo->user);
 
  555    mSmtp.passwordEdit->setText(mTransportInfo->passwd());
 
  556    mSmtp.storePasswordCheck->setChecked(mTransportInfo->storePasswd());
 
  557    mSmtp.precommand->setText(mTransportInfo->precommand);
 
  558    mSmtp.specifyHostnameCheck->setChecked(mTransportInfo->specifyHostname);
 
  559    mSmtp.localHostnameEdit->setText(mTransportInfo->localHostname);
 
  561    if (mTransportInfo->encryption == 
"TLS")
 
  562      mSmtp.encryptionTLS->setChecked(
true);
 
  563    else if (mTransportInfo->encryption == 
"SSL")
 
  564      mSmtp.encryptionSSL->setChecked(
true);
 
  565    else mSmtp.encryptionNone->setChecked(
true);
 
  567    if (mTransportInfo->authType == 
"LOGIN")
 
  568      mSmtp.authLogin->setChecked(
true);
 
  569    else if (mTransportInfo->authType == 
"CRAM-MD5")
 
  570      mSmtp.authCramMd5->setChecked(
true);
 
  571    else if (mTransportInfo->authType == 
"DIGEST-MD5")
 
  572      mSmtp.authDigestMd5->setChecked(
true);
 
  573    else if (mTransportInfo->authType == 
"NTLM")
 
  574      mSmtp.authNTLM->setChecked(
true);
 
  575    else if (mTransportInfo->authType == 
"GSSAPI")
 
  576      mSmtp.authGSSAPI->setChecked(
true);
 
  577    else mSmtp.authPlain->setChecked(
true);
 
  579    slotRequiresAuthClicked();
 
  580    mSmtp.localHostnameEdit->setEnabled(mTransportInfo->specifyHostname);
 
  581    mSmtp.localHostnameLabel->setEnabled(mTransportInfo->specifyHostname);
 
  586void KMTransportDialog::saveSettings()
 
  588  if (mTransportInfo->type == 
"sendmail")
 
  590    mTransportInfo->name = mSendmail.nameEdit->text().stripWhiteSpace();
 
  591    mTransportInfo->host = mSendmail.locationEdit->text().stripWhiteSpace();
 
  593    mTransportInfo->name = mSmtp.nameEdit->text();
 
  594    mTransportInfo->host = mSmtp.hostEdit->text().stripWhiteSpace();
 
  595    mTransportInfo->port = mSmtp.portEdit->text().stripWhiteSpace();
 
  596    mTransportInfo->auth = mSmtp.authCheck->isChecked();
 
  597    mTransportInfo->user = mSmtp.loginEdit->text().stripWhiteSpace();
 
  598    mTransportInfo->setPasswd( mSmtp.passwordEdit->text() );
 
  599    mTransportInfo->setStorePasswd( mSmtp.storePasswordCheck->isChecked() );
 
  600    mTransportInfo->precommand = mSmtp.precommand->text().stripWhiteSpace();
 
  601    mTransportInfo->specifyHostname = mSmtp.specifyHostnameCheck->isChecked();
 
  602    mTransportInfo->localHostname = mSmtp.localHostnameEdit->text().stripWhiteSpace();
 
  604    mTransportInfo->encryption = (mSmtp.encryptionTLS->isChecked()) ? 
"TLS" :
 
  605    (mSmtp.encryptionSSL->isChecked()) ? 
"SSL" : 
"NONE";
 
  607    mTransportInfo->authType = (mSmtp.authLogin->isChecked()) ? 
"LOGIN" :
 
  608    (mSmtp.authCramMd5->isChecked()) ? 
"CRAM-MD5" :
 
  609    (mSmtp.authDigestMd5->isChecked()) ? 
"DIGEST-MD5" :
 
  610    (mSmtp.authNTLM->isChecked()) ? 
"NTLM" :
 
  611    (mSmtp.authGSSAPI->isChecked()) ? 
"GSSAPI" : 
"PLAIN";
 
  616void KMTransportDialog::slotSendmailChooser()
 
  618  KFileDialog dialog(
"/", TQString(), 
this, 0, 
true );
 
  619  dialog.setCaption(i18n(
"Choose sendmail Location") );
 
  621  if( dialog.exec() == TQDialog::Accepted )
 
  623    KURL url = dialog.selectedURL();
 
  624    if( url.isEmpty() == 
true )
 
  629    if( url.isLocalFile() == 
false )
 
  631      KMessageBox::sorry( 0, i18n( 
"Only local files allowed." ) );
 
  635    mSendmail.locationEdit->setText( url.path() );
 
  640void KMTransportDialog::slotRequiresAuthClicked()
 
  642  bool b = mSmtp.authCheck->isChecked();
 
  643  mSmtp.loginLabel->setEnabled(b);
 
  644  mSmtp.loginEdit->setEnabled(b);
 
  645  mSmtp.passwordLabel->setEnabled(b);
 
  646  mSmtp.passwordEdit->setEnabled(b);
 
  647  mSmtp.storePasswordCheck->setEnabled(b);
 
  648  mSmtp.authGroup->setEnabled(b);
 
  652void KMTransportDialog::slotSmtpEncryptionChanged(
int id)
 
  654  kdDebug(5006) << 
"KMTransportDialog::slotSmtpEncryptionChanged( " << 
id << 
" )" << endl;
 
  656  if (
id == EnforceSSL || mSmtp.portEdit->text() == 
"465")
 
  657    mSmtp.portEdit->setText((
id == EnforceSSL) ? 
"465" : 
"25");
 
  660  TQButton * old = mSmtp.authGroup->selected();
 
  661  int authMethods = 
id == StartTLS ? mAuthTLS : 
id == EnforceSSL ? mAuthSSL : mAuthNone ;
 
  662  enableAuthMethods( authMethods );
 
  663  if ( !old->isEnabled() )
 
  664    checkHighest( mSmtp.authGroup );
 
  667void KMTransportDialog::enableAuthMethods( 
unsigned int auth ) {
 
  668  kdDebug(5006) << 
"KMTransportDialog::enableAuthMethods( " << auth << 
" )" << endl;
 
  669  mSmtp.authPlain->setEnabled( auth & PLAIN );
 
  673  mSmtp.authLogin->setEnabled( auth & LOGIN );
 
  674  mSmtp.authCramMd5->setEnabled( auth & CRAM_MD5 );
 
  675  mSmtp.authDigestMd5->setEnabled( auth & DIGEST_MD5 );
 
  676  mSmtp.authNTLM->setEnabled( auth & NTLM );
 
  677  mSmtp.authGSSAPI->setEnabled( auth & GSSAPI );
 
  680unsigned int KMTransportDialog::authMethodsFromString( 
const TQString & s ) {
 
  681  unsigned int result = 0;
 
  682  TQStringList sl = TQStringList::split( 
'\n', s.upper() );
 
  683  for ( TQStringList::const_iterator it = sl.begin() ; it != sl.end() ; ++it )
 
  684    if (  *it == 
"SASL/LOGIN" )
 
  686    else if ( *it == 
"SASL/PLAIN" )
 
  688    else if ( *it == 
"SASL/CRAM-MD5" )
 
  690    else if ( *it == 
"SASL/DIGEST-MD5" )
 
  691      result |= DIGEST_MD5;
 
  692    else if ( *it == 
"SASL/NTLM" )
 
  694    else if ( *it == 
"SASL/GSSAPI" )
 
  699unsigned int KMTransportDialog::authMethodsFromStringList( 
const TQStringList & sl ) {
 
  700  unsigned int result = 0;
 
  701  for ( TQStringList::const_iterator it = sl.begin() ; it != sl.end() ; ++it )
 
  702    if ( *it == 
"LOGIN" )
 
  704    else if ( *it == 
"PLAIN" )
 
  706    else if ( *it == 
"CRAM-MD5" )
 
  708    else if ( *it == 
"DIGEST-MD5" )
 
  709      result |= DIGEST_MD5;
 
  710    else if ( *it == 
"NTLM" )
 
  712    else if ( *it == 
"GSSAPI" )
 
  717void KMTransportDialog::slotCheckSmtpCapabilities()
 
  720  mServerTest = 
new KMServerTest(SMTP_PROTOCOL, mSmtp.hostEdit->text(),
 
  721    mSmtp.portEdit->text().toInt());
 
  722  connect( mServerTest,
 
  723           TQ_SIGNAL( capabilities( 
const TQStringList &, 
const TQStringList &,
 
  724                                 const TQString &, 
const TQString &,
 
  727           TQ_SLOT( slotSmtpCapabilities( 
const TQStringList &,
 
  728                                       const TQStringList &, 
const TQString &,
 
  729                                       const TQString &, 
const TQString & ) ) );
 
  730  mSmtp.checkCapabilities->setEnabled(
false);
 
  734void KMTransportDialog::checkHighest(TQButtonGroup *btnGroup)
 
  736  for ( 
int i = btnGroup->count() - 1; i >= 0 ; --i )
 
  738    TQButton * btn = btnGroup->find(i);
 
  739    if (btn && btn->isEnabled())
 
  748void KMTransportDialog::slotSmtpCapabilities( 
const TQStringList & capaNormal,
 
  749                                              const TQStringList & capaSSL,
 
  750                                              const TQString & authNone,
 
  751                                              const TQString & authSSL,
 
  752                                              const TQString & authTLS )
 
  754  mSmtp.checkCapabilities->setEnabled( 
true );
 
  755  kdDebug(5006) << 
"KMTransportDialog::slotSmtpCapabilities( ..., " 
  756        << authNone << 
", " << authSSL << 
", " << authTLS << 
" )" << endl;
 
  757  mSmtp.encryptionNone->setEnabled( !capaNormal.isEmpty() );
 
  758  mSmtp.encryptionSSL->setEnabled( !capaSSL.isEmpty() );
 
  759  mSmtp.encryptionTLS->setEnabled( capaNormal.findIndex(
"STARTTLS") != -1 );
 
  760  if ( authNone.isEmpty() && authSSL.isEmpty() && authTLS.isEmpty() ) {
 
  762    mAuthNone = authMethodsFromStringList( capaNormal );
 
  763    if ( mSmtp.encryptionTLS->isEnabled() )
 
  764      mAuthTLS = mAuthNone;
 
  767    mAuthSSL = authMethodsFromStringList( capaSSL );
 
  770    mAuthNone = authMethodsFromString( authNone );
 
  771    mAuthSSL = authMethodsFromString( authSSL );
 
  772    mAuthTLS = authMethodsFromString( authTLS );
 
  774  kdDebug(5006) << 
"mAuthNone = " << mAuthNone
 
  775                << 
"; mAuthSSL = " << mAuthSSL
 
  776                << 
"; mAuthTLS = " << mAuthTLS << endl;
 
  777  checkHighest( mSmtp.encryptionGroup );
 
  781bool KMTransportDialog::sanityCheckSmtpInput()
 
  785  if ( mSmtp.hostEdit->text().isEmpty() ) {
 
  786    TQString errorMsg = i18n(
"The Host field cannot be empty. Please  " 
  787                            "enter the name or the IP address of the SMTP server.");
 
  788    KMessageBox::sorry( 
this, errorMsg, i18n(
"Invalid Hostname or Address") );
 
  794void KMTransportDialog::slotOk()
 
  796  if (mTransportInfo->type != 
"sendmail") {
 
  797    if( !sanityCheckSmtpInput() ) {
 
  807#include "kmtransport.moc" 
@ Ok
The user rights/ACL have been fetched from the server sucessfully.