Bug 475359 Fix ASSERTION: space only keyword r+sr=bienvenu
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Mon, 02 Feb 2009 23:19:20 +0000
changeset 1839 2a5433caac6e0df0f0037a109c82add5895f3114
parent 1838 500ab5266b589051ccdbb06c78753f949d5b8e1c
child 1840 1791f2d1a2b85ca11abce0169f8e4a9b6b779707
push idunknown
push userunknown
push dateunknown
bugs475359
Bug 475359 Fix ASSERTION: space only keyword r+sr=bienvenu
mailnews/base/util/nsMsgDBFolder.cpp
--- a/mailnews/base/util/nsMsgDBFolder.cpp
+++ b/mailnews/base/util/nsMsgDBFolder.cpp
@@ -5313,57 +5313,63 @@ NS_IMETHODIMP nsMsgDBFolder::RemoveKeywo
   NS_ENSURE_ARG(aMessages);
   nsresult rv = NS_OK;
   GetDatabase();
   if (mDatabase)
   {
     PRUint32 count;
     nsresult rv = aMessages->GetLength(&count);
     NS_ENSURE_SUCCESS(rv, rv);
+    nsTArray<nsCString> keywordArray;
+    ParseString(aKeywords, ' ', keywordArray);
     nsCString keywords;
     // If the tag is also a label, we should remove the label too...
 
     for(PRUint32 i = 0; i < count; i++)
     {
       nsCOMPtr<nsIMsgDBHdr> message = do_QueryElementAt(aMessages, i, &rv);
       NS_ENSURE_SUCCESS(rv, rv);
       rv = message->GetStringProperty("keywords", getter_Copies(keywords));
-      nsCAutoString originalKeywords(keywords);
-      nsCStringArray keywordArray;
-      ParseString(aKeywords, ' ', keywordArray);
       PRUint32 removeCount = 0;
-      for (PRInt32 j = 0; j < keywordArray.Count(); j++)
+      for (PRUint32 j = 0; j < keywordArray.Length(); j++)
       {
-        PRBool keywordIsLabel = (StringBeginsWith(*(keywordArray[j]), NS_LITERAL_CSTRING("$label"))
-          && keywordArray[j]->CharAt(6) >= '1' && keywordArray[j]->CharAt(6) <= '5');
+        PRBool keywordIsLabel = (StringBeginsWith(keywordArray[j], NS_LITERAL_CSTRING("$label"))
+          && keywordArray[j].CharAt(6) >= '1' && keywordArray[j].CharAt(6) <= '5');
         if (keywordIsLabel)
         {
           nsMsgLabelValue labelValue;
           message->GetLabel(&labelValue);
           // if we're removing the keyword that corresponds to a pre 2.0 label,
           // we need to clear the old label attribute on the message.
-          if (labelValue == (nsMsgLabelValue) (keywordArray[j]->CharAt(6) - '0'))
+          if (labelValue == (nsMsgLabelValue) (keywordArray[j].CharAt(6) - '0'))
             message->SetLabel((nsMsgLabelValue) 0);
         }
         PRInt32 startOffset, length;
-        if (MsgFindKeyword(*(keywordArray[j]), keywords, &startOffset,&length))
+        if (MsgFindKeyword(keywordArray[j], keywords, &startOffset, &length))
         {
-          // delete any space delimiter
-          if (keywords.CharAt(startOffset + length) == ' ')
+          // delete any leading space delimiters
+          while (startOffset && keywords.CharAt(startOffset - 1) == ' ')
+          {
+            startOffset--;
+            length++;
+          }
+          // but if the keyword is at the start then delete the following space
+          if (!startOffset && length < keywords.Length() &&
+              keywords.CharAt(length) == ' ')
             length++;
           keywords.Cut(startOffset, length);
           removeCount++;
-          NS_ASSERTION(keywords.IsEmpty() || keywords.CharAt(0) != ' ', "space only keyword");
         }
       }
 
-      mDatabase->SetStringPropertyByHdr(message, "keywords", keywords.get());
-
       if (removeCount)
+      {
+        mDatabase->SetStringPropertyByHdr(message, "keywords", keywords.get());
         NotifyPropertyFlagChanged(message, kKeywords, removeCount, 0);
+      }
     }
   }
   return rv;
 }
 
 NS_IMETHODIMP nsMsgDBFolder::GetCustomIdentity(nsIMsgIdentity **aIdentity)
 {
   NS_ENSURE_ARG_POINTER(aIdentity);