bug 229872 : non-ASCII file names don't show up in the attachment list (r=bienvenu, sr=mscott)

This commit is contained in:
jshin%mailaps.org 2004-02-10 06:08:13 +00:00
Родитель f6dd17228d
Коммит 3299bfb574
1 изменённых файлов: 37 добавлений и 44 удалений

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

@ -118,9 +118,6 @@
#include "plbase64.h"
#include "nsIUTF8ConverterService.h"
#include "nsUConvCID.h"
#ifdef XP_MACOSX
#include "nsIUnicodeNormalizer.h"
#endif
// Defines....
static NS_DEFINE_CID(kDateTimeFormatCID, NS_DATETIMEFORMAT_CID);
@ -3586,59 +3583,55 @@ nsresult nsMsgCompose::NotifyStateListeners(TStateListenerNotification aNotifica
return NS_OK;
}
nsresult nsMsgCompose::AttachmentPrettyName(const char* url, const char* charset, nsAString& _retval)
nsresult nsMsgCompose::AttachmentPrettyName(const char* scheme, const char* charset, nsACString& _retval)
{
nsresult rv;
nsCAutoString unescapedURL;
nsCOMPtr<nsIUTF8ConverterService> utf8Cvt (do_GetService(NS_UTF8CONVERTERSERVICE_CONTRACTID));
nsCOMPtr<nsIUTF8ConverterService> utf8Cvt =
do_GetService(NS_UTF8CONVERTERSERVICE_CONTRACTID);
NS_ENSURE_TRUE(utf8Cvt, NS_ERROR_UNEXPECTED);
if (PL_strncasestr(url, "file:", 5))
nsCAutoString utf8Scheme;
if (PL_strncasestr(scheme, "file:", 5))
{
rv = utf8Cvt->ConvertURISpecToUTF8(nsDependentCString(url),
nsMsgI18NFileSystemCharset(), unescapedURL);
// first try, filesystem character encoding
rv = utf8Cvt->ConvertURISpecToUTF8(nsDependentCString(scheme),
nsMsgI18NFileSystemCharset(), utf8Scheme);
if (NS_FAILED(rv))
{
rv = utf8Cvt->ConvertURISpecToUTF8(nsDependentCString(url),
(!charset || !*charset) ? "UTF-8" : charset, unescapedURL);
if (NS_FAILED(rv)) {
NS_WARNING("URL unescaping/charset conversion failed.");
unescapedURL = url;
}
// try |charset| if it's set. otherwise, UTF-8.
rv = utf8Cvt->ConvertURISpecToUTF8(nsDependentCString(scheme),
(!charset || !*charset) ? "UTF-8" : charset, utf8Scheme);
NS_ENSURE_SUCCESS(rv, rv);
}
nsFileURL fileUrl(unescapedURL.get());
nsFileSpec fileSpec(fileUrl);
char* leafName = fileSpec.GetLeafName();
NS_ENSURE_TRUE(leafName && *leafName, NS_ERROR_UNEXPECTED);
#ifdef XP_MACOSX
nsAutoString decomposedName;
CopyUTF8toUTF16(leafName, decomposedName);
nsCOMPtr<nsIUnicodeNormalizer> normalizer (do_GetService(NS_UNICODE_NORMALIZER_CONTRACTID));
if (normalizer)
normalizer->NormalizeUnicodeNFC(decomposedName, _retval);
else
_retval = decomposedName;
#else
CopyUTF8toUTF16(leafName, _retval);
#endif
nsCRT::free(leafName);
return NS_OK;
nsCOMPtr<nsIURI> uri;
rv = NS_NewURI(getter_AddRefs(uri), utf8Scheme);
nsCOMPtr<nsIURL> url (do_QueryInterface(uri, &rv));
_retval.Truncate();
if (NS_SUCCEEDED(rv)) {
nsCAutoString leafName;
rv = url->GetFileName(leafName); // leafName is in UTF-8 (escaped).
if (NS_SUCCEEDED(rv))
NS_UnescapeURL(leafName.get(), leafName.Length(),
esc_SkipControl || esc_AlwaysCopy, _retval);
}
return rv;
}
rv = utf8Cvt->ConvertURISpecToUTF8(nsDependentCString(url),
(!charset || !*charset) ? "UTF-8" : charset, unescapedURL);
if (NS_FAILED(rv))
{
NS_WARNING("URL unescaping/charset conversion failed.");
unescapedURL = url;
}
// To work around a mysterious bug in VC++ 6.
const char* cset = (!charset || !*charset) ? "UTF-8" : charset;
rv = utf8Cvt->ConvertURISpecToUTF8(nsDependentCString(scheme),
cset, utf8Scheme);
NS_ENSURE_SUCCESS(rv, rv);
// Some ASCII characters still need to be escaped.
NS_UnescapeURL(utf8Scheme.get(), utf8Scheme.Length(),
esc_SkipControl || esc_AlwaysCopy, _retval);
if (PL_strncasestr(scheme, "http:", 5))
_retval.Cut(0, 7);
if (PL_strncasestr(unescapedURL.get(), "http:", 5))
unescapedURL.Cut(0, 7);
CopyUTF8toUTF16(unescapedURL, _retval);
return NS_OK;
}