diff --git a/mailnews/base/util/nsMsgDBFolder.cpp b/mailnews/base/util/nsMsgDBFolder.cpp
--- a/mailnews/base/util/nsMsgDBFolder.cpp
+++ b/mailnews/base/util/nsMsgDBFolder.cpp
@@ -842,16 +842,19 @@ NS_IMETHODIMP nsMsgDBFolder::GetOfflineS
 }
 
 // path coming in is the root path without the leaf name,
 // on the way out, it's the whole path.
 nsresult nsMsgDBFolder::CreateFileForDB(const nsAString& userLeafName, nsILocalFile *path, nsILocalFile **dbFile)
 {
   NS_ENSURE_ARG_POINTER(dbFile);
 
+  if (userLeafName.Length() == 0)
+    return NS_ERROR_FAILURE;
+
   nsAutoString proposedDBName(userLeafName);
   NS_MsgHashIfNecessary(proposedDBName);
 
   // (note, the caller of this will be using the dbFile to call db->Open()
   // will turn the path into summary file path, and append the ".msf" extension)
   //
   // we want db->Open() to create a new summary file
   // so we have to jump through some hoops to make sure the .msf it will
diff --git a/mailnews/base/util/nsMsgUtils.cpp b/mailnews/base/util/nsMsgUtils.cpp
--- a/mailnews/base/util/nsMsgUtils.cpp
+++ b/mailnews/base/util/nsMsgUtils.cpp
@@ -393,16 +393,18 @@ nsresult NS_MsgHashIfNecessary(nsCAutoSt
                                                 FILE_PATH_SEPARATOR 
                                                 FILE_ILLEGAL_CHARACTERS 
                                                 ILLEGAL_FOLDER_CHARS);
 
   // Need to check the first ('.') and last ('.', '~' and ' ') char
   if (illegalCharacterIndex == -1)
   {
     PRInt32 lastIndex = str.Length() - 1;
+	if (lastIndex == -1)
+      illegalCharacterIndex = -1;
     if (NS_LITERAL_CSTRING(ILLEGAL_FOLDER_CHARS_AS_FIRST_LETTER).FindChar(str[0]) != -1)
       illegalCharacterIndex = 0;
     else if (NS_LITERAL_CSTRING(ILLEGAL_FOLDER_CHARS_AS_LAST_LETTER).FindChar(str[lastIndex]) != -1)
       illegalCharacterIndex = lastIndex;
     else
       illegalCharacterIndex = -1;
   }
 
@@ -446,16 +448,18 @@ nsresult NS_MsgHashIfNecessary(nsAutoStr
                                                 FILE_PATH_SEPARATOR 
                                                 FILE_ILLEGAL_CHARACTERS 
                                                 ILLEGAL_FOLDER_CHARS);
 
   // Need to check the first ('.') and last ('.', '~' and ' ') char
   if (illegalCharacterIndex == -1)
   {
     PRInt32 lastIndex = name.Length() - 1;
+	if (lastIndex == -1)
+      illegalCharacterIndex = -1;
     if (NS_LITERAL_STRING(ILLEGAL_FOLDER_CHARS_AS_FIRST_LETTER).FindChar(name[0]) != -1)
       illegalCharacterIndex = 0;
     else if (NS_LITERAL_STRING(ILLEGAL_FOLDER_CHARS_AS_LAST_LETTER).FindChar(name[lastIndex]) != -1)
       illegalCharacterIndex = lastIndex;
     else
       illegalCharacterIndex = -1;
   }
 
