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