Fix for bug 23109, 23331. Attachment file names are now converted to file system character set and we display only the file name in case of a file url. R=jefft

This commit is contained in:
ducarroz%netscape.com 2000-01-15 01:33:18 +00:00
parent a465fa6447
commit 8b94105da6
2 changed files with 47 additions and 0 deletions

View File

@ -116,6 +116,13 @@ interface nsIMsgCompose : nsISupports {
/* ... */
void CloseWindow();
/*
AttachmentPrettyName will return only the leafName if the it's a file URL.
It will also convert the filename to the right character set.
This UI utility function should probably go into it's own class
*/
wstring AttachmentPrettyName(in wstring url);
/* ... */
attribute nsIEditorShell editor;

View File

@ -50,6 +50,7 @@
#include "nsIHTMLEditor.h"
#include "nsIDOMSelection.h"
#include "nsIDOMNode.h"
#include "nsEscape.h"
// XXX temporary so we can use the current identity hack -alecf
#include "nsIMsgMailSession.h"
@ -1886,3 +1887,42 @@ nsresult nsMsgCompose::NotifyStateListeners(TStateListenerNotification aNotifica
return rv;
}
nsresult nsMsgCompose::AttachmentPrettyName(const PRUnichar* url, PRUnichar** _retval)
{
nsCAutoString unescapeULR = url;
nsUnescape(unescapeULR);
if (unescapeULR.IsEmpty())
{
*_retval = nsCRT::strdup(url);
return NS_OK;
}
if (PL_strncasestr(unescapeULR, "file:", 5))
{
nsFileURL fileUrl(url);
nsFileSpec fileSpec(fileUrl);
char * leafName = fileSpec.GetLeafName();
if (leafName && *leafName)
{
nsAutoString tempStr;
nsresult rv = ConvertToUnicode(msgCompFileSystemCharset(), leafName, tempStr);
if (NS_FAILED(rv))
tempStr = leafName;
*_retval = tempStr.ToNewUnicode();
nsCRT::free(leafName);
return NS_OK;
}
}
if (PL_strncasestr(unescapeULR, "http:", 5))
{
nsAutoString tempStr = &unescapeULR.mBuffer[7];
*_retval = tempStr.ToNewUnicode();
return NS_OK;
}
*_retval = nsCRT::strdup(url);
return NS_OK;
}