kmail

kmtransport.cpp
1 
20 #include <config.h>
21 #include <assert.h>
22 
23 #include "kmtransport.h"
24 
25 #include <tqbuttongroup.h>
26 #include <tqcheckbox.h>
27 #include <tqlayout.h>
28 #include <klineedit.h>
29 #include <tqradiobutton.h>
30 #include <tqtabwidget.h>
31 #include <tqvalidator.h>
32 #include <tqlabel.h>
33 #include <tqpushbutton.h>
34 #include <tqwhatsthis.h>
35 
36 #include <tdefiledialog.h>
37 #include <tdelocale.h>
38 #include <tdemessagebox.h>
39 #include <kseparator.h>
40 #include <kdebug.h>
41 #include <tdewallet.h>
42 using TDEWallet::Wallet;
43 #include <kprotocolinfo.h>
44 
45 #include "kmkernel.h"
46 #include "kmservertest.h"
47 #include "kmaccount.h"
48 #include "protocols.h"
49 #include "transportmanager.h"
50 using namespace KMail;
51 
52 KMTransportInfo::KMTransportInfo() : mPasswdDirty( false ),
53  mStorePasswd( false ), mStorePasswdInConfig( false ), mId( 0 )
54 {
55  name = i18n("Unnamed");
56  port = "25";
57  auth = false;
58  specifyHostname = false;
59 }
60 
61 
62 KMTransportInfo::~KMTransportInfo()
63 {
64 }
65 
66 
67 void KMTransportInfo::readConfig(int id)
68 {
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");
85 
86  if ( !storePasswd() )
87  return;
88 
89  if ( !mPasswd.isEmpty() ) {
90  // migration to tdewallet if available
91  if ( Wallet::isEnabled() ) {
92  config->deleteEntry( "pass" );
93  mPasswdDirty = true;
94  mStorePasswdInConfig = false;
95  writeConfig( id );
96  } else
97  mStorePasswdInConfig = true;
98  } else {
99  // read password if wallet is open, defer otherwise
100  if ( Wallet::isOpen( Wallet::NetworkWallet() ) )
101  readPassword();
102  }
103 }
104 
105 
106 void KMTransportInfo::writeConfig(int id)
107 {
108  TDEConfig *config = KMKernel::config();
109  TDEConfigGroupSaver saver(config, "Transport " + TQString::number(id));
110  if (!mId)
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);
125 
126  if ( storePasswd() ) {
127  // write password into the wallet if possible and necessary
128  bool passwdStored = false;
129  Wallet *wallet = kmkernel->wallet();
130  if ( mPasswdDirty ) {
131  if ( wallet && wallet->writePassword( "transport-" + TQString::number(mId), passwd() ) == 0 ) {
132  passwdStored = true;
133  mPasswdDirty = false;
134  mStorePasswdInConfig = false;
135  }
136  } else {
137  passwdStored = wallet ? !mStorePasswdInConfig /*already in the wallet*/ : config->hasKey("pass");
138  }
139  // wallet not available, ask the user if we should use the config file instead
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;
155  }
156  }
157 
158  // delete already stored password if password storage is disabled
159  if ( !storePasswd() ) {
160  if ( !Wallet::keyDoesNotExist(
161  Wallet::NetworkWallet(), "kmail", "transport-" + TQString::number(mId) ) ) {
162  Wallet *wallet = kmkernel->wallet();
163  if ( wallet )
164  wallet->removeEntry( "transport-" + TQString::number(mId) );
165  }
166  config->deleteEntry( "pass" );
167  }
168 }
169 
170 
171 int KMTransportInfo::findTransport(const TQString &name)
172 {
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++)
177  {
178  TDEConfigGroupSaver saver(config, "Transport " + TQString::number(i));
179  if (config->readEntry("name") == name) return i;
180  }
181  return 0;
182 }
183 
184 
185 TQStringList KMTransportInfo::availableTransports()
186 {
187  TQStringList result;
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++)
192  {
193  TDEConfigGroupSaver saver(config, "Transport " + TQString::number(i));
194  result.append(config->readEntry("name"));
195  }
196  return result;
197 }
198 
199 
200 TQString KMTransportInfo::passwd() const
201 {
202  if ( auth && storePasswd() && mPasswd.isEmpty() )
203  readPassword();
204  return mPasswd;
205 }
206 
207 
208 void KMTransportInfo::setPasswd( const TQString &passwd )
209 {
210  if ( passwd != mPasswd ) {
211  mPasswd = passwd;
212  mPasswdDirty = true;
213  }
214 }
215 
216 
217 void KMTransportInfo::setStorePasswd( bool store )
218 {
219  if ( mStorePasswd != store && store )
220  mPasswdDirty = true;
221  mStorePasswd = store;
222 }
223 
224 
225 void KMTransportInfo::readPassword() const
226 {
227  if ( !storePasswd() || !auth )
228  return;
229 
230  // ### workaround for broken Wallet::keyDoesNotExist() which returns wrong
231  // results for new entries without closing and reopening the wallet
232  if ( Wallet::isOpen( Wallet::NetworkWallet() ) ) {
233  Wallet* wallet = kmkernel->wallet();
234  if ( !wallet || !wallet->hasEntry( "transport-" + TQString::number(mId) ) )
235  return;
236  } else {
237  if ( Wallet::keyDoesNotExist( Wallet::NetworkWallet(), "kmail", "transport-" + TQString::number(mId) ) )
238  return;
239  }
240 
241  if ( kmkernel->wallet() )
242  kmkernel->wallet()->readPassword( "transport-" + TQString::number(mId), mPasswd );
243 }
244 
245 
246 KMTransportSelDlg::KMTransportSelDlg( TQWidget *parent, const char *name,
247  bool modal )
248  : KDialogBase( parent, name, modal, i18n("Add Transport"), Ok|Cancel, Ok )
249 {
250  TQFrame *page = makeMainWidget();
251  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
252 
253  TQButtonGroup *group = new TQButtonGroup( i18n("Transport"), page );
254  connect(group, TQ_SIGNAL(clicked(int)), TQ_SLOT(buttonClicked(int)) );
255 
256  topLayout->addWidget( group, 10 );
257  TQVBoxLayout *vlay = new TQVBoxLayout( group, spacingHint()*2, spacingHint() );
258  vlay->addSpacing( fontMetrics().lineSpacing() );
259 
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 );
264 
265  vlay->addStretch( 10 );
266 
267  radioButton1->setChecked(true); // Pop is most common ?
268  buttonClicked(0);
269 }
270 
271 void KMTransportSelDlg::buttonClicked( int id )
272 {
273  mSelectedButton = id;
274 }
275 
276 
277 int KMTransportSelDlg::selected( void ) const
278 {
279  return mSelectedButton;
280 }
281 
282 
283 KMTransportDialog::KMTransportDialog( const TQString & caption,
284  KMTransportInfo *transportInfo,
285  TQWidget *parent, const char *name,
286  bool modal )
287  : KDialogBase( parent, name, modal, caption, Ok|Cancel, Ok, true ),
288  mServerTest( 0 ),
289  mTransportInfo( transportInfo ),
290  mAuthNone( AllAuth ), mAuthSSL( AllAuth ), mAuthTLS( AllAuth )
291 {
292  assert(transportInfo != 0);
293 
294  if( transportInfo->type == TQString::fromLatin1("sendmail") )
295  {
296  makeSendmailPage();
297  } else {
298  makeSmtpPage();
299  }
300 
301  setupSettings();
302 }
303 
304 
305 KMTransportDialog::~KMTransportDialog()
306 {
307 }
308 
309 
310 void KMTransportDialog::makeSendmailPage()
311 {
312  TQFrame *page = makeMainWidget();
313  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
314 
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 );
323 
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 );
328 
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 );
334 
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()) );
344 
345  connect( mSendmail.locationEdit, TQ_SIGNAL(textChanged ( const TQString & )),
346  this, TQ_SLOT(slotSendmailEditPath(const TQString &)) );
347 
348  mSendmail.chooseButton->setAutoDefault( false );
349  grid->addWidget( mSendmail.chooseButton, 1, 2 );
350  slotSendmailEditPath(mSendmail.locationEdit->text());
351 }
352 
353 void KMTransportDialog::slotSendmailEditPath(const TQString & _text)
354 {
355  enableButtonOK( !_text.isEmpty() );
356 }
357 
358 void KMTransportDialog::makeSmtpPage()
359 {
360  TQFrame *page = makeMainWidget();
361  TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
362 
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 );
371 
372  TQTabWidget *tabWidget = new TQTabWidget(page);
373  topLayout->addWidget( tabWidget );
374 
375  TQWidget *page1 = new TQWidget( tabWidget );
376  tabWidget->addTab( page1, i18n("&General") );
377 
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 );
382 
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 );
391 
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 );
400 
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 );
410 
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 );
421 
422  TQFrame* line = new TQFrame( page1 );
423  line->setFrameStyle( TQFrame::HLine | TQFrame::Plain );
424  grid->addMultiCellWidget( line, 6, 6, 0, 1 );
425 
426  mSmtp.authCheck =
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 );
436 
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 );
445 
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 );
455 
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 );
469 
470  line = new TQFrame( page1 );
471  line->setFrameStyle( TQFrame::HLine | TQFrame::Plain );
472  grid->addMultiCellWidget( line, 11, 11, 0, 1 );
473 
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."));
484 
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)));
497 
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.encryptionSSL =
506  new TQRadioButton( i18n("&SSL"), mSmtp.encryptionGroup );
507  mSmtp.encryptionTLS =
508  new TQRadioButton( i18n("&TLS"), mSmtp.encryptionGroup );
509  connect(mSmtp.encryptionGroup, TQ_SIGNAL(clicked(int)),
510  TQ_SLOT(slotSmtpEncryptionChanged(int)));
511  vlay->addWidget( mSmtp.encryptionGroup );
512 
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"),
517  mSmtp.authGroup );
518  mSmtp.authPlain = new TQRadioButton( i18n("Please translate this "
519  "authentication method only if you have a good reason", "&PLAIN"),
520  mSmtp.authGroup );
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();
528  }
529  vlay->addWidget( mSmtp.authGroup );
530 
531  vlay->addStretch();
532 
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 );
540 }
541 
542 
543 void KMTransportDialog::setupSettings()
544 {
545  if (mTransportInfo->type == "sendmail")
546  {
547  mSendmail.nameEdit->setText(mTransportInfo->name);
548  mSendmail.locationEdit->setText(mTransportInfo->host);
549  } else {
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);
560 
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);
566 
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);
578 
579  slotRequiresAuthClicked();
580  mSmtp.localHostnameEdit->setEnabled(mTransportInfo->specifyHostname);
581  mSmtp.localHostnameLabel->setEnabled(mTransportInfo->specifyHostname);
582  }
583 }
584 
585 
586 void KMTransportDialog::saveSettings()
587 {
588  if (mTransportInfo->type == "sendmail")
589  {
590  mTransportInfo->name = mSendmail.nameEdit->text().stripWhiteSpace();
591  mTransportInfo->host = mSendmail.locationEdit->text().stripWhiteSpace();
592  } else {
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();
603 
604  mTransportInfo->encryption = (mSmtp.encryptionTLS->isChecked()) ? "TLS" :
605  (mSmtp.encryptionSSL->isChecked()) ? "SSL" : "NONE";
606 
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";
612  }
613 }
614 
615 
616 void KMTransportDialog::slotSendmailChooser()
617 {
618  KFileDialog dialog("/", TQString(), this, 0, true );
619  dialog.setCaption(i18n("Choose sendmail Location") );
620 
621  if( dialog.exec() == TQDialog::Accepted )
622  {
623  KURL url = dialog.selectedURL();
624  if( url.isEmpty() == true )
625  {
626  return;
627  }
628 
629  if( url.isLocalFile() == false )
630  {
631  KMessageBox::sorry( 0, i18n( "Only local files allowed." ) );
632  return;
633  }
634 
635  mSendmail.locationEdit->setText( url.path() );
636  }
637 }
638 
639 
640 void KMTransportDialog::slotRequiresAuthClicked()
641 {
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);
649 }
650 
651 
652 void KMTransportDialog::slotSmtpEncryptionChanged(int id)
653 {
654  kdDebug(5006) << "KMTransportDialog::slotSmtpEncryptionChanged( " << id << " )" << endl;
655  // adjust SSL port:
656  if (id == SSL || mSmtp.portEdit->text() == "465")
657  mSmtp.portEdit->setText((id == SSL) ? "465" : "25");
658 
659  // switch supported auth methods:
660  TQButton * old = mSmtp.authGroup->selected();
661  int authMethods = id == TLS ? mAuthTLS : id == SSL ? mAuthSSL : mAuthNone ;
662  enableAuthMethods( authMethods );
663  if ( !old->isEnabled() )
664  checkHighest( mSmtp.authGroup );
665 }
666 
667 void KMTransportDialog::enableAuthMethods( unsigned int auth ) {
668  kdDebug(5006) << "KMTransportDialog::enableAuthMethods( " << auth << " )" << endl;
669  mSmtp.authPlain->setEnabled( auth & PLAIN );
670  // LOGIN doesn't offer anything over PLAIN, requires more server
671  // roundtrips and is not an official SASL mechanism, but a MS-ism,
672  // so only enable it if PLAIN isn't available:
673  mSmtp.authLogin->setEnabled( auth & LOGIN /*&& !(auth & PLAIN)*/);
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 );
678 }
679 
680 unsigned 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" )
685  result |= LOGIN;
686  else if ( *it == "SASL/PLAIN" )
687  result |= PLAIN;
688  else if ( *it == "SASL/CRAM-MD5" )
689  result |= CRAM_MD5;
690  else if ( *it == "SASL/DIGEST-MD5" )
691  result |= DIGEST_MD5;
692  else if ( *it == "SASL/NTLM" )
693  result |= NTLM;
694  else if ( *it == "SASL/GSSAPI" )
695  result |= GSSAPI;
696  return result;
697 }
698 
699 unsigned 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" )
703  result |= LOGIN;
704  else if ( *it == "PLAIN" )
705  result |= PLAIN;
706  else if ( *it == "CRAM-MD5" )
707  result |= CRAM_MD5;
708  else if ( *it == "DIGEST-MD5" )
709  result |= DIGEST_MD5;
710  else if ( *it == "NTLM" )
711  result |= NTLM;
712  else if ( *it == "GSSAPI" )
713  result |= GSSAPI;
714  return result;
715 }
716 
717 void KMTransportDialog::slotCheckSmtpCapabilities()
718 {
719  delete mServerTest;
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 &,
725  const TQString & )),
726  this,
727  TQ_SLOT( slotSmtpCapabilities( const TQStringList &,
728  const TQStringList &, const TQString &,
729  const TQString &, const TQString & ) ) );
730  mSmtp.checkCapabilities->setEnabled(false);
731 }
732 
733 
734 void KMTransportDialog::checkHighest(TQButtonGroup *btnGroup)
735 {
736  for ( int i = btnGroup->count() - 1; i >= 0 ; --i )
737  {
738  TQButton * btn = btnGroup->find(i);
739  if (btn && btn->isEnabled())
740  {
741  btn->animateClick();
742  return;
743  }
744  }
745 }
746 
747 
748 void KMTransportDialog::slotSmtpCapabilities( const TQStringList & capaNormal,
749  const TQStringList & capaSSL,
750  const TQString & authNone,
751  const TQString & authSSL,
752  const TQString & authTLS )
753 {
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() ) {
761  // slave doesn't seem to support "* AUTH METHODS" metadata (or server can't do AUTH)
762  mAuthNone = authMethodsFromStringList( capaNormal );
763  if ( mSmtp.encryptionTLS->isEnabled() )
764  mAuthTLS = mAuthNone;
765  else
766  mAuthTLS = 0;
767  mAuthSSL = authMethodsFromStringList( capaSSL );
768  }
769  else {
770  mAuthNone = authMethodsFromString( authNone );
771  mAuthSSL = authMethodsFromString( authSSL );
772  mAuthTLS = authMethodsFromString( authTLS );
773  }
774  kdDebug(5006) << "mAuthNone = " << mAuthNone
775  << "; mAuthSSL = " << mAuthSSL
776  << "; mAuthTLS = " << mAuthTLS << endl;
777  checkHighest( mSmtp.encryptionGroup );
778  delete mServerTest;
779  mServerTest = 0;
780 }
781 bool KMTransportDialog::sanityCheckSmtpInput()
782 {
783  // FIXME: add additional checks for all fields that needs it
784  // this is only the beginning
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") );
789  return false;
790  }
791  return true;
792 }
793 
794 void KMTransportDialog::slotOk()
795 {
796  if (mTransportInfo->type != "sendmail") {
797  if( !sanityCheckSmtpInput() ) {
798  return;
799  }
800  }
801 
802  saveSettings();
803  accept();
804 }
805 
806 
807 #include "kmtransport.moc"
@ Ok
The user rights/ACL have been fetched from the server sucessfully.
Definition: acljobs.h:66
folderdiaquotatab.h
Definition: aboutdata.cpp:40