00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <kdialog.h>
00030 #include <kfiledialog.h>
00031 #include <klineedit.h>
00032 #include <klistbox.h>
00033 #include <klocale.h>
00034
00035 #include <qcheckbox.h>
00036 #include <qdir.h>
00037 #include <qhbox.h>
00038 #include <qlabel.h>
00039 #include <qlayout.h>
00040 #include <qpushbutton.h>
00041 #include <qvbox.h>
00042
00043 #include "kmacctlocal.h"
00044 #include "kmkernel.h"
00045 #include "popaccount.h"
00046 #include "kmacctimap.h"
00047 #include "kmacctcachedimap.h"
00048 #include "kmacctmaildir.h"
00049 #include "accountmanager.h"
00050 using KMail::AccountManager;
00051
00052 #include "globalsettings.h"
00053 #include "kmservertest.h"
00054 #include "kmtransport.h"
00055 #include "libkpimidentities/identity.h"
00056 #include "libkpimidentities/identitymanager.h"
00057 #include "protocols.h"
00058
00059 #include "accountwizard.h"
00060
00061 enum Capabilities
00062 {
00063 Plain = 1,
00064 Login = 2,
00065 CRAM_MD5 = 4,
00066 Digest_MD5 = 8,
00067 Anonymous = 16,
00068 APOP = 32,
00069 Pipelining = 64,
00070 TOP = 128,
00071 UIDL = 256,
00072 STLS = 512,
00073 STARTTLS = 512,
00074 GSSAPI = 1024,
00075 NTLM = 2048,
00076 AllCapa = 0xffffffff
00077 };
00078
00079 class AccountTypeBox : public KListBox
00080 {
00081 public:
00082 enum Type { Local, POP3, IMAP, dIMAP, Maildir };
00083
00084 AccountTypeBox( QWidget *parent )
00085 : KListBox( parent, "AccountTypeBox" )
00086 {
00087 mTypeList << i18n( "Local mailbox" );
00088 mTypeList << i18n( "POP3" );
00089 mTypeList << i18n( "IMAP" );
00090 mTypeList << i18n( "Disconnected IMAP" );
00091 mTypeList << i18n( "Maildir mailbox" );
00092
00093 insertStringList( mTypeList );
00094 }
00095
00096 void setType( Type type )
00097 {
00098 setCurrentItem( (int)type );
00099 }
00100
00101 Type type() const
00102 {
00103 return (Type)currentItem();
00104 }
00105
00106 private:
00107 QStringList mTypeList;
00108 };
00109
00110 AccountWizard::AccountWizard( KMKernel *kernel, QWidget *parent )
00111 : KWizard( parent, "KWizard" ), mKernel( kernel ),
00112 mAccount( 0 ), mTransportInfo( 0 ), mServerTest( 0 )
00113 {
00114 setupWelcomePage();
00115 setupAccountTypePage();
00116 setupAccountInformationPage();
00117 setupLoginInformationPage();
00118 setupServerInformationPage();
00119 }
00120
00121 void AccountWizard::start( KMKernel *kernel, QWidget *parent )
00122 {
00123 KConfigGroup wizardConfig( KMKernel::config(), "AccountWizard" );
00124
00125 if ( wizardConfig.readBoolEntry( "ShowOnStartup", true ) ) {
00126 AccountWizard wizard( kernel, parent );
00127 int result = wizard.exec();
00128 if ( result == QDialog::Accepted ) {
00129 wizardConfig.writeEntry( "ShowOnStartup", false );
00130 kernel->slotConfigChanged();
00131 }
00132 }
00133 }
00134
00135 void AccountWizard::showPage( QWidget *page )
00136 {
00137 if ( page == mWelcomePage ) {
00138
00139 } else if ( page == mAccountTypePage ) {
00140 if ( mTypeBox->currentItem() == -1 )
00141 mTypeBox->setType( AccountTypeBox::POP3 );
00142 } else if ( page == mAccountInformationPage ) {
00143 if ( mRealName->text().isEmpty() && mEMailAddress->text().isEmpty() &&
00144 mOrganization->text().isEmpty() ) {
00145 KPIM::IdentityManager *manager = mKernel->identityManager();
00146 const KPIM::Identity &identity = manager->defaultIdentity();
00147
00148 mRealName->setText( identity.fullName() );
00149 mEMailAddress->setText( identity.emailAddr() );
00150 mOrganization->setText( identity.organization() );
00151 }
00152 } else if ( page == mLoginInformationPage ) {
00153 if ( mLoginName->text().isEmpty() ) {
00154
00155 QString email = mEMailAddress->text();
00156 int pos = email.find( '@' );
00157 if ( pos != -1 )
00158 mLoginName->setText( email.left( pos ) );
00159
00160
00161 }
00162 } else if ( page == mServerInformationPage ) {
00163 if ( mTypeBox->type() == AccountTypeBox::Local ||
00164 mTypeBox->type() == AccountTypeBox::Maildir ) {
00165 mIncomingServerWdg->hide();
00166 mIncomingLocationWdg->show();
00167 mIncomingLabel->setText( i18n( "Location:" ) );
00168
00169 if ( mTypeBox->type() == AccountTypeBox::Local )
00170 mIncomingLocation->setText( QDir::homeDirPath() + "/inbox" );
00171 else
00172 mIncomingLocation->setText( QDir::homeDirPath() + "/Mail/" );
00173 } else {
00174 mIncomingLocationWdg->hide();
00175 mIncomingServerWdg->show();
00176 mIncomingLabel->setText( i18n( "Incoming server:" ) );
00177 }
00178
00179 setFinishEnabled( mServerInformationPage, true );
00180 }
00181
00182 QWizard::showPage( page );
00183 }
00184
00185 void AccountWizard::setupWelcomePage()
00186 {
00187 mWelcomePage = new QVBox( this );
00188 ((QVBox*)mWelcomePage)->setSpacing( KDialog::spacingHint() );
00189
00190 QLabel *label = new QLabel( i18n( "Welcome to KMail" ), mWelcomePage );
00191 QFont font = label->font();
00192 font.setBold( true );
00193 label->setFont( font );
00194
00195 new QLabel( i18n( "<qt>It seems you have started KMail for the first time. "
00196 "You can use this wizard to setup your mail accounts. Just "
00197 "enter the connection data that you received from your email provider "
00198 "into the following pages.</qt>" ), mWelcomePage );
00199
00200 addPage( mWelcomePage, i18n( "Welcome" ) );
00201 }
00202
00203 void AccountWizard::setupAccountTypePage()
00204 {
00205 mAccountTypePage = new QVBox( this );
00206 ((QVBox*)mAccountTypePage)->setSpacing( KDialog::spacingHint() );
00207
00208 new QLabel( i18n( "Select what kind of account you would like to create" ), mAccountTypePage );
00209
00210 mTypeBox = new AccountTypeBox( mAccountTypePage );
00211
00212 addPage( mAccountTypePage, i18n( "Account Type" ) );
00213 }
00214
00215 void AccountWizard::setupAccountInformationPage()
00216 {
00217 mAccountInformationPage = new QWidget( this );
00218 QGridLayout *layout = new QGridLayout( mAccountInformationPage, 3, 2,
00219 KDialog::marginHint(), KDialog::spacingHint() );
00220
00221 QLabel *label = new QLabel( i18n( "Real name:" ), mAccountInformationPage );
00222 mRealName = new KLineEdit( mAccountInformationPage );
00223 label->setBuddy( mRealName );
00224
00225 layout->addWidget( label, 0, 0 );
00226 layout->addWidget( mRealName, 0, 1 );
00227
00228 label = new QLabel( i18n( "E-mail address:" ), mAccountInformationPage );
00229 mEMailAddress = new KLineEdit( mAccountInformationPage );
00230 label->setBuddy( mEMailAddress );
00231
00232 layout->addWidget( label, 1, 0 );
00233 layout->addWidget( mEMailAddress, 1, 1 );
00234
00235 label = new QLabel( i18n( "Organization:" ), mAccountInformationPage );
00236 mOrganization = new KLineEdit( mAccountInformationPage );
00237 label->setBuddy( mOrganization );
00238
00239 layout->addWidget( label, 2, 0 );
00240 layout->addWidget( mOrganization, 2, 1 );
00241
00242 addPage( mAccountInformationPage, i18n( "Account Information" ) );
00243 }
00244
00245 void AccountWizard::setupLoginInformationPage()
00246 {
00247 mLoginInformationPage = new QWidget( this );
00248 QGridLayout *layout = new QGridLayout( mLoginInformationPage, 2, 2,
00249 KDialog::marginHint(), KDialog::spacingHint() );
00250
00251 QLabel *label = new QLabel( i18n( "Login name:" ), mLoginInformationPage );
00252 mLoginName = new KLineEdit( mLoginInformationPage );
00253 label->setBuddy( mLoginName );
00254
00255 layout->addWidget( label, 0, 0 );
00256 layout->addWidget( mLoginName, 0, 1 );
00257
00258 label = new QLabel( i18n( "Password:" ), mLoginInformationPage );
00259 mPassword = new KLineEdit( mLoginInformationPage );
00260 mPassword->setEchoMode( QLineEdit::Password );
00261 label->setBuddy( mPassword );
00262
00263 layout->addWidget( label, 1, 0 );
00264 layout->addWidget( mPassword, 1, 1 );
00265
00266 addPage( mLoginInformationPage, i18n( "Login Information" ) );
00267 }
00268
00269 void AccountWizard::setupServerInformationPage()
00270 {
00271 mServerInformationPage = new QWidget( this );
00272 QGridLayout *layout = new QGridLayout( mServerInformationPage, 3, 2,
00273 KDialog::marginHint(), KDialog::spacingHint() );
00274
00275 mIncomingLabel = new QLabel( mServerInformationPage );
00276
00277 mIncomingServerWdg = new QVBox( mServerInformationPage );
00278 mIncomingServer = new KLineEdit( mIncomingServerWdg );
00279 mIncomingUseSSL = new QCheckBox( i18n( "Use secure connection (SSL)" ), mIncomingServerWdg );
00280
00281 mIncomingLocationWdg = new QHBox( mServerInformationPage );
00282 mIncomingLocation = new KLineEdit( mIncomingLocationWdg );
00283 mChooseLocation = new QPushButton( i18n( "Choose..." ), mIncomingLocationWdg );
00284
00285 connect( mChooseLocation, SIGNAL( clicked() ),
00286 this, SLOT( chooseLocation() ) );
00287
00288 layout->addWidget( mIncomingLabel, 0, 0, AlignTop );
00289 layout->addWidget( mIncomingLocationWdg, 0, 1 );
00290 layout->addWidget( mIncomingServerWdg, 0, 1 );
00291
00292 QLabel *label = new QLabel( i18n( "Outgoing server:" ), mServerInformationPage );
00293 mOutgoingServer = new KLineEdit( mServerInformationPage );
00294 label->setBuddy( mOutgoingServer );
00295
00296 layout->addWidget( label, 1, 0 );
00297 layout->addWidget( mOutgoingServer, 1, 1 );
00298
00299 mOutgoingUseSSL = new QCheckBox( i18n( "Use secure connection (SSL)" ), mServerInformationPage );
00300 layout->addWidget( mOutgoingUseSSL, 2, 1 );
00301
00302 mLocalDelivery = new QCheckBox( i18n( "Use local delivery" ),
00303 mServerInformationPage );
00304 layout->addWidget( mLocalDelivery, 3, 0 );
00305
00306 connect( mLocalDelivery, SIGNAL( toggled( bool ) ),
00307 mOutgoingServer, SLOT( setDisabled( bool ) ) );
00308
00309 addPage( mServerInformationPage, i18n( "Server Information" ) );
00310 }
00311
00312 void AccountWizard::chooseLocation()
00313 {
00314 QString location;
00315
00316 if ( mTypeBox->type() == AccountTypeBox::Local ) {
00317 location = KFileDialog::getSaveFileName( QString(), QString(), this );
00318 } else if ( mTypeBox->type() == AccountTypeBox::Maildir ) {
00319 location = KFileDialog::getExistingDirectory( QString(), this );
00320 }
00321
00322 if ( !location.isEmpty() )
00323 mIncomingLocation->setText( location );
00324 }
00325
00326 QString AccountWizard::accountName() const
00327 {
00328
00329 QString name( i18n( "None" ) );
00330
00331 QString email = mEMailAddress->text();
00332 int pos = email.find( '@' );
00333 if ( pos != -1 ) {
00334 name = email.mid( pos + 1 );
00335 name[ 0 ] = name[ 0 ].upper();
00336 }
00337
00338 return name;
00339 }
00340
00341 QLabel *AccountWizard::createInfoLabel( const QString &msg )
00342 {
00343 QLabel *label = new QLabel( msg, this );
00344 label->setFrameStyle( QFrame::Panel | QFrame::Raised );
00345 label->resize( fontMetrics().width( msg ) + 20, label->height() * 2 );
00346 label->move( width() / 2 - label->width() / 2, height() / 2 - label->height() / 2 );
00347 label->show();
00348
00349 return label;
00350 }
00351
00352 void AccountWizard::accept()
00353 {
00354
00355 KPIM::IdentityManager *manager = mKernel->identityManager();
00356 KPIM::Identity &identity = manager->modifyIdentityForUoid( manager->defaultIdentity().uoid() );
00357
00358 identity.setFullName( mRealName->text() );
00359 identity.setEmailAddr( mEMailAddress->text() );
00360 identity.setOrganization( mOrganization->text() );
00361
00362 manager->commit();
00363
00364 QTimer::singleShot( 0, this, SLOT( createTransport() ) );
00365 }
00366
00367 void AccountWizard::createTransport()
00368 {
00369
00370 KConfigGroup general( KMKernel::config(), "General" );
00371
00372 uint numTransports = general.readNumEntry( "transports", 0 );
00373
00374 for ( uint i = 1 ; i <= numTransports ; i++ ) {
00375 KMTransportInfo *info = new KMTransportInfo();
00376 info->readConfig( i );
00377 mTransportInfoList.append( info );
00378 }
00379
00380 mTransportInfo = new KMTransportInfo();
00381
00382 if ( mLocalDelivery->isChecked() ) {
00383 mTransportInfo->type = "sendmail";
00384 mTransportInfo->name = i18n( "Sendmail" );
00385 mTransportInfo->host = "/usr/sbin/sendmail";
00386 mTransportInfo->auth = false;
00387 mTransportInfo->setStorePasswd( false );
00388
00389 QTimer::singleShot( 0, this, SLOT( transportCreated() ) );
00390 } else {
00391 mTransportInfo->type = "smtp";
00392 mTransportInfo->name = accountName();
00393 mTransportInfo->host = mOutgoingServer->text();
00394 mTransportInfo->user = mLoginName->text();
00395 mTransportInfo->setPasswd( mPassword->text() );
00396
00397 int port = (mOutgoingUseSSL->isChecked() ? 465 : 25);
00398 checkSmtpCapabilities( mTransportInfo->host, port );
00399 }
00400 }
00401
00402 void AccountWizard::transportCreated()
00403 {
00404 mTransportInfoList.append( mTransportInfo );
00405
00406 KConfigGroup general( KMKernel::config(), "General" );
00407 general.writeEntry( "transports", mTransportInfoList.count() );
00408
00409 for ( uint i = 0 ; i < mTransportInfoList.count() ; i++ )
00410 mTransportInfo->writeConfig( i + 1 );
00411
00412
00413 if ( GlobalSettings::self()->defaultTransport().isEmpty() ) {
00414 KConfigGroup general( KMKernel::config(), "General" );
00415
00416 if ( mTransportInfoList.count() > 0 ) {
00417 KMTransportInfo info;
00418 info.readConfig( 1 );
00419 KConfigGroup composer( KMKernel::config(), "Composer" );
00420 GlobalSettings::self()->setDefaultTransport( info.name );
00421 GlobalSettings::self()->setCurrentTransport( info.name );
00422 }
00423 }
00424
00425 mTransportInfoList.setAutoDelete( true );
00426 mTransportInfoList.clear();
00427
00428 QTimer::singleShot( 0, this, SLOT( createAccount() ) );
00429 }
00430
00431 void AccountWizard::createAccount()
00432 {
00433
00434 AccountManager *acctManager = mKernel->acctMgr();
00435
00436 int port = 0;
00437
00438 switch ( mTypeBox->type() ) {
00439 case AccountTypeBox::Local:
00440 {
00441 mAccount = acctManager->create( "local", i18n( "Local Account" ) );
00442 static_cast<KMAcctLocal*>( mAccount )->setLocation( mIncomingLocation->text() );
00443 break;
00444 }
00445 case AccountTypeBox::POP3:
00446 {
00447 mAccount = acctManager->create( "pop", accountName() );
00448 KMail::PopAccount *acct = static_cast<KMail::PopAccount*>( mAccount );
00449 acct->setLogin( mLoginName->text() );
00450 acct->setPasswd( mPassword->text() );
00451 acct->setHost( mIncomingServer->text() );
00452 port = mIncomingUseSSL->isChecked() ? 995 : 110;
00453 break;
00454 }
00455 case AccountTypeBox::IMAP:
00456 {
00457 mAccount = acctManager->create( "imap", accountName() );
00458 KMAcctImap *acct = static_cast<KMAcctImap*>( mAccount );
00459 acct->setLogin( mLoginName->text() );
00460 acct->setPasswd( mPassword->text() );
00461 acct->setHost( mIncomingServer->text() );
00462 port = mIncomingUseSSL->isChecked() ? 993 : 143;
00463 break;
00464 }
00465 case AccountTypeBox::dIMAP:
00466 {
00467 mAccount = acctManager->create( "cachedimap", accountName() );
00468 KMAcctCachedImap *acct = static_cast<KMAcctCachedImap*>( mAccount );
00469 acct->setLogin( mLoginName->text() );
00470 acct->setPasswd( mPassword->text() );
00471 acct->setHost( mIncomingServer->text() );
00472 port = mIncomingUseSSL->isChecked() ? 993 : 143;
00473 break;
00474 }
00475 case AccountTypeBox::Maildir:
00476 {
00477 mAccount = acctManager->create( "maildir", i18n( "Local Account" ) );
00478 static_cast<KMAcctMaildir*>( mAccount )->setLocation( mIncomingLocation->text() );
00479 break;
00480 }
00481 }
00482
00483 if ( mTypeBox->type() == AccountTypeBox::POP3 )
00484 checkPopCapabilities( mIncomingServer->text(), port );
00485 else if ( mTypeBox->type() == AccountTypeBox::IMAP || mTypeBox->type() == AccountTypeBox::dIMAP )
00486 checkImapCapabilities( mIncomingServer->text(), port );
00487 else
00488 QTimer::singleShot( 0, this, SLOT( accountCreated() ) );
00489 }
00490
00491 void AccountWizard::accountCreated()
00492 {
00493 if ( mAccount )
00494 {
00495 mKernel->acctMgr()->add( mAccount );
00496 mKernel->cleanupImapFolders();
00497 }
00498 finished();
00499 }
00500
00501 void AccountWizard::finished()
00502 {
00503 GlobalSettings::self()->writeConfig();
00504
00505 QWizard::accept();
00506 }
00507
00508
00509
00510 void AccountWizard::checkPopCapabilities( const QString &server, int port )
00511 {
00512 delete mServerTest;
00513 mServerTest = new KMServerTest( POP_PROTOCOL, server, port );
00514
00515 connect( mServerTest, SIGNAL( capabilities( const QStringList&, const QStringList& ) ),
00516 this, SLOT( popCapabilities( const QStringList&, const QStringList& ) ) );
00517
00518 mAuthInfoLabel = createInfoLabel( i18n( "Check for supported security capabilities of %1..." ).arg( server ) );
00519 }
00520
00521 void AccountWizard::checkImapCapabilities( const QString &server, int port )
00522 {
00523 delete mServerTest;
00524 mServerTest = new KMServerTest( IMAP_PROTOCOL, server, port );
00525
00526 connect( mServerTest, SIGNAL( capabilities( const QStringList&, const QStringList& ) ),
00527 this, SLOT( imapCapabilities( const QStringList&, const QStringList& ) ) );
00528
00529 mAuthInfoLabel = createInfoLabel( i18n( "Check for supported security capabilities of %1..." ).arg( server ) );
00530 }
00531
00532 void AccountWizard::checkSmtpCapabilities( const QString &server, int port )
00533 {
00534 delete mServerTest;
00535 mServerTest = new KMServerTest( SMTP_PROTOCOL, server, port );
00536
00537 connect( mServerTest, SIGNAL( capabilities( const QStringList&, const QStringList&,
00538 const QString&, const QString&, const QString& ) ),
00539 this, SLOT( smtpCapabilities( const QStringList&, const QStringList&,
00540 const QString&, const QString&, const QString& ) ) );
00541
00542 mAuthInfoLabel = createInfoLabel( i18n( "Check for supported security capabilities of %1..." ).arg( server ) );
00543 }
00544
00545 void AccountWizard::popCapabilities( const QStringList &capaNormalList,
00546 const QStringList &capaSSLList )
00547 {
00548 uint capaNormal = popCapabilitiesFromStringList( capaNormalList );
00549 uint capaTLS = 0;
00550
00551 if ( capaNormal & STLS )
00552 capaTLS = capaNormal;
00553
00554 uint capaSSL = popCapabilitiesFromStringList( capaSSLList );
00555
00556 KMail::NetworkAccount *account = static_cast<KMail::NetworkAccount*>( mAccount );
00557
00558 bool useSSL = !capaSSLList.isEmpty();
00559 bool useTLS = capaTLS != 0;
00560
00561 account->setUseSSL( useSSL );
00562 account->setUseTLS( useTLS );
00563
00564 uint capa = (useSSL ? capaSSL : (useTLS ? capaTLS : capaNormal));
00565
00566 if ( capa & Plain )
00567 account->setAuth( "PLAIN" );
00568 else if ( capa & Login )
00569 account->setAuth( "LOGIN" );
00570 else if ( capa & CRAM_MD5 )
00571 account->setAuth( "CRAM-MD5" );
00572 else if ( capa & Digest_MD5 )
00573 account->setAuth( "DIGEST-MD5" );
00574 else if ( capa & NTLM )
00575 account->setAuth( "NTLM" );
00576 else if ( capa & GSSAPI )
00577 account->setAuth( "GSSAPI" );
00578 else if ( capa & APOP )
00579 account->setAuth( "APOP" );
00580 else
00581 account->setAuth( "USER" );
00582
00583 account->setPort( useSSL ? 995 : 110 );
00584
00585 mServerTest->deleteLater();
00586 mServerTest = 0;
00587
00588 delete mAuthInfoLabel;
00589 mAuthInfoLabel = 0;
00590
00591 accountCreated();
00592 }
00593
00594
00595 void AccountWizard::imapCapabilities( const QStringList &capaNormalList,
00596 const QStringList &capaSSLList )
00597 {
00598 uint capaNormal = imapCapabilitiesFromStringList( capaNormalList );
00599 uint capaTLS = 0;
00600 if ( capaNormal & STARTTLS )
00601 capaTLS = capaNormal;
00602
00603 uint capaSSL = imapCapabilitiesFromStringList( capaSSLList );
00604
00605 KMail::NetworkAccount *account = static_cast<KMail::NetworkAccount*>( mAccount );
00606
00607 bool useSSL = !capaSSLList.isEmpty();
00608 bool useTLS = (capaTLS != 0);
00609
00610 account->setUseSSL( useSSL );
00611 account->setUseTLS( useTLS );
00612
00613 uint capa = (useSSL ? capaSSL : (useTLS ? capaTLS : capaNormal));
00614
00615 if ( capa & CRAM_MD5 )
00616 account->setAuth( "CRAM-MD5" );
00617 else if ( capa & Digest_MD5 )
00618 account->setAuth( "DIGEST-MD5" );
00619 else if ( capa & NTLM )
00620 account->setAuth( "NTLM" );
00621 else if ( capa & GSSAPI )
00622 account->setAuth( "GSSAPI" );
00623 else if ( capa & Anonymous )
00624 account->setAuth( "ANONYMOUS" );
00625 else if ( capa & Login )
00626 account->setAuth( "LOGIN" );
00627 else if ( capa & Plain )
00628 account->setAuth( "PLAIN" );
00629 else
00630 account->setAuth( "*" );
00631
00632 account->setPort( useSSL ? 993 : 143 );
00633
00634 mServerTest->deleteLater();
00635 mServerTest = 0;
00636
00637 delete mAuthInfoLabel;
00638 mAuthInfoLabel = 0;
00639
00640 accountCreated();
00641 }
00642
00643 void AccountWizard::smtpCapabilities( const QStringList &capaNormal,
00644 const QStringList &capaSSL,
00645 const QString &authNone,
00646 const QString &authSSL,
00647 const QString &authTLS )
00648 {
00649 uint authBitsNone, authBitsSSL, authBitsTLS;
00650
00651 if ( authNone.isEmpty() && authSSL.isEmpty() && authTLS.isEmpty() ) {
00652
00653 authBitsNone = authMethodsFromStringList( capaNormal );
00654 if ( capaNormal.findIndex( "STARTTLS" ) != -1 )
00655 authBitsTLS = authBitsNone;
00656 else
00657 authBitsTLS = 0;
00658 authBitsSSL = authMethodsFromStringList( capaSSL );
00659 } else {
00660 authBitsNone = authMethodsFromString( authNone );
00661 authBitsSSL = authMethodsFromString( authSSL );
00662 authBitsTLS = authMethodsFromString( authTLS );
00663 }
00664
00665 uint authBits = 0;
00666 if ( capaNormal.findIndex( "STARTTLS" ) != -1 ) {
00667 mTransportInfo->encryption = "TLS";
00668 authBits = authBitsTLS;
00669 } else if ( !capaSSL.isEmpty() ) {
00670 mTransportInfo->encryption = "SSL";
00671 authBits = authBitsSSL;
00672 } else {
00673 mTransportInfo->encryption = "NONE";
00674 authBits = authBitsNone;
00675 }
00676
00677 if ( authBits & Login )
00678 mTransportInfo->authType = "LOGIN";
00679 else if ( authBits & CRAM_MD5 )
00680 mTransportInfo->authType = "CRAM-MD5";
00681 else if ( authBits & Digest_MD5 )
00682 mTransportInfo->authType = "DIGEST-MD5";
00683 else if ( authBits & NTLM )
00684 mTransportInfo->authType = "NTLM";
00685 else if ( authBits & GSSAPI )
00686 mTransportInfo->authType = "GSSAPI";
00687 else
00688 mTransportInfo->authType = "PLAIN";
00689
00690 mTransportInfo->port = ( !capaSSL.isEmpty() ? "465" : "25" );
00691
00692 mServerTest->deleteLater();
00693 mServerTest = 0;
00694
00695 delete mAuthInfoLabel;
00696 mAuthInfoLabel = 0;
00697
00698 transportCreated();
00699 }
00700
00701 uint AccountWizard::popCapabilitiesFromStringList( const QStringList & l )
00702 {
00703 unsigned int capa = 0;
00704
00705 for ( QStringList::const_iterator it = l.begin() ; it != l.end() ; ++it ) {
00706 QString cur = (*it).upper();
00707 if ( cur == "PLAIN" )
00708 capa |= Plain;
00709 else if ( cur == "LOGIN" )
00710 capa |= Login;
00711 else if ( cur == "CRAM-MD5" )
00712 capa |= CRAM_MD5;
00713 else if ( cur == "DIGEST-MD5" )
00714 capa |= Digest_MD5;
00715 else if ( cur == "NTLM" )
00716 capa |= NTLM;
00717 else if ( cur == "GSSAPI" )
00718 capa |= GSSAPI;
00719 else if ( cur == "APOP" )
00720 capa |= APOP;
00721 else if ( cur == "STLS" )
00722 capa |= STLS;
00723 }
00724
00725 return capa;
00726 }
00727
00728 uint AccountWizard::imapCapabilitiesFromStringList( const QStringList & l )
00729 {
00730 unsigned int capa = 0;
00731
00732 for ( QStringList::const_iterator it = l.begin() ; it != l.end() ; ++it ) {
00733 QString cur = (*it).upper();
00734 if ( cur == "AUTH=PLAIN" )
00735 capa |= Plain;
00736 else if ( cur == "AUTH=LOGIN" )
00737 capa |= Login;
00738 else if ( cur == "AUTH=CRAM-MD5" )
00739 capa |= CRAM_MD5;
00740 else if ( cur == "AUTH=DIGEST-MD5" )
00741 capa |= Digest_MD5;
00742 else if ( cur == "AUTH=NTLM" )
00743 capa |= NTLM;
00744 else if ( cur == "AUTH=GSSAPI" )
00745 capa |= GSSAPI;
00746 else if ( cur == "AUTH=ANONYMOUS" )
00747 capa |= Anonymous;
00748 else if ( cur == "STARTTLS" )
00749 capa |= STARTTLS;
00750 }
00751
00752 return capa;
00753 }
00754
00755 uint AccountWizard::authMethodsFromString( const QString & s )
00756 {
00757 unsigned int result = 0;
00758
00759 QStringList sl = QStringList::split( '\n', s.upper() );
00760 for ( QStringList::const_iterator it = sl.begin() ; it != sl.end() ; ++it )
00761 if ( *it == "SASL/LOGIN" )
00762 result |= Login;
00763 else if ( *it == "SASL/PLAIN" )
00764 result |= Plain;
00765 else if ( *it == "SASL/CRAM-MD5" )
00766 result |= CRAM_MD5;
00767 else if ( *it == "SASL/DIGEST-MD5" )
00768 result |= Digest_MD5;
00769 else if ( *it == "SASL/NTLM" )
00770 result |= NTLM;
00771 else if ( *it == "SASL/GSSAPI" )
00772 result |= GSSAPI;
00773
00774 return result;
00775 }
00776
00777 uint AccountWizard::authMethodsFromStringList( const QStringList & sl )
00778 {
00779 unsigned int result = 0;
00780
00781 for ( QStringList::const_iterator it = sl.begin() ; it != sl.end() ; ++it )
00782 if ( *it == "LOGIN" )
00783 result |= Login;
00784 else if ( *it == "PLAIN" )
00785 result |= Plain;
00786 else if ( *it == "CRAM-MD5" )
00787 result |= CRAM_MD5;
00788 else if ( *it == "DIGEST-MD5" )
00789 result |= Digest_MD5;
00790 else if ( *it == "NTLM" )
00791 result |= NTLM;
00792 else if ( *it == "GSSAPI" )
00793 result |= GSSAPI;
00794
00795 return result;
00796 }
00797
00798 #include "accountwizard.moc"