[Kde-pim] KDE/kdepim/runtime/resources/imap

Casey Link unnamedrambler at gmail.com
Sat Jun 5 01:11:34 BST 2010


SVN commit 1134685 by link:

imap resource:  revert the resource config to store the auth enum type in MailTransport's representation, rather then KIMAP's.

You must reset your imap resources' settings (doing an autodetect is easiest).

So a month ago when I refactored the imap resource config, I thought
"Hey?! why bother storing the MailTransport Auth type internally when
this is the imap resource and we have our own enum auth type? After all
its better to keep things consistent internally, and the only place to
change the authtype is in the config dialog." So, I changed it to use the
KIMAP::LoginJob::AuthenticationMode.

It seemed reasonable at the time, but I was very wrong. The auth mode is changed
in many places *not* the config dialog which I wasn't aware of then (account wizards
for example). Of course  I didn't get any compile time errors then, because
the auth type was being set via roundabout ways and usually directly as an integer.

This reverts that, and performs the MailTransport enum -> KIMAP enum at the last
instance possible (right before passing it to KIMAP::LoginJob). So now all those places
where you have imapResource.setAuthMode(4) will work as expected again (i.e., setting
MailTransport's auth type). My apologies for borking it up in the first place, I'm sorry.
If only java-c++-script were super-duper-strongly typed.

CCMAIL:kde-pim at kde.org

 M  +36 -1     imapaccount.cpp  
 M  +4 -0      imapaccount.h  
 M  +30 -67    setupserver.cpp  


--- trunk/KDE/kdepim/runtime/resources/imap/imapaccount.cpp #1134684:1134685
@@ -43,6 +43,41 @@
 
 #include "settings.h"
 
+/**
+ * Maps the enum used to represent authentication in MailTransport (kdepimlibs)
+ * to the one used by the imap resource.
+ * @param authType the MailTransport auth enum value
+ * @return the corresponding KIMAP auth value.
+ * @note will cause fatal error if there is no mapping, so be careful not to pass invalid auth options (e.g., APOP) to this function.
+ */
+KIMAP::LoginJob::AuthenticationMode ImapAccount::mapTransportAuthToKimap( MailTransport::Transport::EnumAuthenticationType::type authType )
+{
+  // typedef these for readability
+  typedef MailTransport::Transport::EnumAuthenticationType MTAuth;
+  typedef KIMAP::LoginJob KIAuth;
+  switch ( authType ) {
+    case MTAuth::ANONYMOUS:
+      return KIAuth::Anonymous;
+    case MTAuth::PLAIN:
+      return KIAuth::Plain;
+    case MTAuth::NTLM:
+      return KIAuth::NTLM;
+    case MTAuth::LOGIN:
+      return KIAuth::Login;
+    case MTAuth::GSSAPI:
+      return KIAuth::GSSAPI;
+    case MTAuth::DIGEST_MD5:
+      return KIAuth::DigestMD5;
+    case MTAuth::CRAM_MD5:
+      return KIAuth::CramMD5;
+    case MTAuth::CLEAR:
+      return KIAuth::ClearText;
+    default:
+      kFatal() << "mapping from Transport::EnumAuthenticationType ->  KIMAP::LoginJob::AuthenticationMode not possible";
+  }
+  return KIAuth::ClearText; // dummy value, shouldn't get here.
+}
+
 class SessionUiProxy : public KIMAP::SessionUiProxy {
   public:
     bool ignoreSslError(const KSslErrorUiData& errorData) {
@@ -74,7 +109,7 @@
     m_encryption = KIMAP::LoginJob::TlsV1;
   else
     m_encryption = KIMAP::LoginJob::Unencrypted;
-  m_authentication = (KIMAP::LoginJob::AuthenticationMode) settings->authentication();
+  m_authentication = mapTransportAuthToKimap( (MailTransport::TransportBase::EnumAuthenticationType::type) settings->authentication() );
 }
 
 ImapAccount::ImapAccount( QObject *parent )
--- trunk/KDE/kdepim/runtime/resources/imap/imapaccount.h #1134684:1134685
@@ -24,6 +24,8 @@
 
 class KJob;
 
+#include <mailtransport/transport.h>
+
 #include <akonadi/resourcebase.h>
 #include <boost/shared_ptr.hpp>
 #include <QtCore/QStringList>
@@ -84,6 +86,8 @@
   QStringList capabilities() const;
   QList<KIMAP::MailBoxDescriptor> namespaces() const;
 
+  static KIMAP::LoginJob::AuthenticationMode mapTransportAuthToKimap( MailTransport::Transport::EnumAuthenticationType::type authType );
+
 Q_SIGNALS:
   void success( KIMAP::Session *session );
   void error( KIMAP::Session *session, int code, const QString &message );
--- trunk/KDE/kdepim/runtime/resources/imap/setupserver.cpp #1134684:1134685
@@ -60,26 +60,25 @@
 #include "ui_setupserverview_desktop.h"
 #endif
 
-
 /** static helper functions **/
-static QString authenticationModeString( KIMAP::LoginJob::AuthenticationMode mode )
+static QString authenticationModeString( MailTransport::Transport::EnumAuthenticationType::type mode )
 {
   switch ( mode ) {
-    case KIMAP::LoginJob::Login:
+    case  MailTransport::Transport::EnumAuthenticationType::LOGIN:
       return "LOGIN";
-    case KIMAP::LoginJob::Plain:
+    case MailTransport::Transport::EnumAuthenticationType::PLAIN:
       return "PLAIN";
-    case KIMAP::LoginJob::CramMD5:
+    case MailTransport::Transport::EnumAuthenticationType::CRAM_MD5:
       return "CRAM-MD5";
-    case KIMAP::LoginJob::DigestMD5:
+    case MailTransport::Transport::EnumAuthenticationType::DIGEST_MD5:
       return "DIGEST-MD5";
-    case KIMAP::LoginJob::GSSAPI:
+    case MailTransport::Transport::EnumAuthenticationType::GSSAPI:
       return "GSSAPI";
-    case KIMAP::LoginJob::NTLM:
+    case MailTransport::Transport::EnumAuthenticationType::NTLM:
       return "NTLM";
-    case KIMAP::LoginJob::ClearText:
+    case MailTransport::Transport::EnumAuthenticationType::CLEAR:
       return i18nc( "Authentication method", "Clear text" );
-    case KIMAP::LoginJob::Anonymous:
+    case MailTransport::Transport::EnumAuthenticationType::ANONYMOUS:
       return i18nc( "Authentication method", "Anonymous" );
     default:
       break;
@@ -87,27 +86,27 @@
   return QString();
 }
 
-static void setCurrentAuthMode( QComboBox* authCombo, KIMAP::LoginJob::AuthenticationMode authtype )
+static void setCurrentAuthMode( QComboBox* authCombo, MailTransport::Transport::EnumAuthenticationType::type authtype )
 {
   kDebug() << "setting authcombo: " << authenticationModeString( authtype );
   int index = authCombo->findData( authtype );
   if( index == -1 )
     kWarning() << "desired authmode not in the combo";
-  kDebug() << "found corresponding index: " << index << "with data" << authenticationModeString( (KIMAP::LoginJob::AuthenticationMode) authCombo->itemData( index ).toInt() );
+  kDebug() << "found corresponding index: " << index << "with data" << authenticationModeString( (MailTransport::Transport::EnumAuthenticationType::type) authCombo->itemData( index ).toInt() );
   authCombo->setCurrentIndex( index );
-  KIMAP::LoginJob::AuthenticationMode t = (KIMAP::LoginJob::AuthenticationMode) authCombo->itemData( authCombo->currentIndex() ).toInt();
+  MailTransport::Transport::EnumAuthenticationType::type t = (MailTransport::Transport::EnumAuthenticationType::type) authCombo->itemData( authCombo->currentIndex() ).toInt();
   kDebug() << "selected auth mode:" << authenticationModeString( t );
   Q_ASSERT( t == authtype );
 }
 
-static KIMAP::LoginJob::AuthenticationMode getCurrentAuthMode( QComboBox* authCombo )
+static MailTransport::Transport::EnumAuthenticationType::type getCurrentAuthMode( QComboBox* authCombo )
 {
-  KIMAP::LoginJob::AuthenticationMode authtype = (KIMAP::LoginJob::AuthenticationMode) authCombo->itemData( authCombo->currentIndex() ).toInt();
+  MailTransport::Transport::EnumAuthenticationType::type authtype = (MailTransport::Transport::EnumAuthenticationType::type) authCombo->itemData( authCombo->currentIndex() ).toInt();
   kDebug() << "current auth mode: " << authenticationModeString( authtype );
   return authtype;
 }
 
-static void addAuthenticationItem( QComboBox* authCombo, KIMAP::LoginJob::AuthenticationMode authtype )
+static void addAuthenticationItem( QComboBox* authCombo, MailTransport::Transport::EnumAuthenticationType::type authtype )
 {
     kDebug() << "adding auth item " << authenticationModeString( authtype );
     authCombo->addItem( authenticationModeString( authtype ), QVariant( authtype ) );
@@ -255,7 +254,7 @@
     kFatal() << "Shouldn't happen";
   }
   Settings::self()->setSafety( encryption );
-  KIMAP::LoginJob::AuthenticationMode authtype = getCurrentAuthMode( m_ui->authenticationCombo );
+  MailTransport::Transport::EnumAuthenticationType::type authtype = getCurrentAuthMode( m_ui->authenticationCombo );
   kDebug() << "saving IMAP auth mode: " << authenticationModeString( authtype );
   Settings::self()->setAuthentication( authtype );
   Settings::self()->setPassword( m_ui->password->text() );
@@ -326,8 +325,8 @@
 
   populateDefaultAuthenticationOptions();
   i = Settings::self()->authentication();
-  kDebug() << "read IMAP auth mode: " << authenticationModeString( (KIMAP::LoginJob::AuthenticationMode) i );
-  setCurrentAuthMode( m_ui->authenticationCombo, (KIMAP::LoginJob::AuthenticationMode) i );
+  kDebug() << "read IMAP auth mode: " << authenticationModeString( (MailTransport::Transport::EnumAuthenticationType::type) i );
+  setCurrentAuthMode( m_ui->authenticationCombo, (MailTransport::Transport::EnumAuthenticationType::type) i );
 
   bool rejected = false;
   QString password = Settings::self()->password( &rejected );
@@ -484,41 +483,6 @@
   button( KDialog::Ok )->setEnabled( ok );
 }
 
-/**
- * Maps the enum used to represent authentication in MailTransport (kdepimlibs)
- * to the one used by the imap resource.
- * @param authType the MailTransport auth enum value
- * @return the corresponding KIMAP auth value.
- * @note will cause fatal error if there is no mapping, so be careful not to pass invalid auth options (e.g., APOP) to this function.
- */
-static KIMAP::LoginJob::AuthenticationMode mapTransportAuthToKimap( MailTransport::Transport::EnumAuthenticationType::type authType )
-{
-  // setup some nice shortcuts
-  typedef MailTransport::Transport::EnumAuthenticationType MTAuth;
-  typedef KIMAP::LoginJob KIAuth;
-  switch ( authType ) {
-    case MTAuth::ANONYMOUS:
-      return KIAuth::Anonymous;
-    case MTAuth::PLAIN:
-      return KIAuth::Plain;
-    case MTAuth::NTLM:
-      return KIAuth::NTLM;
-    case MTAuth::LOGIN:
-      return KIAuth::Login;
-    case MTAuth::GSSAPI:
-      return KIAuth::GSSAPI;
-    case MTAuth::DIGEST_MD5:
-      return KIAuth::DigestMD5;
-    case MTAuth::CRAM_MD5:
-      return KIAuth::CramMD5;
-    case MTAuth::CLEAR:
-      return KIAuth::ClearText;
-    default:
-      kFatal() << "mapping from Transport::EnumAuthenticationType -> KIMAP::LoginJob::AuthenticationMode not possible";
-  }
-  return KIAuth::ClearText; // dummy value, shouldn't get here.
-}
-
 void SetupServer::slotSafetyChanged()
 {
   if ( m_serverTest == 0 ) {
@@ -551,13 +515,12 @@
   }
 
   m_ui->authenticationCombo->clear();
-  addAuthenticationItem( m_ui->authenticationCombo, KIMAP::LoginJob::ClearText );
+  addAuthenticationItem( m_ui->authenticationCombo, MailTransport::Transport::EnumAuthenticationType::CLEAR );
   foreach( int prot, protocols ) {
-    KIMAP::LoginJob::AuthenticationMode t = mapTransportAuthToKimap( ( MailTransport::Transport::EnumAuthenticationType::type ) prot );
-    addAuthenticationItem( m_ui->authenticationCombo, t );
+    addAuthenticationItem( m_ui->authenticationCombo, (MailTransport::Transport::EnumAuthenticationType::type) prot );
   }
   if( protocols.size() > 0 )
-    setCurrentAuthMode( m_ui->authenticationCombo, mapTransportAuthToKimap( ( MailTransport::Transport::EnumAuthenticationType::type ) protocols.first() ) );
+    setCurrentAuthMode( m_ui->authenticationCombo, (MailTransport::Transport::EnumAuthenticationType::type) protocols.first() );
   else
     kDebug() << "no authmodes found";
 }
@@ -581,7 +544,7 @@
     static_cast<KIMAP::LoginJob::EncryptionMode>( m_ui->safeImapGroup->checkedId() )
   );
 
-  account.setAuthenticationMode( getCurrentAuthMode( m_ui->authenticationCombo ) );
+  account.setAuthenticationMode( ImapAccount::mapTransportAuthToKimap( getCurrentAuthMode( m_ui->authenticationCombo ) ) );
 
   m_subscriptionsChanged = false;
   SubscriptionDialog *subscriptions = new SubscriptionDialog( this, i18n("Serverside Subscription..."), &account, m_subscriptionsChanged );
@@ -613,14 +576,14 @@
 void SetupServer::populateDefaultAuthenticationOptions()
 {
   m_ui->authenticationCombo->clear();
-  addAuthenticationItem( m_ui->authenticationCombo, KIMAP::LoginJob::ClearText );
-  addAuthenticationItem( m_ui->authenticationCombo, KIMAP::LoginJob::Login );
-  addAuthenticationItem( m_ui->authenticationCombo, KIMAP::LoginJob::Plain );
-  addAuthenticationItem( m_ui->authenticationCombo, KIMAP::LoginJob::CramMD5 );
-  addAuthenticationItem( m_ui->authenticationCombo, KIMAP::LoginJob::DigestMD5 );
-  addAuthenticationItem( m_ui->authenticationCombo, KIMAP::LoginJob::NTLM );
-  addAuthenticationItem( m_ui->authenticationCombo, KIMAP::LoginJob::GSSAPI );
-  addAuthenticationItem( m_ui->authenticationCombo, KIMAP::LoginJob::Anonymous );
+  addAuthenticationItem( m_ui->authenticationCombo, MailTransport::Transport::EnumAuthenticationType::CLEAR);
+  addAuthenticationItem( m_ui->authenticationCombo, MailTransport::Transport::EnumAuthenticationType::LOGIN );
+  addAuthenticationItem( m_ui->authenticationCombo, MailTransport::Transport::EnumAuthenticationType::PLAIN );
+  addAuthenticationItem( m_ui->authenticationCombo, MailTransport::Transport::EnumAuthenticationType::CRAM_MD5 );
+  addAuthenticationItem( m_ui->authenticationCombo, MailTransport::Transport::EnumAuthenticationType::DIGEST_MD5 );
+  addAuthenticationItem( m_ui->authenticationCombo, MailTransport::Transport::EnumAuthenticationType::NTLM );
+  addAuthenticationItem( m_ui->authenticationCombo, MailTransport::Transport::EnumAuthenticationType::GSSAPI );
+  addAuthenticationItem( m_ui->authenticationCombo, MailTransport::Transport::EnumAuthenticationType::ANONYMOUS );
 }
 
 
_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/



More information about the kde-pim mailing list