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 TQt library by Trolltech AS, Norway (or with modified versions 00020 ** of TQt that use the same license as TQt), 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 ** TQt. 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 <tdefiledialog.h> 00031 #include <klineedit.h> 00032 #include <tdelistbox.h> 00033 #include <tdelocale.h> 00034 00035 #include <tqcheckbox.h> 00036 #include <tqdir.h> 00037 #include <tqhbox.h> 00038 #include <tqlabel.h> 00039 #include <tqlayout.h> 00040 #include <tqpushbutton.h> 00041 #include <tqvbox.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 TDEListBox 00080 { 00081 public: 00082 enum Type { Local, POP3, IMAP, dIMAP, Maildir }; 00083 00084 AccountTypeBox( TQWidget *parent ) 00085 : TDEListBox( 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 TQStringList mTypeList; 00108 }; 00109 00110 AccountWizard::AccountWizard( KMKernel *kernel, TQWidget *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, TQWidget *parent ) 00122 { 00123 TDEConfigGroup wizardConfig( KMKernel::config(), "AccountWizard" ); 00124 00125 if ( wizardConfig.readBoolEntry( "ShowOnStartup", true ) ) { 00126 AccountWizard wizard( kernel, parent ); 00127 int result = wizard.exec(); 00128 if ( result == TQDialog::Accepted ) { 00129 wizardConfig.writeEntry( "ShowOnStartup", false ); 00130 kernel->slotConfigChanged(); 00131 } 00132 } 00133 } 00134 00135 void AccountWizard::showPage( TQWidget *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.primaryEmailAddress() ); 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 TQString 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( TQDir::homeDirPath() + "/inbox" ); 00171 else 00172 mIncomingLocation->setText( TQDir::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 TQWizard::showPage( page ); 00183 } 00184 00185 void AccountWizard::setupWelcomePage() 00186 { 00187 mWelcomePage = new TQVBox( this ); 00188 ((TQVBox*)mWelcomePage)->setSpacing( KDialog::spacingHint() ); 00189 00190 TQLabel *label = new TQLabel( i18n( "Welcome to KMail" ), mWelcomePage ); 00191 TQFont font = label->font(); 00192 font.setBold( true ); 00193 label->setFont( font ); 00194 00195 new TQLabel( 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 TQVBox( this ); 00206 ((TQVBox*)mAccountTypePage)->setSpacing( KDialog::spacingHint() ); 00207 00208 new TQLabel( 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 TQWidget( this ); 00218 TQGridLayout *layout = new TQGridLayout( mAccountInformationPage, 3, 2, 00219 KDialog::marginHint(), KDialog::spacingHint() ); 00220 00221 TQLabel *label = new TQLabel( 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 TQLabel( 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 TQLabel( 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 TQWidget( this ); 00248 TQGridLayout *layout = new TQGridLayout( mLoginInformationPage, 2, 2, 00249 KDialog::marginHint(), KDialog::spacingHint() ); 00250 00251 TQLabel *label = new TQLabel( 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 TQLabel( i18n( "Password:" ), mLoginInformationPage ); 00259 mPassword = new KLineEdit( mLoginInformationPage ); 00260 mPassword->setEchoMode( TQLineEdit::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 TQWidget( this ); 00272 TQGridLayout *layout = new TQGridLayout( mServerInformationPage, 3, 2, 00273 KDialog::marginHint(), KDialog::spacingHint() ); 00274 00275 mIncomingLabel = new TQLabel( mServerInformationPage ); 00276 00277 mIncomingServerWdg = new TQVBox( mServerInformationPage ); 00278 mIncomingServer = new KLineEdit( mIncomingServerWdg ); 00279 mIncomingUseSSL = new TQCheckBox( i18n( "Use secure connection (SSL)" ), mIncomingServerWdg ); 00280 00281 mIncomingLocationWdg = new TQHBox( mServerInformationPage ); 00282 mIncomingLocation = new KLineEdit( mIncomingLocationWdg ); 00283 mChooseLocation = new TQPushButton( i18n( "Choose..." ), mIncomingLocationWdg ); 00284 00285 connect( mChooseLocation, TQT_SIGNAL( clicked() ), 00286 this, TQT_SLOT( chooseLocation() ) ); 00287 00288 layout->addWidget( mIncomingLabel, 0, 0, AlignTop ); 00289 layout->addWidget( mIncomingLocationWdg, 0, 1 ); 00290 layout->addWidget( mIncomingServerWdg, 0, 1 ); 00291 00292 TQLabel *label = new TQLabel( 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 TQCheckBox( i18n( "Use secure connection (SSL)" ), mServerInformationPage ); 00300 layout->addWidget( mOutgoingUseSSL, 2, 1 ); 00301 00302 mLocalDelivery = new TQCheckBox( i18n( "Use local delivery" ), 00303 mServerInformationPage ); 00304 layout->addWidget( mLocalDelivery, 3, 0 ); 00305 00306 connect( mLocalDelivery, TQT_SIGNAL( toggled( bool ) ), 00307 mOutgoingServer, TQT_SLOT( setDisabled( bool ) ) ); 00308 00309 addPage( mServerInformationPage, i18n( "Server Information" ) ); 00310 } 00311 00312 void AccountWizard::chooseLocation() 00313 { 00314 TQString location; 00315 00316 if ( mTypeBox->type() == AccountTypeBox::Local ) { 00317 location = KFileDialog::getSaveFileName( TQString(), TQString(), this ); 00318 } else if ( mTypeBox->type() == AccountTypeBox::Maildir ) { 00319 location = KFileDialog::getExistingDirectory( TQString(), this ); 00320 } 00321 00322 if ( !location.isEmpty() ) 00323 mIncomingLocation->setText( location ); 00324 } 00325 00326 TQString AccountWizard::accountName() const 00327 { 00328 // create account name 00329 TQString name( i18n( "None" ) ); 00330 00331 TQString 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 TQLabel *AccountWizard::createInfoLabel( const TQString &msg ) 00342 { 00343 TQLabel *label = new TQLabel( msg, this ); 00344 label->setFrameStyle( TQFrame::Panel | TQFrame::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.setPrimaryEmailAddress( mEMailAddress->text() ); 00360 identity.setOrganization( mOrganization->text() ); 00361 00362 manager->commit(); 00363 00364 TQTimer::singleShot( 0, this, TQT_SLOT( createTransport() ) ); 00365 } 00366 00367 void AccountWizard::createTransport() 00368 { 00369 // create outgoing account 00370 TDEConfigGroup 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 TQTimer::singleShot( 0, this, TQT_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 TDEConfigGroup 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 // No default transport? => set the first transport as the default 00413 if ( GlobalSettings::self()->defaultTransport().isEmpty() ) { 00414 TDEConfigGroup general( KMKernel::config(), "General" ); 00415 00416 if ( mTransportInfoList.count() > 0 ) { 00417 KMTransportInfo info; 00418 info.readConfig( 1 ); 00419 TDEConfigGroup 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 TQTimer::singleShot( 0, this, TQT_SLOT( createAccount() ) ); 00429 } 00430 00431 void AccountWizard::createAccount() 00432 { 00433 // create incoming account 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 TQTimer::singleShot( 0, this, TQT_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 TQWizard::accept(); 00507 } 00508 00509 // ----- Security Checks -------------- 00510 00511 void AccountWizard::checkPopCapabilities( const TQString &server, int port ) 00512 { 00513 delete mServerTest; 00514 mServerTest = new KMServerTest( POP_PROTOCOL, server, port ); 00515 00516 connect( mServerTest, TQT_SIGNAL( capabilities( const TQStringList&, const TQStringList& ) ), 00517 this, TQT_SLOT( popCapabilities( const TQStringList&, const TQStringList& ) ) ); 00518 00519 mAuthInfoLabel = createInfoLabel( i18n( "Check for supported security capabilities of %1..." ).arg( server ) ); 00520 } 00521 00522 void AccountWizard::checkImapCapabilities( const TQString &server, int port ) 00523 { 00524 delete mServerTest; 00525 mServerTest = new KMServerTest( IMAP_PROTOCOL, server, port ); 00526 00527 connect( mServerTest, TQT_SIGNAL( capabilities( const TQStringList&, const TQStringList& ) ), 00528 this, TQT_SLOT( imapCapabilities( const TQStringList&, const TQStringList& ) ) ); 00529 00530 mAuthInfoLabel = createInfoLabel( i18n( "Check for supported security capabilities of %1..." ).arg( server ) ); 00531 } 00532 00533 void AccountWizard::checkSmtpCapabilities( const TQString &server, int port ) 00534 { 00535 delete mServerTest; 00536 mServerTest = new KMServerTest( SMTP_PROTOCOL, server, port ); 00537 00538 connect( mServerTest, TQT_SIGNAL( capabilities( const TQStringList&, const TQStringList&, 00539 const TQString&, const TQString&, const TQString& ) ), 00540 this, TQT_SLOT( smtpCapabilities( const TQStringList&, const TQStringList&, 00541 const TQString&, const TQString&, const TQString& ) ) ); 00542 00543 mAuthInfoLabel = createInfoLabel( i18n( "Check for supported security capabilities of %1..." ).arg( server ) ); 00544 } 00545 00546 void AccountWizard::popCapabilities( const TQStringList &capaNormalList, 00547 const TQStringList &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 TQStringList &capaNormalList, 00597 const TQStringList &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 TQStringList &capaNormal, 00645 const TQStringList &capaSSL, 00646 const TQString &authNone, 00647 const TQString &authSSL, 00648 const TQString &authTLS ) 00649 { 00650 uint authBitsNone, authBitsSSL, authBitsTLS; 00651 00652 if ( authNone.isEmpty() && authSSL.isEmpty() && authTLS.isEmpty() ) { 00653 // slave doesn't seem to support "* AUTH METHODS" metadata (or server can't do AUTH) 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 TQStringList & l ) 00703 { 00704 unsigned int capa = 0; 00705 00706 for ( TQStringList::const_iterator it = l.begin() ; it != l.end() ; ++it ) { 00707 TQString 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 TQStringList & l ) 00730 { 00731 unsigned int capa = 0; 00732 00733 for ( TQStringList::const_iterator it = l.begin() ; it != l.end() ; ++it ) { 00734 TQString 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 TQString & s ) 00757 { 00758 unsigned int result = 0; 00759 00760 TQStringList sl = TQStringList::split( '\n', s.upper() ); 00761 for ( TQStringList::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 TQStringList & sl ) 00779 { 00780 unsigned int result = 0; 00781 00782 for ( TQStringList::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"