bug 227547 : convert Mac OS X file names in NFD (decomposed Unicode) to NFC (composed filename) before sending out to the world. mailnews part (r=bienvenu, sr=mscott)

This commit is contained in:
jshin%mailaps.org 2003-12-22 06:26:06 +00:00
parent 7c6f47247d
commit a3596ed940
5 changed files with 50 additions and 25 deletions

View File

@ -46,7 +46,7 @@ interface nsIMsgAttachment : nsISupports {
* @Attachment real name, will be sent with the attachment's header.
* @If no name has been provided, a name will be generated using the url.
*/
attribute wstring name;
attribute AString name;
/**
* url attribute

View File

@ -39,6 +39,9 @@
#include "nsILocalFile.h"
#include "nsReadableUtils.h"
#include "nsNetUtil.h"
#ifdef XP_MAC
#include "nsIUnicodeNormalizer.h"
#endif
NS_IMPL_ISUPPORTS1(nsMsgAttachment, nsIMsgAttachment)
@ -54,19 +57,30 @@ nsMsgAttachment::~nsMsgAttachment()
}
/* attribute wstring name; */
NS_IMETHODIMP nsMsgAttachment::GetName(PRUnichar * *aName)
NS_IMETHODIMP nsMsgAttachment::GetName(nsAString & aName)
{
NS_ENSURE_ARG_POINTER(aName);
*aName = ToNewUnicode(mName);
return (*aName ? NS_OK : NS_ERROR_OUT_OF_MEMORY);
}
NS_IMETHODIMP nsMsgAttachment::SetName(const PRUnichar * aName)
{
mName = aName;
aName = mName;
return NS_OK;
}
NS_IMETHODIMP nsMsgAttachment::SetName(const nsAString & aName)
{
#ifndef XP_MAC
mName = aName;
#else
// Mac OS X filesystem uses NFD. When exporting names to the 'world',
// we have to convert NFD (decomposed Unicode) to NFC (precomopsed Unicode)
// because most other platforms expect that.
nsCOMPtr<nsIUnicodeNormalizer> normalizer (do_GetService(NS_UNICODE_NORMALIZER_CONTRACTID));
if (normalizer)
normalizer->NormalizeUnicodeNFC(aName, mName);
else
mName = aName;
#endif
return NS_OK;
}
/* attribute string url; */
NS_IMETHODIMP nsMsgAttachment::GetUrl(char * *aUrl)
{

View File

@ -118,6 +118,9 @@
#include "plbase64.h"
#include "nsIUTF8ConverterService.h"
#include "nsUConvCID.h"
#ifdef XP_MAC
#include "nsIUnicodeNormalizer.h"
#endif
// Defines....
static NS_DEFINE_CID(kDateTimeFormatCID, NS_DATETIMEFORMAT_CID);
@ -873,13 +876,11 @@ nsresult nsMsgCompose::_SendMsg(MSG_DeliverMode deliverMode, nsIMsgIdentity *ide
attachmentsArray->QueryElementAt(i, NS_GET_IID(nsIMsgAttachment), getter_AddRefs(element));
if (element)
{
nsXPIDLString name;
nsAutoString name;
nsXPIDLCString url;
nsXPIDLCString nameCStr;
element->GetName(getter_Copies(name));
nameCStr.Adopt(ToNewCString(name));
element->GetName(name);
element->GetUrl(getter_Copies(url));
printf("Attachment %d: %s - %s\n",i + 1, nameCStr.get(), url.get());
printf("Attachment %d: %s - %s\n",i + 1, NS_ConvertUTF16toUTF8(name).get(), url.get());
}
}
}
@ -1103,11 +1104,11 @@ NS_IMETHODIMP nsMsgCompose::SendMsg(MSG_DeliverMode deliverMode, nsIMsgIdentity
userid.Truncate(index);
if (userid.IsEmpty())
attachment->SetName(NS_LITERAL_STRING("vcard.vcf").get());
attachment->SetName(NS_LITERAL_STRING("vcard.vcf"));
else
{
userid.Append(NS_LITERAL_CSTRING(".vcf"));
attachment->SetName(NS_ConvertASCIItoUCS2(userid).get());
attachment->SetName(NS_ConvertASCIItoUCS2(userid));
}
attachment->SetUrl(vCardUrl.get());
@ -1679,7 +1680,7 @@ nsresult nsMsgCompose::CreateMessage(const char * originalMsgURI,
nsCOMPtr<nsIMsgAttachment> attachment = do_CreateInstance(NS_MSGATTACHMENT_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv) && attachment)
{
attachment->SetName(subject.get());
attachment->SetName(subject);
attachment->SetUrl(uri);
m_compFields->AddAttachment(attachment);
}
@ -3629,7 +3630,17 @@ nsresult nsMsgCompose::AttachmentPrettyName(const char* url, const char* charset
nsFileSpec fileSpec(fileUrl);
char* leafName = fileSpec.GetLeafName();
NS_ENSURE_TRUE(leafName && *leafName, NS_ERROR_UNEXPECTED);
CopyUTF8toUTF16(nsDependentCString(leafName), _retval);
#ifdef XP_MAC
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;
}

View File

@ -2282,8 +2282,8 @@ nsMsgComposeAndSend::AddCompFieldLocalAttachments()
m_attachments[newLoc].mDeleteFile = PR_FALSE;
if (m_attachments[newLoc].mURL)
{
nsXPIDLString proposedName;
element->GetName(getter_Copies(proposedName));
nsAutoString proposedName;
element->GetName(proposedName);
msg_pick_real_name(&m_attachments[newLoc], proposedName.get(), mCompFields->GetCharacterSet());
}
@ -2449,9 +2449,9 @@ nsMsgComposeAndSend::AddCompFieldRemoteAttachments(PRUint32 aStartLocation,
if (do_add_attachment)
{
nsXPIDLString proposedName;
element->GetName(getter_Copies(proposedName));
msg_pick_real_name(&m_attachments[newLoc], proposedName, mCompFields->GetCharacterSet());
nsAutoString proposedName;
element->GetName(proposedName);
msg_pick_real_name(&m_attachments[newLoc], proposedName.get(), mCompFields->GetCharacterSet());
++newLoc;
}
}

View File

@ -233,7 +233,7 @@ CreateTheComposeWindow(nsIMsgCompFields * compFields,
rv = ConvertToUnicode(msgCompHeaderInternalCharset(), curAttachment->real_name, nameStr);
if (NS_FAILED(rv))
nameStr.AssignWithConversion(curAttachment->real_name);
attachment->SetName(nameStr.get());
attachment->SetName(nameStr);
attachment->SetUrl(spec.get());
attachment->SetTemporary(PR_TRUE);
attachment->SetContentType(curAttachment->real_type);