mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-02 20:20:00 +00:00
fix for bug 107708. Look at the attachment real name to determine if possible the content-type before looking at the url. R=varada, SR=sspitzer
This commit is contained in:
parent
347d1302d8
commit
b023fb727a
@ -74,7 +74,7 @@ interface nsIMsgAttachment : nsISupports {
|
||||
* contentType attribute
|
||||
*
|
||||
* @Specify the content-type of the attachment
|
||||
* @If ommitted, it will be determined base on either the url or the content of the file.
|
||||
* @If ommitted, it will be determined base on either the name, the url or the content of the file.
|
||||
*/
|
||||
attribute string contentType;
|
||||
|
||||
|
@ -1962,49 +1962,6 @@ GetFolderURIFromUserPrefs(nsMsgDeliverMode aMode,
|
||||
return uri;
|
||||
}
|
||||
|
||||
//
|
||||
// Find an extension in a URL
|
||||
char *
|
||||
nsMsgGetExtensionFromFileURL(nsString aUrl)
|
||||
{
|
||||
char *url = nsnull;
|
||||
char *rightDot = nsnull;
|
||||
char *rightSlash = nsnull;
|
||||
|
||||
if (aUrl.IsEmpty())
|
||||
return nsnull;
|
||||
|
||||
url = ToNewCString(aUrl);
|
||||
if (!url)
|
||||
goto ERROR_OUT;
|
||||
|
||||
rightDot = PL_strrchr(url, '.');
|
||||
if (!rightDot)
|
||||
goto ERROR_OUT;
|
||||
|
||||
rightSlash = PL_strrchr(url, '/');
|
||||
if (!rightSlash)
|
||||
rightSlash = PL_strrchr(url, '\\');
|
||||
|
||||
if (!rightSlash)
|
||||
goto ERROR_OUT;
|
||||
|
||||
if (rightDot > rightSlash)
|
||||
{
|
||||
if (rightDot+1 == '\0')
|
||||
goto ERROR_OUT;
|
||||
|
||||
char *retVal = PL_strdup(rightDot + 1);
|
||||
PR_FREEIF(url);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
ERROR_OUT:
|
||||
if (url)
|
||||
nsMemory::Free(url);
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
//
|
||||
// Convert an nsString buffer to plain text...
|
||||
//
|
||||
|
@ -134,7 +134,6 @@ char *nsMsgParseURLHost(const char *url);
|
||||
|
||||
char *GenerateFileNameFromURI(nsIURI *aURL);
|
||||
|
||||
char *nsMsgGetExtensionFromFileURL(nsString aUrl);
|
||||
char *GetFolderNameFromURLString(char *aUrl);
|
||||
char *nsMsgParseSubjectFromFile(nsFileSpec* fileSpec);
|
||||
|
||||
|
@ -2832,33 +2832,31 @@ nsMsgCompose::ProcessSignature(nsIMsgIdentity *identity, nsString *aMsgBody)
|
||||
// Once we get here, we need to figure out if we have the correct file
|
||||
// type for the editor.
|
||||
//
|
||||
nsFileURL sigFilePath(testSpec);
|
||||
char *fileExt = nsMsgGetExtensionFromFileURL(NS_ConvertASCIItoUCS2(NS_STATIC_CAST(const char*, sigFilePath)));
|
||||
|
||||
if ( (fileExt) && (*fileExt) )
|
||||
nsCOMPtr<nsIFileURL> fileUrl(do_CreateInstance(NS_STANDARDURL_CONTRACTID));
|
||||
if (fileUrl)
|
||||
{
|
||||
fileUrl->SetFilePath(sigNativePath);
|
||||
nsXPIDLCString fileExt;
|
||||
rv = fileUrl->GetFileExtension(getter_Copies(fileExt));
|
||||
if (NS_SUCCEEDED(rv) && !fileExt.IsEmpty())
|
||||
{
|
||||
// Now, most importantly, we need to figure out what the content type is for
|
||||
// this signature...if we can't, we assume text
|
||||
rv = NS_OK;
|
||||
char *sigContentType = nsnull;
|
||||
nsXPIDLCString sigContentType;
|
||||
nsCOMPtr<nsIMIMEService> mimeFinder (do_GetService(NS_MIMESERVICE_CONTRACTID, &rv));
|
||||
if (NS_SUCCEEDED(rv) && mimeFinder && fileExt)
|
||||
{
|
||||
mimeFinder->GetTypeFromExtension(fileExt, &(sigContentType));
|
||||
PR_FREEIF(fileExt);
|
||||
}
|
||||
if (NS_SUCCEEDED(rv) && mimeFinder)
|
||||
mimeFinder->GetTypeFromExtension(fileExt.get(), getter_Copies(sigContentType));
|
||||
|
||||
if (sigContentType)
|
||||
if (!sigContentType.IsEmpty())
|
||||
{
|
||||
imageSig = (!PL_strncasecmp(sigContentType, "image/", 6));
|
||||
imageSig = (!PL_strncasecmp(sigContentType.get(), "image/", 6));
|
||||
if (!imageSig)
|
||||
htmlSig = (!PL_strcasecmp(sigContentType, TEXT_HTML));
|
||||
htmlSig = (!PL_strcasecmp(sigContentType.get(), TEXT_HTML));
|
||||
}
|
||||
else
|
||||
htmlSig = ( (!PL_strcasecmp(fileExt, "HTM")) || (!PL_strcasecmp(fileExt, "HTML")) );
|
||||
|
||||
PR_FREEIF(fileExt);
|
||||
PR_FREEIF(sigContentType);
|
||||
htmlSig = ( (!PL_strcasecmp(fileExt.get(), "HTM")) || (!PL_strcasecmp(fileExt.get(), "HTML")) );
|
||||
}
|
||||
}
|
||||
|
||||
static const char htmlBreak[] = "<BR>";
|
||||
|
@ -94,6 +94,7 @@
|
||||
#include "nsILoadGroup.h"
|
||||
#include "nsMsgSendReport.h"
|
||||
#include "nsMsgSimulateError.h"
|
||||
#include "nsNetCID.h"
|
||||
|
||||
|
||||
// use these macros to define a class IID for our component. Our object currently
|
||||
@ -2119,11 +2120,31 @@ nsMsgComposeAndSend::AddCompFieldLocalAttachments()
|
||||
nsCOMPtr<nsIMIMEService> mimeFinder (do_GetService(NS_MIMESERVICE_CONTRACTID, &rv));
|
||||
if (NS_SUCCEEDED(rv) && mimeFinder)
|
||||
{
|
||||
char *fileExt = nsMsgGetExtensionFromFileURL(NS_ConvertASCIItoUCS2(url));
|
||||
if (fileExt)
|
||||
mimeFinder->GetTypeFromExtension(fileExt, &(m_attachments[newLoc].m_type));
|
||||
nsCOMPtr<nsIFileURL> fileUrl(do_CreateInstance(NS_STANDARDURL_CONTRACTID));
|
||||
nsXPIDLCString fileExt;
|
||||
if (fileUrl)
|
||||
{
|
||||
//First try using the real file name
|
||||
rv = fileUrl->SetFileName(m_attachments[newLoc].m_real_name);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
rv = fileUrl->GetFileExtension(getter_Copies(fileExt));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
mimeFinder->GetTypeFromExtension(fileExt.get(), &(m_attachments[newLoc].m_type));
|
||||
}
|
||||
|
||||
PR_FREEIF(fileExt);
|
||||
//Then try using the url if we still haven't figured out the content type
|
||||
if ((!m_attachments[newLoc].m_type) || (!*m_attachments[newLoc].m_type))
|
||||
{
|
||||
rv = fileUrl->SetSpec(url.get());
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
rv = fileUrl->GetFileExtension(getter_Copies(fileExt));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
mimeFinder->GetTypeFromExtension(fileExt.get(), &(m_attachments[newLoc].m_type));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user