Bug 1404654 - use FOLDER_SUFFIX and SUMMARY_SUFFIX constants where possible, use #define for length. r=jorgk
--- a/mailnews/base/public/msgCore.h
+++ b/mailnews/base/public/msgCore.h
@@ -21,22 +21,24 @@ class nsIMsgFolder;
#include "nsIServiceManager.h"
#include "nsIComponentManager.h"
/*
* The suffix we use for the mail summary file.
*/
#define SUMMARY_SUFFIX u".msf"
#define SUMMARY_SUFFIX8 ".msf"
+#define SUMMARY_SUFFIX_LENGTH 4
/*
* The suffix we use for folder subdirectories.
*/
#define FOLDER_SUFFIX u".sbd"
#define FOLDER_SUFFIX8 ".sbd"
+#define FOLDER_SUFFIX_LENGTH 4
/*
* These are folder property strings, which are used in several places.
*/
// Most recently used (opened, moved to, got new messages)
#define MRU_TIME_PROPERTY "MRUTime"
// Most recently moved to, for recent folders list in move menu
--- a/mailnews/base/search/src/nsMsgFilter.cpp
+++ b/mailnews/base/search/src/nsMsgFilter.cpp
@@ -791,21 +791,21 @@ nsresult nsMsgFilter::ConvertMoveOrCopyT
}
if (NS_SUCCEEDED(rv) && localMailRoot)
{
nsCString localRootURI;
nsCOMPtr <nsIMsgFolder> destIMsgFolder;
nsCOMPtr <nsIMsgFolder> localMailRootMsgFolder = do_QueryInterface(localMailRoot);
localMailRoot->GetURI(localRootURI);
nsCString destFolderUri;
- destFolderUri.Assign( localRootURI);
+ destFolderUri.Assign(localRootURI);
// need to remove ".sbd" from moveValue, and perhaps escape it.
- int32_t offset = moveValue.Find(".sbd/");
+ int32_t offset = moveValue.Find(FOLDER_SUFFIX8 "/");
if (offset != -1)
- moveValue.Cut(offset, 4);
+ moveValue.Cut(offset, FOLDER_SUFFIX_LENGTH);
#ifdef XP_MACOSX
nsCString unescapedMoveValue;
MsgUnescapeString(moveValue, 0, unescapedMoveValue);
moveValue = unescapedMoveValue;
#endif
destFolderUri.Append('/');
if (filterVersion == k45Version)
--- a/mailnews/base/util/nsMsgDBFolder.cpp
+++ b/mailnews/base/util/nsMsgDBFolder.cpp
@@ -918,17 +918,17 @@ nsresult nsMsgDBFolder::CreateFileForDB(
dbPath->Exists(&exists);
if (exists)
{
rv = dbPath->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 00600);
NS_ENSURE_SUCCESS(rv, rv);
dbPath->GetLeafName(proposedDBName);
}
// now, take the ".msf" off
- proposedDBName.SetLength(proposedDBName.Length() - NS_LITERAL_STRING(SUMMARY_SUFFIX).Length());
+ proposedDBName.SetLength(proposedDBName.Length() - SUMMARY_SUFFIX_LENGTH);
dbPath->SetLeafName(proposedDBName);
dbPath.forget(dbFile);
return NS_OK;
}
NS_IMETHODIMP
nsMsgDBFolder::GetMsgDatabase(nsIMsgDatabase** aMsgDatabase)
@@ -4067,17 +4067,17 @@ NS_IMETHODIMP nsMsgDBFolder::Rename(cons
{
ThrowAlertMsg("folderRenameFailed", msgWindow);
return rv;
}
if (NS_SUCCEEDED(rv) && count > 0)
{
// rename "*.sbd" directory
- newNameDirStr.AppendLiteral(".sbd");
+ newNameDirStr.AppendLiteral(FOLDER_SUFFIX);
dirFile->MoveTo(nullptr, newNameDirStr);
}
nsCOMPtr<nsIMsgFolder> newFolder;
if (parentSupport)
{
rv = parentFolder->AddSubfolder(aNewName, getter_AddRefs(newFolder));
if (newFolder)
--- a/mailnews/base/util/nsMsgUtils.cpp
+++ b/mailnews/base/util/nsMsgUtils.cpp
@@ -577,17 +577,17 @@ nsresult NS_MsgCreatePathStringFromFolde
pathPiece.Assign(Substring(oldPath, startSlashPos + 1, endSlashPos - startSlashPos));
// skip leading '/' (and other // style things)
if (!pathPiece.IsEmpty())
{
// add .sbd onto the previous path
if (haveFirst)
{
- path.AppendLiteral(".sbd/");
+ path.AppendLiteral(FOLDER_SUFFIX "/");
}
if (aIsNewsFolder)
{
nsAutoCString tmp;
CopyUTF16toMUTF7(pathPiece, tmp);
CopyASCIItoUTF16(tmp, pathPiece);
}
--- a/mailnews/db/msgdb/src/nsMailDatabase.cpp
+++ b/mailnews/db/msgdb/src/nsMailDatabase.cpp
@@ -40,17 +40,17 @@ nsMailDatabase::~nsMailDatabase()
// If so, they'll extract out the interesting info from the db, close it, delete it, and
// then try to open the db again, prior to reparsing.
nsresult nsMailDatabase::Open(nsMsgDBService* aDBService, nsIFile *aSummaryFile,
bool aCreate, bool aUpgrading)
{
#ifdef DEBUG
nsString leafName;
aSummaryFile->GetLeafName(leafName);
- if (!StringEndsWith(leafName, NS_LITERAL_STRING(".msf"),
+ if (!StringEndsWith(leafName, NS_LITERAL_STRING(SUMMARY_SUFFIX),
nsCaseInsensitiveStringComparator()))
NS_ERROR("non summary file passed into open\n");
#endif
return nsMsgDatabase::Open(aDBService, aSummaryFile, aCreate, aUpgrading);
}
NS_IMETHODIMP nsMailDatabase::ForceClosed()
{
--- a/mailnews/imap/src/nsImapMailFolder.cpp
+++ b/mailnews/imap/src/nsImapMailFolder.cpp
@@ -246,23 +246,19 @@ nsresult nsImapMailFolder::AddDirectoryS
}
return NS_OK;
}
static bool
nsShouldIgnoreFile(nsString& name)
{
- int32_t len = name.Length();
- // Warning: The first argument of RFind() needs to be a char string here so
- // that the second argument means 'ignorecase'. When passing a char16_t here,
- // a different overload is triggered and the argument is interpreted as offset.
- if (len > 4 && name.RFind(SUMMARY_SUFFIX8, true) == len - 4)
- {
- name.SetLength(len-4); // truncate the string
+ if (StringEndsWith(name, NS_LITERAL_STRING(SUMMARY_SUFFIX), nsCaseInsensitiveStringComparator()))
+ {
+ name.SetLength(name.Length() - SUMMARY_SUFFIX_LENGTH); // truncate the string
return false;
}
return true;
}
nsresult nsImapMailFolder::CreateChildFromURI(const nsCString &uri, nsIMsgFolder **folder)
{
nsImapMailFolder *newFolder = new nsImapMailFolder;
@@ -1709,17 +1705,17 @@ NS_IMETHODIMP nsImapMailFolder::RenameLo
NS_ENSURE_SUCCESS(rv, rv);
nsAutoCString newNameStr;
oldSummaryFile->Remove(false);
if (count > 0)
{
newNameStr = leafname;
NS_MsgHashIfNecessary(newNameStr);
- newNameStr += ".sbd";
+ newNameStr.AppendLiteral(FOLDER_SUFFIX8);
nsAutoCString leafName;
dirFile->GetNativeLeafName(leafName);
if (!leafName.Equals(newNameStr))
return dirFile->MoveToNative(nullptr, newNameStr); // in case of rename operation leaf names will differ
parentPathFile->AppendNative(newNameStr); //only for move we need to progress further in case the parent differs
bool isDirectory = false;
parentPathFile->IsDirectory(&isDirectory);
--- a/mailnews/local/src/nsMsgBrkMBoxStore.cpp
+++ b/mailnews/local/src/nsMsgBrkMBoxStore.cpp
@@ -382,24 +382,24 @@ NS_IMETHODIMP nsMsgBrkMBoxStore::RenameF
aFolder->ForceDBClosed();
//save off dir name before appending .msf
rv = oldPathFile->MoveTo(nullptr, safeName);
if (NS_FAILED(rv))
return rv;
nsString dbName(safeName);
- dbName += NS_LITERAL_STRING(SUMMARY_SUFFIX);
+ dbName.AppendLiteral(SUMMARY_SUFFIX);
oldSummaryFile->MoveTo(nullptr, dbName);
if (numChildren > 0)
{
// rename "*.sbd" directory
nsAutoString newNameDirStr(safeName);
- newNameDirStr += NS_LITERAL_STRING(".sbd");
+ newNameDirStr.AppendLiteral(FOLDER_SUFFIX);
dirFile->MoveTo(nullptr, newNameDirStr);
}
return parentFolder->AddSubfolder(safeName, aNewFolder);
}
NS_IMETHODIMP nsMsgBrkMBoxStore::CopyFolder(nsIMsgFolder *aSrcFolder,
nsIMsgFolder *aDstFolder,
@@ -457,17 +457,17 @@ NS_IMETHODIMP nsMsgBrkMBoxStore::CopyFol
NS_ENSURE_SUCCESS(rv, rv); // Will fail if a file by that name exists
// Copy to dir can fail if filespec does not exist. If copy fails, we test
// if the filespec exist or not, if it does not that's ok, we continue
// without copying it. If it fails and filespec exist and is not zero sized
// there is real problem
// Copy the file to the new dir
nsAutoString dbName(safeFolderName);
- dbName += NS_LITERAL_STRING(SUMMARY_SUFFIX);
+ dbName.AppendLiteral(SUMMARY_SUFFIX);
rv = summaryFile->CopyTo(newPath, dbName);
if (NS_FAILED(rv)) // Test if the copy is successful
{
// Test if the filespec has data
bool exists;
int64_t fileSize;
summaryFile->Exists(&exists);
summaryFile->GetFileSize(&fileSize);
@@ -1019,17 +1019,17 @@ nsMsgBrkMBoxStore::AddSubFolders(nsIMsgF
path->IsDirectory(&isDirectory);
if (!isDirectory)
{
rv = path->Clone(getter_AddRefs(tmp));
path = tmp;
NS_ENSURE_SUCCESS(rv, rv);
nsAutoString leafName;
path->GetLeafName(leafName);
- leafName.AppendLiteral(".sbd");
+ leafName.AppendLiteral(FOLDER_SUFFIX);
path->SetLeafName(leafName);
path->IsDirectory(&isDirectory);
}
if (!isDirectory)
return NS_OK;
// first find out all the current subfolders and files, before using them
// while creating new subfolders; we don't want to modify and iterate the same
// directory at once.
--- a/mailnews/local/src/nsMsgLocalStoreUtils.cpp
+++ b/mailnews/local/src/nsMsgLocalStoreUtils.cpp
@@ -53,17 +53,17 @@ nsMsgLocalStoreUtils::nsShouldIgnoreFile
// ignore RSS data source files
if (name.LowerCaseEqualsLiteral("feeds.rdf") ||
name.LowerCaseEqualsLiteral("feeditems.rdf") ||
StringBeginsWith(name, NS_LITERAL_STRING("feeditems_error")))
return true;
// The .mozmsgs dir is for spotlight support
return (StringEndsWith(name, NS_LITERAL_STRING(".mozmsgs")) ||
- StringEndsWith(name, NS_LITERAL_STRING(".sbd")) ||
+ StringEndsWith(name, NS_LITERAL_STRING(FOLDER_SUFFIX)) ||
StringEndsWith(name, NS_LITERAL_STRING(SUMMARY_SUFFIX)));
}
/**
* We're passed a stream positioned at the start of the message.
* We start reading lines, looking for x-mozilla-keys: headers; If we're
* adding the keyword and we find a header with the desired keyword already
* in it, we don't need to do anything. Likewise, if removing keyword and we
--- a/mailnews/local/src/nsMsgMaildirStore.cpp
+++ b/mailnews/local/src/nsMsgMaildirStore.cpp
@@ -376,23 +376,23 @@ NS_IMETHODIMP nsMsgMaildirStore::RenameF
// rename folder
rv = oldPathFile->MoveTo(nullptr, safeName);
NS_ENSURE_SUCCESS(rv, rv);
if (numChildren > 0)
{
// rename "*.sbd" directory
nsAutoString sbdName = safeName;
- sbdName += NS_LITERAL_STRING(FOLDER_SUFFIX);
+ sbdName.AppendLiteral(FOLDER_SUFFIX);
sbdPathFile->MoveTo(nullptr, sbdName);
}
// rename summary
nsAutoString summaryName(safeName);
- summaryName += NS_LITERAL_STRING(SUMMARY_SUFFIX);
+ summaryName.AppendLiteral(SUMMARY_SUFFIX);
oldSummaryFile->MoveTo(nullptr, summaryName);
nsCOMPtr<nsIMsgFolder> parentFolder;
rv = aFolder->GetParent(getter_AddRefs(parentFolder));
if (!parentFolder)
return NS_ERROR_NULL_POINTER;
return parentFolder->AddSubfolder(safeName, aNewFolder);
@@ -442,17 +442,17 @@ NS_IMETHODIMP nsMsgMaildirStore::CopyFol
rv = oldPath->CopyTo(newPath, safeFolderName);
NS_ENSURE_SUCCESS(rv, rv); //will fail if a file by that name exists
// Copy to dir can fail if file does not exist. If copy fails, we test
// if the file exists or not, if it does not that's ok, we continue
// without copying it. If it fails and file exist and is not zero sized
// there is real problem.
nsAutoString dbName(safeFolderName);
- dbName += NS_LITERAL_STRING(SUMMARY_SUFFIX);
+ dbName.AppendLiteral(SUMMARY_SUFFIX);
rv = summaryFile->CopyTo(newPath, dbName);
if (!NS_SUCCEEDED(rv))
{
// Test if the file is not empty
bool exists;
int64_t fileSize;
summaryFile->Exists(&exists);
summaryFile->GetFileSize(&fileSize);