kmail

accountwizard.cpp

00001 /*******************************************************************************
00002 **
00003 ** Filename   : accountwizard.cpp
00004 ** Created on : 07 February, 2005
00005 ** Copyright  : (c) 2005 Tobias Koenig
00006 ** Email      : tokoe@kde.org
00007 **
00008 *******************************************************************************/
00009 
00010 /*******************************************************************************
00011 **
00012 **   This program is free software; you can redistribute it and/or modify
00013 **   it under the terms of the GNU General Public License as published by
00014 **   the Free Software Foundation; either version 2 of the License, or
00015 **   (at your option) any later version.
00016 **
00017 **   In addition, as a special exception, the copyright holders give
00018 **   permission to link the code of this program with any edition of
00019 **   the Qt library by Trolltech AS, Norway (or with modified versions
00020 **   of Qt that use the same license as Qt), and distribute linked
00021 **   combinations including the two.  You must obey the GNU General
00022 **   Public License in all respects for all of the code used other than
00023 **   Qt.  If you modify this file, you may extend this exception to
00024 **   your version of the file, but you are not obligated to do so.  If
00025 **   you do not wish to do so, delete this exception statement from
00026 **   your version.
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, // TLS for POP
00073   STARTTLS   = 512, // TLS for IMAP
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     // do nothing
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       // try to extract login from email address
00155       QString email = mEMailAddress->text();
00156       int pos = email.find( '@' );
00157       if ( pos != -1 )
00158         mLoginName->setText( email.left( pos ) );
00159 
00160       // take the whole email as login otherwise?!?
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   // create account name
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   // store identity information
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   // create outgoing account
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() ) { // local delivery
00383     mTransportInfo->type = "sendmail";
00384     mTransportInfo->name = i18n( "Sendmail" );
00385     mTransportInfo->host = "/usr/sbin/sendmail"; // TODO: search for sendmail in PATH
00386     mTransportInfo->auth = false;
00387     mTransportInfo->setStorePasswd( false );
00388 
00389     QTimer::singleShot( 0, this, SLOT( transportCreated() ) );
00390   } else { // delivery via SMTP
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   mTransportInfoList.setAutoDelete( true );
00413   mTransportInfoList.clear();
00414 
00415   QTimer::singleShot( 0, this, SLOT( createAccount() ) );
00416 }
00417 
00418 void AccountWizard::createAccount()
00419 {
00420   // create incoming account
00421   AccountManager *acctManager = mKernel->acctMgr();
00422 
00423   int port = 0;
00424 
00425   switch ( mTypeBox->type() ) {
00426     case AccountTypeBox::Local:
00427     {
00428       mAccount = acctManager->create( "local", i18n( "Local Account" ) );
00429       static_cast<KMAcctLocal*>( mAccount )->setLocation( mIncomingLocation->text() );
00430       break;
00431     }
00432     case AccountTypeBox::POP3:
00433     {
00434       mAccount = acctManager->create( "pop", accountName() );
00435       KMail::PopAccount *acct = static_cast<KMail::PopAccount*>( mAccount );
00436       acct->setLogin( mLoginName->text() );
00437       acct->setPasswd( mPassword->text() );
00438       acct->setHost( mIncomingServer->text() );
00439       port = mIncomingUseSSL->isChecked() ? 995 : 110;
00440       break;
00441     }
00442     case AccountTypeBox::IMAP:
00443     {
00444       mAccount = acctManager->create( "imap", accountName() );
00445       KMAcctImap *acct = static_cast<KMAcctImap*>( mAccount );
00446       acct->setLogin( mLoginName->text() );
00447       acct->setPasswd( mPassword->text() );
00448       acct->setHost( mIncomingServer->text() );
00449       port = mIncomingUseSSL->isChecked() ? 993 : 143;
00450       break;
00451     }
00452     case AccountTypeBox::dIMAP:
00453     {
00454       mAccount = acctManager->create( "cachedimap", accountName() );
00455       KMAcctCachedImap *acct = static_cast<KMAcctCachedImap*>( mAccount );
00456       acct->setLogin( mLoginName->text() );
00457       acct->setPasswd( mPassword->text() );
00458       acct->setHost( mIncomingServer->text() );
00459       port = mIncomingUseSSL->isChecked() ? 993 : 143;
00460       break;
00461     }
00462     case AccountTypeBox::Maildir:
00463     {
00464       mAccount = acctManager->create( "maildir", i18n( "Local Account" ) );
00465       static_cast<KMAcctMaildir*>( mAccount )->setLocation( mIncomingLocation->text() );
00466       break;
00467     }
00468   }
00469 
00470   if ( mTypeBox->type() == AccountTypeBox::POP3 )
00471     checkPopCapabilities( mIncomingServer->text(), port );
00472   else if ( mTypeBox->type() == AccountTypeBox::IMAP || mTypeBox->type() == AccountTypeBox::dIMAP )
00473     checkImapCapabilities( mIncomingServer->text(), port );
00474   else
00475     QTimer::singleShot( 0, this, SLOT( accountCreated() ) );
00476 }
00477 
00478 void AccountWizard::accountCreated()
00479 {
00480   if ( mAccount )
00481     mKernel->acctMgr()->add( mAccount );
00482 
00483   finished();
00484 }
00485 
00486 void AccountWizard::finished()
00487 {
00488   GlobalSettings::self()->writeConfig();
00489 
00490   QWizard::accept();
00491 }
00492 
00493 // ----- Security Checks --------------
00494 
00495 void AccountWizard::checkPopCapabilities( const QString &server, int port )
00496 {
00497   delete mServerTest;
00498   mServerTest = new KMServerTest( POP_PROTOCOL, server, port );
00499 
00500   connect( mServerTest, SIGNAL( capabilities( const QStringList&, const QStringList& ) ),
00501            this, SLOT( popCapabilities( const QStringList&, const QStringList& ) ) );
00502 
00503   mAuthInfoLabel = createInfoLabel( i18n( "Check for supported security capabilities of %1..." ).arg( server ) );
00504 }
00505 
00506 void AccountWizard::checkImapCapabilities( const QString &server, int port )
00507 {
00508   delete mServerTest;
00509   mServerTest = new KMServerTest( IMAP_PROTOCOL, server, port );
00510 
00511   connect( mServerTest, SIGNAL( capabilities( const QStringList&, const QStringList& ) ),
00512            this, SLOT( imapCapabilities( const QStringList&, const QStringList& ) ) );
00513 
00514   mAuthInfoLabel = createInfoLabel( i18n( "Check for supported security capabilities of %1..." ).arg( server ) );
00515 }
00516 
00517 void AccountWizard::checkSmtpCapabilities( const QString &server, int port )
00518 {
00519   delete mServerTest;
00520   mServerTest = new KMServerTest( SMTP_PROTOCOL, server, port );
00521 
00522   connect( mServerTest, SIGNAL( capabilities( const QStringList&, const QStringList&,
00523                                               const QString&, const QString&, const QString& ) ),
00524            this, SLOT( smtpCapabilities( const QStringList&, const QStringList&,
00525                                          const QString&, const QString&, const QString& ) ) );
00526 
00527   mAuthInfoLabel = createInfoLabel( i18n( "Check for supported security capabilities of %1..." ).arg( server ) );
00528 }
00529 
00530 void AccountWizard::popCapabilities( const QStringList &capaNormalList,
00531                                      const QStringList &capaSSLList )
00532 {
00533   uint capaNormal = popCapabilitiesFromStringList( capaNormalList );
00534   uint capaTLS = 0;
00535 
00536   if ( capaNormal & STLS )
00537     capaTLS = capaNormal;
00538 
00539   uint capaSSL = popCapabilitiesFromStringList( capaSSLList );
00540 
00541   KMail::NetworkAccount *account = static_cast<KMail::NetworkAccount*>( mAccount );
00542 
00543   bool useSSL = !capaSSLList.isEmpty();
00544   bool useTLS = capaTLS != 0;
00545 
00546   account->setUseSSL( useSSL );
00547   account->setUseTLS( useTLS );
00548 
00549   uint capa = (useSSL ? capaSSL : (useTLS ? capaTLS : capaNormal));
00550 
00551   if ( capa & Plain )
00552     account->setAuth( "PLAIN" );
00553   else if ( capa & Login )
00554     account->setAuth( "LOGIN" );
00555   else if ( capa & CRAM_MD5 )
00556     account->setAuth( "CRAM-MD5" );
00557   else if ( capa & Digest_MD5 )
00558     account->setAuth( "DIGEST-MD5" );
00559   else if ( capa & NTLM )
00560     account->setAuth( "NTLM" );
00561   else if ( capa & GSSAPI )
00562     account->setAuth( "GSSAPI" );
00563   else if ( capa & APOP )
00564     account->setAuth( "APOP" );
00565   else
00566     account->setAuth( "USER" );
00567 
00568   account->setPort( useSSL ? 995 : 110 );
00569 
00570   mServerTest->deleteLater();
00571   mServerTest = 0;
00572 
00573   delete mAuthInfoLabel;
00574   mAuthInfoLabel = 0;
00575 
00576   accountCreated();
00577 }
00578 
00579 
00580 void AccountWizard::imapCapabilities( const QStringList &capaNormalList,
00581                                       const QStringList &capaSSLList )
00582 {
00583   uint capaNormal = imapCapabilitiesFromStringList( capaNormalList );
00584   uint capaTLS = 0;
00585   if ( capaNormal & STARTTLS )
00586     capaTLS = capaNormal;
00587 
00588   uint capaSSL = imapCapabilitiesFromStringList( capaSSLList );
00589 
00590   KMail::NetworkAccount *account = static_cast<KMail::NetworkAccount*>( mAccount );
00591 
00592   bool useSSL = !capaSSLList.isEmpty();
00593   bool useTLS = (capaTLS != 0);
00594 
00595   account->setUseSSL( useSSL );
00596   account->setUseTLS( useTLS );
00597 
00598   uint capa = (useSSL ? capaSSL : (useTLS ? capaTLS : capaNormal));
00599 
00600   if ( capa & CRAM_MD5 )
00601     account->setAuth( "CRAM-MD5" );
00602   else if ( capa & Digest_MD5 )
00603     account->setAuth( "DIGEST-MD5" );
00604   else if ( capa & NTLM )
00605     account->setAuth( "NTLM" );
00606   else if ( capa & GSSAPI )
00607     account->setAuth( "GSSAPI" );
00608   else if ( capa & Anonymous )
00609     account->setAuth( "ANONYMOUS" );
00610   else if ( capa & Login )
00611     account->setAuth( "LOGIN" );
00612   else if ( capa & Plain )
00613     account->setAuth( "PLAIN" );
00614   else
00615     account->setAuth( "*" );
00616 
00617   account->setPort( useSSL ? 993 : 143 );
00618 
00619   mServerTest->deleteLater();
00620   mServerTest = 0;
00621 
00622   delete mAuthInfoLabel;
00623   mAuthInfoLabel = 0;
00624 
00625   accountCreated();
00626 }
00627 
00628 void AccountWizard::smtpCapabilities( const QStringList &capaNormal,
00629                                       const QStringList &capaSSL,
00630                                       const QString &authNone,
00631                                       const QString &authSSL,
00632                                       const QString &authTLS )
00633 {
00634   uint authBitsNone, authBitsSSL, authBitsTLS;
00635 
00636   if ( authNone.isEmpty() && authSSL.isEmpty() && authTLS.isEmpty() ) {
00637     // slave doesn't seem to support "* AUTH METHODS" metadata (or server can't do AUTH)
00638     authBitsNone = authMethodsFromStringList( capaNormal );
00639     if ( capaNormal.findIndex( "STARTTLS" ) != -1 )
00640       authBitsTLS = authBitsNone;
00641     else
00642       authBitsTLS = 0;
00643     authBitsSSL = authMethodsFromStringList( capaSSL );
00644   } else {
00645     authBitsNone = authMethodsFromString( authNone );
00646     authBitsSSL = authMethodsFromString( authSSL );
00647     authBitsTLS = authMethodsFromString( authTLS );
00648   }
00649 
00650   uint authBits = 0;
00651   if ( capaNormal.findIndex( "STARTTLS" ) != -1 ) {
00652     mTransportInfo->encryption = "TLS";
00653     authBits = authBitsTLS;
00654   } else if ( !capaSSL.isEmpty() ) {
00655     mTransportInfo->encryption = "SSL";
00656     authBits = authBitsSSL;
00657   } else {
00658     mTransportInfo->encryption = "NONE";
00659     authBits = authBitsNone;
00660   }
00661 
00662   if ( authBits & Login )
00663     mTransportInfo->authType = "LOGIN";
00664   else if ( authBits & CRAM_MD5 )
00665     mTransportInfo->authType = "CRAM-MD5";
00666   else if ( authBits & Digest_MD5 )
00667     mTransportInfo->authType = "DIGEST-MD5";
00668   else if ( authBits & NTLM )
00669     mTransportInfo->authType = "NTLM";
00670   else if ( authBits & GSSAPI )
00671     mTransportInfo->authType = "GSSAPI";
00672   else
00673     mTransportInfo->authType = "PLAIN";
00674 
00675   mTransportInfo->port = ( !capaSSL.isEmpty() ? "465" : "25" );
00676 
00677   mServerTest->deleteLater();
00678   mServerTest = 0;
00679 
00680   delete mAuthInfoLabel;
00681   mAuthInfoLabel = 0;
00682 
00683   transportCreated();
00684 }
00685 
00686 uint AccountWizard::popCapabilitiesFromStringList( const QStringList & l )
00687 {
00688   unsigned int capa = 0;
00689 
00690   for ( QStringList::const_iterator it = l.begin() ; it != l.end() ; ++it ) {
00691     QString cur = (*it).upper();
00692     if ( cur == "PLAIN" )
00693       capa |= Plain;
00694     else if ( cur == "LOGIN" )
00695       capa |= Login;
00696     else if ( cur == "CRAM-MD5" )
00697       capa |= CRAM_MD5;
00698     else if ( cur == "DIGEST-MD5" )
00699       capa |= Digest_MD5;
00700     else if ( cur == "NTLM" )
00701       capa |= NTLM;
00702     else if ( cur == "GSSAPI" )
00703       capa |= GSSAPI;
00704     else if ( cur == "APOP" )
00705       capa |= APOP;
00706     else if ( cur == "STLS" )
00707       capa |= STLS;
00708   }
00709 
00710   return capa;
00711 }
00712 
00713 uint AccountWizard::imapCapabilitiesFromStringList( const QStringList & l )
00714 {
00715   unsigned int capa = 0;
00716 
00717   for ( QStringList::const_iterator it = l.begin() ; it != l.end() ; ++it ) {
00718     QString cur = (*it).upper();
00719     if ( cur == "AUTH=PLAIN" )
00720       capa |= Plain;
00721     else if ( cur == "AUTH=LOGIN" )
00722       capa |= Login;
00723     else if ( cur == "AUTH=CRAM-MD5" )
00724       capa |= CRAM_MD5;
00725     else if ( cur == "AUTH=DIGEST-MD5" )
00726       capa |= Digest_MD5;
00727     else if ( cur == "AUTH=NTLM" )
00728       capa |= NTLM;
00729     else if ( cur == "AUTH=GSSAPI" )
00730       capa |= GSSAPI;
00731     else if ( cur == "AUTH=ANONYMOUS" )
00732       capa |= Anonymous;
00733     else if ( cur == "STARTTLS" )
00734       capa |= STARTTLS;
00735   }
00736 
00737   return capa;
00738 }
00739 
00740 uint AccountWizard::authMethodsFromString( const QString & s )
00741 {
00742   unsigned int result = 0;
00743 
00744   QStringList sl = QStringList::split( '\n', s.upper() );
00745   for ( QStringList::const_iterator it = sl.begin() ; it != sl.end() ; ++it )
00746     if (  *it == "SASL/LOGIN" )
00747       result |= Login;
00748     else if ( *it == "SASL/PLAIN" )
00749       result |= Plain;
00750     else if ( *it == "SASL/CRAM-MD5" )
00751       result |= CRAM_MD5;
00752     else if ( *it == "SASL/DIGEST-MD5" )
00753       result |= Digest_MD5;
00754     else if ( *it == "SASL/NTLM" )
00755       result |= NTLM;
00756     else if ( *it == "SASL/GSSAPI" )
00757       result |= GSSAPI;
00758 
00759   return result;
00760 }
00761 
00762 uint AccountWizard::authMethodsFromStringList( const QStringList & sl )
00763 {
00764   unsigned int result = 0;
00765 
00766   for ( QStringList::const_iterator it = sl.begin() ; it != sl.end() ; ++it )
00767     if ( *it == "LOGIN" )
00768       result |= Login;
00769     else if ( *it == "PLAIN" )
00770       result |= Plain;
00771     else if ( *it == "CRAM-MD5" )
00772       result |= CRAM_MD5;
00773     else if ( *it == "DIGEST-MD5" )
00774       result |= Digest_MD5;
00775     else if ( *it == "NTLM" )
00776       result |= NTLM;
00777     else if ( *it == "GSSAPI" )
00778       result |= GSSAPI;
00779 
00780   return result;
00781 }
00782 
00783 #include "accountwizard.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys