Index: kioslaves/imap4/mimeheader.cc
===================================================================
--- kioslaves/imap4/mimeheader.cc	(revision 510129)
+++ kioslaves/imap4/mimeheader.cc	(working copy)
@@ -331,9 +331,11 @@
   uint vlen, llen;
   QString val = aValue;
 
+  if ( aLabel.isEmpty() ) // safety check to prevent infinite recursion
+    return;
+
   if (aDict)
   {
-
     //see if it needs to get encoded
     if (encoded && aLabel.find ('*') == -1)
     {
@@ -356,13 +358,30 @@
         if (limit > int(vlen))
           limit = vlen;
         offset = val.findRev ('%', limit);
+        if ( offset == -1 && ( val.right( 2 ) == "?=" ) )
+        {
+          // windows variation of % encoding, using =
+          offset = val.findRev('=', limit);
+        }
+        if ( offset == -1 ) // we found no encoding escape chars
+          offset = 0;
         if (offset == limit - 1 || offset == limit - 2)
         {
-//          cout << "offset " << offset << "-" << limit << "=" << limit-offset << endl;
+          //kdDebug() << "limit-offset= " << limit << "-" << offset << "=" << limit-offset << endl;
           offset = limit - offset;
         }
         else
           offset = 0;
+        if ( ( limit - offset ) < 1 )
+        {
+          // panic, we can't make this work properly
+          // eg we have a size limit of 1 for the value and encoding dictates
+          // an offset.
+          // for safety, truncate the label chars and try again
+          kdWarning(7116) << k_funcinfo << "Had to truncate oversize mime header label: " << aLabel << " by 20 chars." << endl;
+          setParameter( aLabel.left( llen - 20 ), aValue, aDict );
+          return;
+        }
         shortValue = val.left (limit - offset);
         shortLabel.setNum (i);
         shortLabel = aLabel + "*" + shortLabel;
@@ -376,7 +395,7 @@
           }
           shortLabel += "*";
         }
-//        cout << shortLabel << "-" << shortValue << endl;
+        //kdDebug() << "shortLabel-shortValue: " << shortLabel << "-" << shortValue << endl;
         aDict->insert (shortLabel, new QString (shortValue));
         i++;
       }
Index: kioslaves/imap4/imapparser.cc
===================================================================
--- kioslaves/imap4/imapparser.cc	(revision 510129)
+++ kioslaves/imap4/imapparser.cc	(working copy)
@@ -949,7 +949,9 @@
 
     while (!inWords.isEmpty () && inWords[0] != ')')
     {
-      retVal.insert (parseLiteralC(inWords), new QString(parseLiteralC(inWords)));
+      QCString key = parseLiteralC(inWords);
+      QString * value = new QString(parseLiteralC(inWords));
+      retVal.insert ( key, value );
     }
 
     if (inWords[0] != ')')
