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 mKernel->acctMgr()->add( mAccount );
00495
00496 finished();
00497 }
00498
00499 void AccountWizard::finished()
00500 {
00501 GlobalSettings::self()->writeConfig();
00502
00503 QWizard::accept();
00504 }
00505
00506
00507
00508 void AccountWizard::checkPopCapabilities( const QString &server, int port )
00509 {
00510 delete mServerTest;
00511 mServerTest = new KMServerTest( POP_PROTOCOL, server, port );
00512
00513 connect( mServerTest, SIGNAL( capabilities( const QStringList&, const QStringList& ) ),
00514 this, SLOT( popCapabilities( const QStringList&, const QStringList& ) ) );
00515
00516 mAuthInfoLabel = createInfoLabel( i18n( "Check for supported security capabilities of %1..." ).arg( server ) );
00517 }
00518
00519 void AccountWizard::checkImapCapabilities( const QString &server, int port )
00520 {
00521 delete mServerTest;
00522 mServerTest = new KMServerTest( IMAP_PROTOCOL, server, port );
00523
00524 connect( mServerTest, SIGNAL( capabilities( const QStringList&, const QStringList& ) ),
00525 this, SLOT( imapCapabilities( const QStringList&, const QStringList& ) ) );
00526
00527 mAuthInfoLabel = createInfoLabel( i18n( "Check for supported security capabilities of %1..." ).arg( server ) );
00528 }
00529
00530 void AccountWizard::checkSmtpCapabilities( const QString &server, int port )
00531 {
00532 delete mServerTest;
00533 mServerTest = new KMServerTest( SMTP_PROTOCOL, server, port );
00534
00535 connect( mServerTest, SIGNAL( capabilities( const QStringList&, const QStringList&,
00536 const QString&, const QString&, const QString& ) ),
00537 this, SLOT( smtpCapabilities( const QStringList&, const QStringList&,
00538 const QString&, const QString&, const QString& ) ) );
00539
00540 mAuthInfoLabel = createInfoLabel( i18n( "Check for supported security capabilities of %1..." ).arg( server ) );
00541 }
00542
00543 void AccountWizard::popCapabilities( const QStringList &capaNormalList,
00544 const QStringList &capaSSLList )
00545 {
00546 uint capaNormal = popCapabilitiesFromStringList( capaNormalList );
00547 uint capaTLS = 0;
00548
00549 if ( capaNormal & STLS )
00550 capaTLS = capaNormal;
00551
00552 uint capaSSL = popCapabilitiesFromStringList( capaSSLList );
00553
00554 KMail::NetworkAccount *account = static_cast<KMail::NetworkAccount*>( mAccount );
00555
00556 bool useSSL = !capaSSLList.isEmpty();
00557 bool useTLS = capaTLS != 0;
00558
00559 account->setUseSSL( useSSL );
00560 account->setUseTLS( useTLS );
00561
00562 uint capa = (useSSL ? capaSSL : (useTLS ? capaTLS : capaNormal));
00563
00564 if ( capa & Plain )
00565 account->setAuth( "PLAIN" );
00566 else if ( capa & Login )
00567 account->setAuth( "LOGIN" );
00568 else if ( capa & CRAM_MD5 )
00569 account->setAuth( "CRAM-MD5" );
00570 else if ( capa & Digest_MD5 )
00571 account->setAuth( "DIGEST-MD5" );
00572 else if ( capa & NTLM )
00573 account->setAuth( "NTLM" );
00574 else if ( capa & GSSAPI )
00575 account->setAuth( "GSSAPI" );
00576 else if ( capa & APOP )
00577 account->setAuth( "APOP" );
00578 else
00579 account->setAuth( "USER" );
00580
00581 account->setPort( useSSL ? 995 : 110 );
00582
00583 mServerTest->deleteLater();
00584 mServerTest = 0;
00585
00586 delete mAuthInfoLabel;
00587 mAuthInfoLabel = 0;
00588
00589 accountCreated();
00590 }
00591
00592
00593 void AccountWizard::imapCapabilities( const QStringList &capaNormalList,
00594 const QStringList &capaSSLList )
00595 {
00596 uint capaNormal = imapCapabilitiesFromStringList( capaNormalList );
00597 uint capaTLS = 0;
00598 if ( capaNormal & STARTTLS )
00599 capaTLS = capaNormal;
00600
00601 uint capaSSL = imapCapabilitiesFromStringList( capaSSLList );
00602
00603 KMail::NetworkAccount *account = static_cast<KMail::NetworkAccount*>( mAccount );
00604
00605 bool useSSL = !capaSSLList.isEmpty();
00606 bool useTLS = (capaTLS != 0);
00607
00608 account->setUseSSL( useSSL );
00609 account->setUseTLS( useTLS );
00610
00611 uint capa = (useSSL ? capaSSL : (useTLS ? capaTLS : capaNormal));
00612
00613 if ( capa & CRAM_MD5 )
00614 account->setAuth( "CRAM-MD5" );
00615 else if ( capa & Digest_MD5 )
00616 account->setAuth( "DIGEST-MD5" );
00617 else if ( capa & NTLM )
00618 account->setAuth( "NTLM" );
00619 else if ( capa & GSSAPI )
00620 account->setAuth( "GSSAPI" );
00621 else if ( capa & Anonymous )
00622 account->setAuth( "ANONYMOUS" );
00623 else if ( capa & Login )
00624 account->setAuth( "LOGIN" );
00625 else if ( capa & Plain )
00626 account->setAuth( "PLAIN" );
00627 else
00628 account->setAuth( "*" );
00629
00630 account->setPort( useSSL ? 993 : 143 );
00631
00632 mServerTest->deleteLater();
00633 mServerTest = 0;
00634
00635 delete mAuthInfoLabel;
00636 mAuthInfoLabel = 0;
00637
00638 accountCreated();
00639 }
00640
00641 void AccountWizard::smtpCapabilities( const QStringList &capaNormal,
00642 const QStringList &capaSSL,
00643 const QString &authNone,
00644 const QString &authSSL,
00645 const QString &authTLS )
00646 {
00647 uint authBitsNone, authBitsSSL, authBitsTLS;
00648
00649 if ( authNone.isEmpty() && authSSL.isEmpty() && authTLS.isEmpty() ) {
00650
00651 authBitsNone = authMethodsFromStringList( capaNormal );
00652 if ( capaNormal.findIndex( "STARTTLS" ) != -1 )
00653 authBitsTLS = authBitsNone;
00654 else
00655 authBitsTLS = 0;
00656 authBitsSSL = authMethodsFromStringList( capaSSL );
00657 } else {
00658 authBitsNone = authMethodsFromString( authNone );
00659 authBitsSSL = authMethodsFromString( authSSL );
00660 authBitsTLS = authMethodsFromString( authTLS );
00661 }
00662
00663 uint authBits = 0;
00664 if ( capaNormal.findIndex( "STARTTLS" ) != -1 ) {
00665 mTransportInfo->encryption = "TLS";
00666 authBits = authBitsTLS;
00667 } else if ( !capaSSL.isEmpty() ) {
00668 mTransportInfo->encryption = "SSL";
00669 authBits = authBitsSSL;
00670 } else {
00671 mTransportInfo->encryption = "NONE";
00672 authBits = authBitsNone;
00673 }
00674
00675 if ( authBits & Login )
00676 mTransportInfo->authType = "LOGIN";
00677 else if ( authBits & CRAM_MD5 )
00678 mTransportInfo->authType = "CRAM-MD5";
00679 else if ( authBits & Digest_MD5 )
00680 mTransportInfo->authType = "DIGEST-MD5";
00681 else if ( authBits & NTLM )
00682 mTransportInfo->authType = "NTLM";
00683 else if ( authBits & GSSAPI )
00684 mTransportInfo->authType = "GSSAPI";
00685 else
00686 mTransportInfo->authType = "PLAIN";
00687
00688 mTransportInfo->port = ( !capaSSL.isEmpty() ? "465" : "25" );
00689
00690 mServerTest->deleteLater();
00691 mServerTest = 0;
00692
00693 delete mAuthInfoLabel;
00694 mAuthInfoLabel = 0;
00695
00696 transportCreated();
00697 }
00698
00699 uint AccountWizard::popCapabilitiesFromStringList( const QStringList & l )
00700 {
00701 unsigned int capa = 0;
00702
00703 for ( QStringList::const_iterator it = l.begin() ; it != l.end() ; ++it ) {
00704 QString cur = (*it).upper();
00705 if ( cur == "PLAIN" )
00706 capa |= Plain;
00707 else if ( cur == "LOGIN" )
00708 capa |= Login;
00709 else if ( cur == "CRAM-MD5" )
00710 capa |= CRAM_MD5;
00711 else if ( cur == "DIGEST-MD5" )
00712 capa |= Digest_MD5;
00713 else if ( cur == "NTLM" )
00714 capa |= NTLM;
00715 else if ( cur == "GSSAPI" )
00716 capa |= GSSAPI;
00717 else if ( cur == "APOP" )
00718 capa |= APOP;
00719 else if ( cur == "STLS" )
00720 capa |= STLS;
00721 }
00722
00723 return capa;
00724 }
00725
00726 uint AccountWizard::imapCapabilitiesFromStringList( const QStringList & l )
00727 {
00728 unsigned int capa = 0;
00729
00730 for ( QStringList::const_iterator it = l.begin() ; it != l.end() ; ++it ) {
00731 QString cur = (*it).upper();
00732 if ( cur == "AUTH=PLAIN" )
00733 capa |= Plain;
00734 else if ( cur == "AUTH=LOGIN" )
00735 capa |= Login;
00736 else if ( cur == "AUTH=CRAM-MD5" )
00737 capa |= CRAM_MD5;
00738 else if ( cur == "AUTH=DIGEST-MD5" )
00739 capa |= Digest_MD5;
00740 else if ( cur == "AUTH=NTLM" )
00741 capa |= NTLM;
00742 else if ( cur == "AUTH=GSSAPI" )
00743 capa |= GSSAPI;
00744 else if ( cur == "AUTH=ANONYMOUS" )
00745 capa |= Anonymous;
00746 else if ( cur == "STARTTLS" )
00747 capa |= STARTTLS;
00748 }
00749
00750 return capa;
00751 }
00752
00753 uint AccountWizard::authMethodsFromString( const QString & s )
00754 {
00755 unsigned int result = 0;
00756
00757 QStringList sl = QStringList::split( '\n', s.upper() );
00758 for ( QStringList::const_iterator it = sl.begin() ; it != sl.end() ; ++it )
00759 if ( *it == "SASL/LOGIN" )
00760 result |= Login;
00761 else if ( *it == "SASL/PLAIN" )
00762 result |= Plain;
00763 else if ( *it == "SASL/CRAM-MD5" )
00764 result |= CRAM_MD5;
00765 else if ( *it == "SASL/DIGEST-MD5" )
00766 result |= Digest_MD5;
00767 else if ( *it == "SASL/NTLM" )
00768 result |= NTLM;
00769 else if ( *it == "SASL/GSSAPI" )
00770 result |= GSSAPI;
00771
00772 return result;
00773 }
00774
00775 uint AccountWizard::authMethodsFromStringList( const QStringList & sl )
00776 {
00777 unsigned int result = 0;
00778
00779 for ( QStringList::const_iterator it = sl.begin() ; it != sl.end() ; ++it )
00780 if ( *it == "LOGIN" )
00781 result |= Login;
00782 else if ( *it == "PLAIN" )
00783 result |= Plain;
00784 else if ( *it == "CRAM-MD5" )
00785 result |= CRAM_MD5;
00786 else if ( *it == "DIGEST-MD5" )
00787 result |= Digest_MD5;
00788 else if ( *it == "NTLM" )
00789 result |= NTLM;
00790 else if ( *it == "GSSAPI" )
00791 result |= GSSAPI;
00792
00793 return result;
00794 }
00795
00796 #include "accountwizard.moc"