Bug 1705765 - Fix regression to allow creation and rename of imap folders containing ascii ampersand. r=benc

This commit is contained in:
Gene Smith 2021-04-22 12:57:31 +03:00
Родитель 794d182373
Коммит 5c2abe79ee
2 изменённых файлов: 31 добавлений и 21 удалений

Просмотреть файл

@ -141,11 +141,20 @@ nsresult CopyUTF16toMUTF7(const nsAString& aSrc, nsACString& aDest) {
// MUTF-7 or UTF-8.
nsresult CopyFolderNameToUTF16(const nsACString& aSrc, nsAString& aDest) {
if (NS_IsAscii(aSrc.BeginReading(), aSrc.Length())) {
return CopyMUTF7toUTF16(aSrc, aDest);
} else {
CopyUTF8toUTF16(aSrc, aDest);
return NS_OK;
// An ASCII string may not be valid MUTF-7. For example, it may contain an
// ampersand not immediately followed by a dash which is invalid MUTF-7.
// Check for validity by converting to UTF-16 and then back to MUTF-7 and
// the result should be unchanged. If the MUTF-7 is invalid, treat it as
// UTF-8.
if (NS_SUCCEEDED(CopyMUTF7toUTF16(aSrc, aDest))) {
nsAutoCString tmp;
CopyUTF16toMUTF7(aDest, tmp);
if (aSrc.Equals(tmp)) return NS_OK;
}
}
// Do if aSrc non-ASCII or if ASCII but invalid MUTF-7.
CopyUTF8toUTF16(aSrc, aDest);
return NS_OK;
}
nsresult CopyMUTF7toUTF16(const nsACString& aSrc, nsAString& aDest) {

Просмотреть файл

@ -2166,15 +2166,15 @@ NS_IMETHODIMP nsImapService::RenameLeaf(nsIMsgFolder* srcFolder,
urlSpec.Append(cStrFolderName);
}
NS_ConvertUTF16toUTF8 utfNewName(newLeafName);
if (!NS_IsAscii(utfNewName.get())) {
// Convert to MUTF-7 if UTF8=ACCEPT not enabled by server.
bool utf8AcceptEnabled;
nsCOMPtr<nsIMsgImapMailFolder> imapFolder =
do_QueryInterface(srcFolder);
rv = imapFolder->GetShouldUseUtf8FolderName(&utf8AcceptEnabled);
NS_ENSURE_SUCCESS(rv, rv);
if (!utf8AcceptEnabled) CopyUTF16toMUTF7(newLeafName, utfNewName);
nsAutoCString utfNewName;
bool utf8AcceptEnabled;
nsCOMPtr<nsIMsgImapMailFolder> imapFolder = do_QueryInterface(srcFolder);
rv = imapFolder->GetShouldUseUtf8FolderName(&utf8AcceptEnabled);
NS_ENSURE_SUCCESS(rv, rv);
if (utf8AcceptEnabled) {
CopyUTF16toUTF8(newLeafName, utfNewName);
} else {
CopyUTF16toMUTF7(newLeafName, utfNewName);
}
nsCString escapedNewName;
MsgEscapeString(utfNewName, nsINetUtil::ESCAPE_URL_PATH, escapedNewName);
@ -2222,14 +2222,15 @@ NS_IMETHODIMP nsImapService::CreateFolder(nsIMsgFolder* parent,
urlSpec.Append(hierarchyDelimiter);
}
NS_ConvertUTF16toUTF8 utfNewName(newFolderName);
if (!NS_IsAscii(utfNewName.get())) {
// Convert to MUTF-7 if UTF8=ACCEPT not enabled by server.
bool utf8AcceptEnabled;
nsCOMPtr<nsIMsgImapMailFolder> imapFolder = do_QueryInterface(parent);
rv = imapFolder->GetShouldUseUtf8FolderName(&utf8AcceptEnabled);
NS_ENSURE_SUCCESS(rv, rv);
if (!utf8AcceptEnabled) CopyUTF16toMUTF7(newFolderName, utfNewName);
nsAutoCString utfNewName;
bool utf8AcceptEnabled;
nsCOMPtr<nsIMsgImapMailFolder> imapFolder = do_QueryInterface(parent);
rv = imapFolder->GetShouldUseUtf8FolderName(&utf8AcceptEnabled);
NS_ENSURE_SUCCESS(rv, rv);
if (utf8AcceptEnabled) {
CopyUTF16toUTF8(newFolderName, utfNewName);
} else {
CopyUTF16toMUTF7(newFolderName, utfNewName);
}
nsCString escapedFolderName;
MsgEscapeString(utfNewName, nsINetUtil::ESCAPE_URL_PATH,