kmail

accountwizard.cpp
1 /*******************************************************************************
2 **
3 ** Filename : accountwizard.cpp
4 ** Created on : 07 February, 2005
5 ** Copyright : (c) 2005 Tobias Koenig
6 ** Email : tokoe@kde.org
7 **
8 *******************************************************************************/
9 
10 /*******************************************************************************
11 **
12 ** This program is free software; you can redistribute it and/or modify
13 ** it under the terms of the GNU General Public License as published by
14 ** the Free Software Foundation; either version 2 of the License, or
15 ** (at your option) any later version.
16 **
17 ** In addition, as a special exception, the copyright holders give
18 ** permission to link the code of this program with any edition of
19 ** the TQt library by Trolltech AS, Norway (or with modified versions
20 ** of TQt that use the same license as TQt), and distribute linked
21 ** combinations including the two. You must obey the GNU General
22 ** Public License in all respects for all of the code used other than
23 ** TQt. If you modify this file, you may extend this exception to
24 ** your version of the file, but you are not obligated to do so. If
25 ** you do not wish to do so, delete this exception statement from
26 ** your version.
27 *******************************************************************************/
28 
29 #include <kdialog.h>
30 #include <tdefiledialog.h>
31 #include <klineedit.h>
32 #include <tdelistbox.h>
33 #include <tdelocale.h>
34 
35 #include <tqcheckbox.h>
36 #include <tqdir.h>
37 #include <tqhbox.h>
38 #include <tqlabel.h>
39 #include <tqlayout.h>
40 #include <tqpushbutton.h>
41 #include <tqvbox.h>
42 
43 #include "kmacctlocal.h"
44 #include "kmkernel.h"
45 #include "popaccount.h"
46 #include "kmacctimap.h"
47 #include "kmacctcachedimap.h"
48 #include "kmacctmaildir.h"
49 #include "accountmanager.h"
51 
52 #include "globalsettings.h"
53 #include "kmservertest.h"
54 #include "kmtransport.h"
55 #include "libkpimidentities/identity.h"
56 #include "libkpimidentities/identitymanager.h"
57 #include "protocols.h"
58 
59 #include "accountwizard.h"
60 
61 enum Capabilities
62 {
63  Plain = 1,
64  Login = 2,
65  CRAM_MD5 = 4,
66  Digest_MD5 = 8,
67  Anonymous = 16,
68  APOP = 32,
69  Pipelining = 64,
70  TOP = 128,
71  UIDL = 256,
72  STLS = 512, // TLS for POP
73  STARTTLS = 512, // TLS for IMAP
74  GSSAPI = 1024,
75  NTLM = 2048,
76  AllCapa = 0xffffffff
77 };
78 
79 class AccountTypeBox : public TDEListBox
80 {
81  public:
82  enum Type { Local, POP3, IMAP, dIMAP, Maildir };
83 
84  AccountTypeBox( TQWidget *parent )
85  : TDEListBox( parent, "AccountTypeBox" )
86  {
87  mTypeList << i18n( "Local mailbox" );
88  mTypeList << i18n( "POP3" );
89  mTypeList << i18n( "IMAP" );
90  mTypeList << i18n( "Disconnected IMAP" );
91  mTypeList << i18n( "Maildir mailbox" );
92 
93  insertStringList( mTypeList );
94  }
95 
96  void setType( Type type )
97  {
98  setCurrentItem( (int)type );
99  }
100 
101  Type type() const
102  {
103  return (Type)currentItem();
104  }
105 
106  private:
107  TQStringList mTypeList;
108 };
109 
110 AccountWizard::AccountWizard( KMKernel *kernel, TQWidget *parent )
111  : KWizard( parent, "KWizard" ), mKernel( kernel ),
112  mAccount( 0 ), mTransportInfo( 0 ), mServerTest( 0 )
113 {
114  setupWelcomePage();
115  setupAccountTypePage();
116  setupAccountInformationPage();
117  setupLoginInformationPage();
118  setupServerInformationPage();
119 }
120 
121 void AccountWizard::start( KMKernel *kernel, TQWidget *parent )
122 {
123  TDEConfigGroup wizardConfig( KMKernel::config(), "AccountWizard" );
124 
125  if ( wizardConfig.readBoolEntry( "ShowOnStartup", true ) ) {
126  AccountWizard wizard( kernel, parent );
127  int result = wizard.exec();
128  if ( result == TQDialog::Accepted ) {
129  wizardConfig.writeEntry( "ShowOnStartup", false );
130  kernel->slotConfigChanged();
131  }
132  }
133 }
134 
135 void AccountWizard::showPage( TQWidget *page )
136 {
137  if ( page == mWelcomePage ) {
138  // do nothing
139  } else if ( page == mAccountTypePage ) {
140  if ( mTypeBox->currentItem() == -1 )
141  mTypeBox->setType( AccountTypeBox::POP3 );
142  } else if ( page == mAccountInformationPage ) {
143  if ( mRealName->text().isEmpty() && mEMailAddress->text().isEmpty() &&
144  mOrganization->text().isEmpty() ) {
145  KPIM::IdentityManager *manager = mKernel->identityManager();
146  const KPIM::Identity &identity = manager->defaultIdentity();
147 
148  mRealName->setText( identity.fullName() );
149  mEMailAddress->setText( identity.primaryEmailAddress() );
150  mOrganization->setText( identity.organization() );
151  }
152  } else if ( page == mLoginInformationPage ) {
153  if ( mLoginName->text().isEmpty() ) {
154  // try to extract login from email address
155  TQString email = mEMailAddress->text();
156  int pos = email.find( '@' );
157  if ( pos != -1 )
158  mLoginName->setText( email.left( pos ) );
159 
160  // take the whole email as login otherwise?!?
161  }
162  } else if ( page == mServerInformationPage ) {
163  if ( mTypeBox->type() == AccountTypeBox::Local ||
164  mTypeBox->type() == AccountTypeBox::Maildir ) {
165  mIncomingServerWdg->hide();
166  mIncomingLocationWdg->show();
167  mIncomingLabel->setText( i18n( "Location:" ) );
168 
169  if ( mTypeBox->type() == AccountTypeBox::Local )
170  mIncomingLocation->setText( TQDir::homeDirPath() + "/inbox" );
171  else
172  mIncomingLocation->setText( TQDir::homeDirPath() + "/Mail/" );
173  } else {
174  mIncomingLocationWdg->hide();
175  mIncomingServerWdg->show();
176  mIncomingLabel->setText( i18n( "Incoming server:" ) );
177  }
178 
179  setFinishEnabled( mServerInformationPage, true );
180  }
181 
182  TQWizard::showPage( page );
183 }
184 
185 void AccountWizard::setupWelcomePage()
186 {
187  mWelcomePage = new TQVBox( this );
188  ((TQVBox*)mWelcomePage)->setSpacing( KDialog::spacingHint() );
189 
190  TQLabel *label = new TQLabel( i18n( "Welcome to KMail" ), mWelcomePage );
191  TQFont font = label->font();
192  font.setBold( true );
193  label->setFont( font );
194 
195  new TQLabel( i18n( "<qt>It seems you have started KMail for the first time. "
196  "You can use this wizard to setup your mail accounts. Just "
197  "enter the connection data that you received from your email provider "
198  "into the following pages.</qt>" ), mWelcomePage );
199 
200  addPage( mWelcomePage, i18n( "Welcome" ) );
201 }
202 
203 void AccountWizard::setupAccountTypePage()
204 {
205  mAccountTypePage = new TQVBox( this );
206  ((TQVBox*)mAccountTypePage)->setSpacing( KDialog::spacingHint() );
207 
208  new TQLabel( i18n( "Select what kind of account you would like to create" ), mAccountTypePage );
209 
210  mTypeBox = new AccountTypeBox( mAccountTypePage );
211 
212  addPage( mAccountTypePage, i18n( "Account Type" ) );
213 }
214 
215 void AccountWizard::setupAccountInformationPage()
216 {
217  mAccountInformationPage = new TQWidget( this );
218  TQGridLayout *layout = new TQGridLayout( mAccountInformationPage, 3, 2,
219  KDialog::marginHint(), KDialog::spacingHint() );
220 
221  TQLabel *label = new TQLabel( i18n( "Real name:" ), mAccountInformationPage );
222  mRealName = new KLineEdit( mAccountInformationPage );
223  label->setBuddy( mRealName );
224 
225  layout->addWidget( label, 0, 0 );
226  layout->addWidget( mRealName, 0, 1 );
227 
228  label = new TQLabel( i18n( "E-mail address:" ), mAccountInformationPage );
229  mEMailAddress = new KLineEdit( mAccountInformationPage );
230  label->setBuddy( mEMailAddress );
231 
232  layout->addWidget( label, 1, 0 );
233  layout->addWidget( mEMailAddress, 1, 1 );
234 
235  label = new TQLabel( i18n( "Organization:" ), mAccountInformationPage );
236  mOrganization = new KLineEdit( mAccountInformationPage );
237  label->setBuddy( mOrganization );
238 
239  layout->addWidget( label, 2, 0 );
240  layout->addWidget( mOrganization, 2, 1 );
241 
242  addPage( mAccountInformationPage, i18n( "Account Information" ) );
243 }
244 
245 void AccountWizard::setupLoginInformationPage()
246 {
247  mLoginInformationPage = new TQWidget( this );
248  TQGridLayout *layout = new TQGridLayout( mLoginInformationPage, 2, 2,
249  KDialog::marginHint(), KDialog::spacingHint() );
250 
251  TQLabel *label = new TQLabel( i18n( "Login name:" ), mLoginInformationPage );
252  mLoginName = new KLineEdit( mLoginInformationPage );
253  label->setBuddy( mLoginName );
254 
255  layout->addWidget( label, 0, 0 );
256  layout->addWidget( mLoginName, 0, 1 );
257 
258  label = new TQLabel( i18n( "Password:" ), mLoginInformationPage );
259  mPassword = new KLineEdit( mLoginInformationPage );
260  mPassword->setEchoMode( TQLineEdit::Password );
261  label->setBuddy( mPassword );
262 
263  layout->addWidget( label, 1, 0 );
264  layout->addWidget( mPassword, 1, 1 );
265 
266  addPage( mLoginInformationPage, i18n( "Login Information" ) );
267 }
268 
269 void AccountWizard::setupServerInformationPage()
270 {
271  mServerInformationPage = new TQWidget( this );
272  TQGridLayout *layout = new TQGridLayout( mServerInformationPage, 3, 2,
273  KDialog::marginHint(), KDialog::spacingHint() );
274 
275  mIncomingLabel = new TQLabel( mServerInformationPage );
276 
277  mIncomingServerWdg = new TQVBox( mServerInformationPage );
278  mIncomingServer = new KLineEdit( mIncomingServerWdg );
279  mIncomingUseSSL = new TQCheckBox( i18n( "Use secure connection (SSL)" ), mIncomingServerWdg );
280 
281  mIncomingLocationWdg = new TQHBox( mServerInformationPage );
282  mIncomingLocation = new KLineEdit( mIncomingLocationWdg );
283  mChooseLocation = new TQPushButton( i18n( "Choose..." ), mIncomingLocationWdg );
284 
285  connect( mChooseLocation, TQ_SIGNAL( clicked() ),
286  this, TQ_SLOT( chooseLocation() ) );
287 
288  layout->addWidget( mIncomingLabel, 0, 0, AlignTop );
289  layout->addWidget( mIncomingLocationWdg, 0, 1 );
290  layout->addWidget( mIncomingServerWdg, 0, 1 );
291 
292  TQLabel *label = new TQLabel( i18n( "Outgoing server:" ), mServerInformationPage );
293  mOutgoingServer = new KLineEdit( mServerInformationPage );
294  label->setBuddy( mOutgoingServer );
295 
296  layout->addWidget( label, 1, 0 );
297  layout->addWidget( mOutgoingServer, 1, 1 );
298 
299  mOutgoingUseSSL = new TQCheckBox( i18n( "Use secure connection (SSL)" ), mServerInformationPage );
300  layout->addWidget( mOutgoingUseSSL, 2, 1 );
301 
302  mLocalDelivery = new TQCheckBox( i18n( "Use local delivery" ),
303  mServerInformationPage );
304  layout->addWidget( mLocalDelivery, 3, 0 );
305 
306  connect( mLocalDelivery, TQ_SIGNAL( toggled( bool ) ),
307  mOutgoingServer, TQ_SLOT( setDisabled( bool ) ) );
308 
309  addPage( mServerInformationPage, i18n( "Server Information" ) );
310 }
311 
312 void AccountWizard::chooseLocation()
313 {
314  TQString location;
315 
316  if ( mTypeBox->type() == AccountTypeBox::Local ) {
317  location = KFileDialog::getSaveFileName( TQString(), TQString(), this );
318  } else if ( mTypeBox->type() == AccountTypeBox::Maildir ) {
319  location = KFileDialog::getExistingDirectory( TQString(), this );
320  }
321 
322  if ( !location.isEmpty() )
323  mIncomingLocation->setText( location );
324 }
325 
326 TQString AccountWizard::accountName() const
327 {
328  // create account name
329  TQString name( i18n( "None" ) );
330 
331  TQString email = mEMailAddress->text();
332  int pos = email.find( '@' );
333  if ( pos != -1 ) {
334  name = email.mid( pos + 1 );
335  name[ 0 ] = name[ 0 ].upper();
336  }
337 
338  return name;
339 }
340 
341 TQLabel *AccountWizard::createInfoLabel( const TQString &msg )
342 {
343  TQLabel *label = new TQLabel( msg, this );
344  label->setFrameStyle( TQFrame::Panel | TQFrame::Raised );
345  label->resize( fontMetrics().width( msg ) + 20, label->height() * 2 );
346  label->move( width() / 2 - label->width() / 2, height() / 2 - label->height() / 2 );
347  label->show();
348 
349  return label;
350 }
351 
352 void AccountWizard::accept()
353 {
354  // store identity information
355  KPIM::IdentityManager *manager = mKernel->identityManager();
356  KPIM::Identity &identity = manager->modifyIdentityForUoid( manager->defaultIdentity().uoid() );
357 
358  identity.setFullName( mRealName->text() );
359  identity.setPrimaryEmailAddress( mEMailAddress->text() );
360  identity.setOrganization( mOrganization->text() );
361 
362  manager->commit();
363 
364  TQTimer::singleShot( 0, this, TQ_SLOT( createTransport() ) );
365 }
366 
367 void AccountWizard::createTransport()
368 {
369  // create outgoing account
370  TDEConfigGroup general( KMKernel::config(), "General" );
371 
372  uint numTransports = general.readNumEntry( "transports", 0 );
373 
374  for ( uint i = 1 ; i <= numTransports ; i++ ) {
375  KMTransportInfo *info = new KMTransportInfo();
376  info->readConfig( i );
377  mTransportInfoList.append( info );
378  }
379 
380  mTransportInfo = new KMTransportInfo();
381 
382  if ( mLocalDelivery->isChecked() ) { // local delivery
383  mTransportInfo->type = "sendmail";
384  mTransportInfo->name = i18n( "Sendmail" );
385  mTransportInfo->host = "/usr/sbin/sendmail"; // TODO: search for sendmail in PATH
386  mTransportInfo->auth = false;
387  mTransportInfo->setStorePasswd( false );
388 
389  TQTimer::singleShot( 0, this, TQ_SLOT( transportCreated() ) );
390  } else { // delivery via SMTP
391  mTransportInfo->type = "smtp";
392  mTransportInfo->name = accountName();
393  mTransportInfo->host = mOutgoingServer->text();
394  mTransportInfo->user = mLoginName->text();
395  mTransportInfo->setPasswd( mPassword->text() );
396 
397  int port = (mOutgoingUseSSL->isChecked() ? 465 : 25);
398  checkSmtpCapabilities( mTransportInfo->host, port );
399  }
400 }
401 
402 void AccountWizard::transportCreated()
403 {
404  mTransportInfoList.append( mTransportInfo );
405 
406  TDEConfigGroup general( KMKernel::config(), "General" );
407  general.writeEntry( "transports", mTransportInfoList.count() );
408 
409  for ( uint i = 0 ; i < mTransportInfoList.count() ; i++ )
410  mTransportInfo->writeConfig( i + 1 );
411 
412  // No default transport? => set the first transport as the default
413  if ( GlobalSettings::self()->defaultTransport().isEmpty() ) {
414  TDEConfigGroup general( KMKernel::config(), "General" );
415 
416  if ( mTransportInfoList.count() > 0 ) {
417  KMTransportInfo info;
418  info.readConfig( 1 );
419  TDEConfigGroup composer( KMKernel::config(), "Composer" );
420  GlobalSettings::self()->setDefaultTransport( info.name );
421  GlobalSettings::self()->setCurrentTransport( info.name );
422  }
423  }
424 
425  mTransportInfoList.setAutoDelete( true );
426  mTransportInfoList.clear();
427 
428  TQTimer::singleShot( 0, this, TQ_SLOT( createAccount() ) );
429 }
430 
431 void AccountWizard::createAccount()
432 {
433  // create incoming account
434  AccountManager *acctManager = mKernel->acctMgr();
435 
436  int port = 0;
437 
438  switch ( mTypeBox->type() ) {
439  case AccountTypeBox::Local:
440  {
441  mAccount = acctManager->create( "local", i18n( "Local Account" ) );
442  static_cast<KMAcctLocal*>( mAccount )->setLocation( mIncomingLocation->text() );
443  break;
444  }
445  case AccountTypeBox::POP3:
446  {
447  mAccount = acctManager->create( "pop", accountName() );
448  KMail::PopAccount *acct = static_cast<KMail::PopAccount*>( mAccount );
449  acct->setLogin( mLoginName->text() );
450  acct->setPasswd( mPassword->text() );
451  acct->setHost( mIncomingServer->text() );
452  port = mIncomingUseSSL->isChecked() ? 995 : 110;
453  break;
454  }
455  case AccountTypeBox::IMAP:
456  {
457  mAccount = acctManager->create( "imap", accountName() );
458  KMAcctImap *acct = static_cast<KMAcctImap*>( mAccount );
459  acct->setLogin( mLoginName->text() );
460  acct->setPasswd( mPassword->text() );
461  acct->setHost( mIncomingServer->text() );
462  port = mIncomingUseSSL->isChecked() ? 993 : 143;
463  break;
464  }
465  case AccountTypeBox::dIMAP:
466  {
467  mAccount = acctManager->create( "cachedimap", accountName() );
468  KMAcctCachedImap *acct = static_cast<KMAcctCachedImap*>( mAccount );
469  acct->setLogin( mLoginName->text() );
470  acct->setPasswd( mPassword->text() );
471  acct->setHost( mIncomingServer->text() );
472  port = mIncomingUseSSL->isChecked() ? 993 : 143;
473  break;
474  }
475  case AccountTypeBox::Maildir:
476  {
477  mAccount = acctManager->create( "maildir", i18n( "Local Account" ) );
478  static_cast<KMAcctMaildir*>( mAccount )->setLocation( mIncomingLocation->text() );
479  break;
480  }
481  }
482 
483  if ( mTypeBox->type() == AccountTypeBox::POP3 )
484  checkPopCapabilities( mIncomingServer->text(), port );
485  else if ( mTypeBox->type() == AccountTypeBox::IMAP || mTypeBox->type() == AccountTypeBox::dIMAP )
486  checkImapCapabilities( mIncomingServer->text(), port );
487  else
488  TQTimer::singleShot( 0, this, TQ_SLOT( accountCreated() ) );
489 }
490 
491 void AccountWizard::accountCreated()
492 {
493  if ( mAccount )
494  {
495  mKernel->acctMgr()->add( mAccount );
496  mKernel->cleanupImapFolders();
497  }
498 
499  finished();
500 }
501 
502 void AccountWizard::finished()
503 {
504  GlobalSettings::self()->writeConfig();
505 
506  TQWizard::accept();
507 }
508 
509 // ----- Security Checks --------------
510 
511 void AccountWizard::checkPopCapabilities( const TQString &server, int port )
512 {
513  delete mServerTest;
514  mServerTest = new KMServerTest( POP_PROTOCOL, server, port );
515 
516  connect( mServerTest, TQ_SIGNAL( capabilities( const TQStringList&, const TQStringList& ) ),
517  this, TQ_SLOT( popCapabilities( const TQStringList&, const TQStringList& ) ) );
518 
519  mAuthInfoLabel = createInfoLabel( i18n( "Check for supported security capabilities of %1..." ).arg( server ) );
520 }
521 
522 void AccountWizard::checkImapCapabilities( const TQString &server, int port )
523 {
524  delete mServerTest;
525  mServerTest = new KMServerTest( IMAP_PROTOCOL, server, port );
526 
527  connect( mServerTest, TQ_SIGNAL( capabilities( const TQStringList&, const TQStringList& ) ),
528  this, TQ_SLOT( imapCapabilities( const TQStringList&, const TQStringList& ) ) );
529 
530  mAuthInfoLabel = createInfoLabel( i18n( "Check for supported security capabilities of %1..." ).arg( server ) );
531 }
532 
533 void AccountWizard::checkSmtpCapabilities( const TQString &server, int port )
534 {
535  delete mServerTest;
536  mServerTest = new KMServerTest( SMTP_PROTOCOL, server, port );
537 
538  connect( mServerTest, TQ_SIGNAL( capabilities( const TQStringList&, const TQStringList&,
539  const TQString&, const TQString&, const TQString& ) ),
540  this, TQ_SLOT( smtpCapabilities( const TQStringList&, const TQStringList&,
541  const TQString&, const TQString&, const TQString& ) ) );
542 
543  mAuthInfoLabel = createInfoLabel( i18n( "Check for supported security capabilities of %1..." ).arg( server ) );
544 }
545 
546 void AccountWizard::popCapabilities( const TQStringList &capaNormalList,
547  const TQStringList &capaSSLList )
548 {
549  uint capaNormal = popCapabilitiesFromStringList( capaNormalList );
550  uint capaTLS = 0;
551 
552  if ( capaNormal & STLS )
553  capaTLS = capaNormal;
554 
555  uint capaSSL = popCapabilitiesFromStringList( capaSSLList );
556 
557  KMail::NetworkAccount *account = static_cast<KMail::NetworkAccount*>( mAccount );
558 
559  bool useSSL = !capaSSLList.isEmpty();
560  bool useTLS = capaTLS != 0;
561 
562  account->setUseSSL( useSSL );
563  account->setUseTLS( useTLS );
564 
565  uint capa = (useSSL ? capaSSL : (useTLS ? capaTLS : capaNormal));
566 
567  if ( capa & Plain )
568  account->setAuth( "PLAIN" );
569  else if ( capa & Login )
570  account->setAuth( "LOGIN" );
571  else if ( capa & CRAM_MD5 )
572  account->setAuth( "CRAM-MD5" );
573  else if ( capa & Digest_MD5 )
574  account->setAuth( "DIGEST-MD5" );
575  else if ( capa & NTLM )
576  account->setAuth( "NTLM" );
577  else if ( capa & GSSAPI )
578  account->setAuth( "GSSAPI" );
579  else if ( capa & APOP )
580  account->setAuth( "APOP" );
581  else
582  account->setAuth( "USER" );
583 
584  account->setPort( useSSL ? 995 : 110 );
585 
586  mServerTest->deleteLater();
587  mServerTest = 0;
588 
589  delete mAuthInfoLabel;
590  mAuthInfoLabel = 0;
591 
592  accountCreated();
593 }
594 
595 
596 void AccountWizard::imapCapabilities( const TQStringList &capaNormalList,
597  const TQStringList &capaSSLList )
598 {
599  uint capaNormal = imapCapabilitiesFromStringList( capaNormalList );
600  uint capaTLS = 0;
601  if ( capaNormal & STARTTLS )
602  capaTLS = capaNormal;
603 
604  uint capaSSL = imapCapabilitiesFromStringList( capaSSLList );
605 
606  KMail::NetworkAccount *account = static_cast<KMail::NetworkAccount*>( mAccount );
607 
608  bool useSSL = !capaSSLList.isEmpty();
609  bool useTLS = (capaTLS != 0);
610 
611  account->setUseSSL( useSSL );
612  account->setUseTLS( useTLS );
613 
614  uint capa = (useSSL ? capaSSL : (useTLS ? capaTLS : capaNormal));
615 
616  if ( capa & CRAM_MD5 )
617  account->setAuth( "CRAM-MD5" );
618  else if ( capa & Digest_MD5 )
619  account->setAuth( "DIGEST-MD5" );
620  else if ( capa & NTLM )
621  account->setAuth( "NTLM" );
622  else if ( capa & GSSAPI )
623  account->setAuth( "GSSAPI" );
624  else if ( capa & Anonymous )
625  account->setAuth( "ANONYMOUS" );
626  else if ( capa & Login )
627  account->setAuth( "LOGIN" );
628  else if ( capa & Plain )
629  account->setAuth( "PLAIN" );
630  else
631  account->setAuth( "*" );
632 
633  account->setPort( useSSL ? 993 : 143 );
634 
635  mServerTest->deleteLater();
636  mServerTest = 0;
637 
638  delete mAuthInfoLabel;
639  mAuthInfoLabel = 0;
640 
641  accountCreated();
642 }
643 
644 void AccountWizard::smtpCapabilities( const TQStringList &capaNormal,
645  const TQStringList &capaSSL,
646  const TQString &authNone,
647  const TQString &authSSL,
648  const TQString &authTLS )
649 {
650  uint authBitsNone, authBitsSSL, authBitsTLS;
651 
652  if ( authNone.isEmpty() && authSSL.isEmpty() && authTLS.isEmpty() ) {
653  // slave doesn't seem to support "* AUTH METHODS" metadata (or server can't do AUTH)
654  authBitsNone = authMethodsFromStringList( capaNormal );
655  if ( capaNormal.findIndex( "STARTTLS" ) != -1 )
656  authBitsTLS = authBitsNone;
657  else
658  authBitsTLS = 0;
659  authBitsSSL = authMethodsFromStringList( capaSSL );
660  } else {
661  authBitsNone = authMethodsFromString( authNone );
662  authBitsSSL = authMethodsFromString( authSSL );
663  authBitsTLS = authMethodsFromString( authTLS );
664  }
665 
666  uint authBits = 0;
667  if ( capaNormal.findIndex( "STARTTLS" ) != -1 ) {
668  mTransportInfo->encryption = "TLS";
669  authBits = authBitsTLS;
670  } else if ( !capaSSL.isEmpty() ) {
671  mTransportInfo->encryption = "SSL";
672  authBits = authBitsSSL;
673  } else {
674  mTransportInfo->encryption = "NONE";
675  authBits = authBitsNone;
676  }
677 
678  if ( authBits & Login )
679  mTransportInfo->authType = "LOGIN";
680  else if ( authBits & CRAM_MD5 )
681  mTransportInfo->authType = "CRAM-MD5";
682  else if ( authBits & Digest_MD5 )
683  mTransportInfo->authType = "DIGEST-MD5";
684  else if ( authBits & NTLM )
685  mTransportInfo->authType = "NTLM";
686  else if ( authBits & GSSAPI )
687  mTransportInfo->authType = "GSSAPI";
688  else
689  mTransportInfo->authType = "PLAIN";
690 
691  mTransportInfo->port = ( !capaSSL.isEmpty() ? "465" : "25" );
692 
693  mServerTest->deleteLater();
694  mServerTest = 0;
695 
696  delete mAuthInfoLabel;
697  mAuthInfoLabel = 0;
698 
699  transportCreated();
700 }
701 
702 uint AccountWizard::popCapabilitiesFromStringList( const TQStringList & l )
703 {
704  unsigned int capa = 0;
705 
706  for ( TQStringList::const_iterator it = l.begin() ; it != l.end() ; ++it ) {
707  TQString cur = (*it).upper();
708  if ( cur == "PLAIN" )
709  capa |= Plain;
710  else if ( cur == "LOGIN" )
711  capa |= Login;
712  else if ( cur == "CRAM-MD5" )
713  capa |= CRAM_MD5;
714  else if ( cur == "DIGEST-MD5" )
715  capa |= Digest_MD5;
716  else if ( cur == "NTLM" )
717  capa |= NTLM;
718  else if ( cur == "GSSAPI" )
719  capa |= GSSAPI;
720  else if ( cur == "APOP" )
721  capa |= APOP;
722  else if ( cur == "STLS" )
723  capa |= STLS;
724  }
725 
726  return capa;
727 }
728 
729 uint AccountWizard::imapCapabilitiesFromStringList( const TQStringList & l )
730 {
731  unsigned int capa = 0;
732 
733  for ( TQStringList::const_iterator it = l.begin() ; it != l.end() ; ++it ) {
734  TQString cur = (*it).upper();
735  if ( cur == "AUTH=PLAIN" )
736  capa |= Plain;
737  else if ( cur == "AUTH=LOGIN" )
738  capa |= Login;
739  else if ( cur == "AUTH=CRAM-MD5" )
740  capa |= CRAM_MD5;
741  else if ( cur == "AUTH=DIGEST-MD5" )
742  capa |= Digest_MD5;
743  else if ( cur == "AUTH=NTLM" )
744  capa |= NTLM;
745  else if ( cur == "AUTH=GSSAPI" )
746  capa |= GSSAPI;
747  else if ( cur == "AUTH=ANONYMOUS" )
748  capa |= Anonymous;
749  else if ( cur == "STARTTLS" )
750  capa |= STARTTLS;
751  }
752 
753  return capa;
754 }
755 
756 uint AccountWizard::authMethodsFromString( const TQString & s )
757 {
758  unsigned int result = 0;
759 
760  TQStringList sl = TQStringList::split( '\n', s.upper() );
761  for ( TQStringList::const_iterator it = sl.begin() ; it != sl.end() ; ++it )
762  if ( *it == "SASL/LOGIN" )
763  result |= Login;
764  else if ( *it == "SASL/PLAIN" )
765  result |= Plain;
766  else if ( *it == "SASL/CRAM-MD5" )
767  result |= CRAM_MD5;
768  else if ( *it == "SASL/DIGEST-MD5" )
769  result |= Digest_MD5;
770  else if ( *it == "SASL/NTLM" )
771  result |= NTLM;
772  else if ( *it == "SASL/GSSAPI" )
773  result |= GSSAPI;
774 
775  return result;
776 }
777 
778 uint AccountWizard::authMethodsFromStringList( const TQStringList & sl )
779 {
780  unsigned int result = 0;
781 
782  for ( TQStringList::const_iterator it = sl.begin() ; it != sl.end() ; ++it )
783  if ( *it == "LOGIN" )
784  result |= Login;
785  else if ( *it == "PLAIN" )
786  result |= Plain;
787  else if ( *it == "CRAM-MD5" )
788  result |= CRAM_MD5;
789  else if ( *it == "DIGEST-MD5" )
790  result |= Digest_MD5;
791  else if ( *it == "NTLM" )
792  result |= NTLM;
793  else if ( *it == "GSSAPI" )
794  result |= GSSAPI;
795 
796  return result;
797 }
798 
799 #include "accountwizard.moc"
KMail account for pop mail account.
Definition: popaccount.h:27
KMAccount * create(const TQString &type, const TQString &name=TQString(), uint id=0)
Create a new account of given type with given name.
The account manager is responsible for creating accounts of various types via the factory method crea...
Central point of coordination in KMail.
Definition: kmkernel.h:91