Bug 132560 - When changing identity, the transport is then reset to the wrong one
Summary: When changing identity, the transport is then reset to the wrong one
Status: RESOLVED FIXED
Alias: None
Product: kmail
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Fedora RPMs Linux
: NOR normal
Target Milestone: ---
Assignee: kdepim bugs
URL:
Keywords:
: 133422 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-08-17 18:55 UTC by David Anderson
Modified: 2007-09-14 12:17 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Anderson 2006-08-17 18:55:57 UTC
Version:            (using KDE KDE 3.5.3)
Installed from:    Fedora RPMs
OS:                Linux

I have two computers on which I use kmail, and both manifest this bug.

Both machines have several accounts, and several transports.

When I change the account being used in a compose window to a different one, and then hit "Send", kmail decides to use the first-listed transport. Not the default transport - the first listed one in the configuration (the "Outgoing accounts" tab - the first listed one is not the default).

Neither the default account nor the one being changed to has a special transport. Therefore, the default transport should continue to be used. Kmail selects the first-listed transport for no good reason, and I have to override manually. Happens every time.
Comment 1 Magnus Holmgren 2006-08-17 19:05:59 UTC
See also bug 126288. It could be the same bug if the reporters only saw one of cases in which it manifests itself.
Comment 2 2006-09-02 05:09:32 UTC
I also confirm this, a very annoying bug.
Comment 3 Ingo Klöcker 2006-10-17 21:11:13 UTC
*** Bug 133422 has been marked as a duplicate of this bug. ***
Comment 4 Ingo Klöcker 2006-10-17 21:17:28 UTC
SVN commit 596514 by kloecker:

Fix bug 132560 (When changing identity, the transport is then reset to the wrong one)

I've got this patch on my harddisk for a long time. The patch should also fix a few other transport related bugs.

BUG:132560


 M  +37 -31    kmcomposewin.cpp  
 M  +8 -0      kmcomposewin.h  


--- branches/KDE/3.5/kdepim/kmail/kmcomposewin.cpp #596513:596514
@@ -620,18 +620,11 @@
   while ( transportHistory.count() > (uint)GlobalSettings::self()->maxTransportEntries() )
     transportHistory.remove( transportHistory.last() );
   mTransport->insertStringList( transportHistory );
-  if (mBtnTransport->isChecked() && !currentTransport.isEmpty())
-  {
-    for (int i = 0; i < mTransport->count(); i++)
-      if (mTransport->text(i) == currentTransport)
-        mTransport->setCurrentItem(i);
-    mTransport->setEditText( currentTransport );
+  mTransport->setCurrentText( GlobalSettings::self()->defaultTransport() );
+  if ( mBtnTransport->isChecked() ) {
+    setTransport( currentTransport );
   }
 
-  if ( !mBtnTransport->isChecked() ) {
-    mTransport->setCurrentText( GlobalSettings::self()->defaultTransport() );
-  }
-
   QString fccName = "";
   if ( mBtnFcc->isChecked() ) {
     fccName = GlobalSettings::self()->previousFcc();
@@ -1659,6 +1652,37 @@
 }
 
 //-----------------------------------------------------------------------------
+void KMComposeWin::setTransport( const QString & transport )
+{
+  kdDebug(5006) << "KMComposeWin::setTransport( \"" << transport << "\" )" << endl;
+  // Don't change the transport combobox if transport is empty
+  if ( transport.isEmpty() )
+    return;
+
+  bool transportFound = false;
+  for ( int i = 0; i < mTransport->count(); ++i ) {
+    if ( mTransport->text(i) == transport ) {
+      transportFound = true;
+      mTransport->setCurrentItem(i);
+      kdDebug(5006) << "transport found, it's no. " << i << " in the list" << endl;
+      break;
+    }
+  }
+  if ( !transportFound ) { // unknown transport
+    kdDebug(5006) << "unknown transport \"" << transport << "\"" << endl;
+    if ( transport.startsWith("smtp://") || transport.startsWith("smtps://") ||
+         transport.startsWith("file://") ) {
+      // set custom transport
+      mTransport->setEditText( transport );
+    }
+    else {
+      // neither known nor custom transport -> use default transport
+      mTransport->setCurrentText( GlobalSettings::self()->defaultTransport() );
+    }
+  }
+}
+
+//-----------------------------------------------------------------------------
 void KMComposeWin::setMsg(KMMessage* newMsg, bool mayAutoSign,
                           bool allowDecryption, bool isModified)
 {
@@ -1778,12 +1802,7 @@
 
   QString transport = newMsg->headerField("X-KMail-Transport");
   if (!mBtnTransport->isChecked() && !transport.isEmpty())
-  {
-    for (int i = 0; i < mTransport->count(); i++)
-      if (mTransport->text(i) == transport)
-        mTransport->setCurrentItem(i);
-    mTransport->setEditText( transport );
-  }
+    setTransport( transport );
 
   if (!mBtnFcc->isChecked())
   {
@@ -4293,24 +4312,11 @@
     if ( transp.isEmpty() )
     {
       mMsg->removeHeaderField("X-KMail-Transport");
-      transp = mTransport->text(0);
+      transp = GlobalSettings::self()->defaultTransport();
     }
     else
       mMsg->setHeaderField("X-KMail-Transport", transp);
-    bool found = false;
-    int i;
-    for (i = 0; i < mTransport->count(); i++) {
-      if (mTransport->text(i) == transp) {
-        found = true;
-        mTransport->setCurrentItem(i);
-        break;
-      }
-    }
-    if (found == false) {
-      if (i == mTransport->maxCount()) mTransport->setMaxCount(i + 1);
-      mTransport->insertItem(transp,i);
-      mTransport->setCurrentItem(i);
-    }
+    setTransport( transp );
   }
 
   mDictionaryCombo->setCurrentByDictionary( ident.dictionary() );
--- branches/KDE/3.5/kdepim/kmail/kmcomposewin.h #596513:596514
@@ -649,6 +649,14 @@
    */
   static bool validateAddresses( QWidget * parent, const QString & addresses );
 
+  /**
+   * Sets the transport combobox to @p transport. If @p transport is empty
+   * then the combobox remains unchanged. If @p transport is neither a known transport
+   * nor a custom transport then the combobox is set to the default transport.
+   * @param transport the transport the combobox should be set to
+   */
+  void setTransport( const QString & transport );
+
 private slots:
    /**
     * Compress an attachemnt with the given index
Comment 5 2006-10-17 21:52:00 UTC
was this fix already commited in branch_3.5?
Comment 6 Ingo Klöcker 2006-10-17 23:16:44 UTC
Yes, I've committed the fix two hours ago to the 3.5 branch.