From b739c9c7b5cdf56705049b9fd5e9d745b7c3d1e6 Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Sun, 29 Feb 2004 13:21:53 +0000 Subject: Decode RFC 2231 and RFC 2047 encoded filenames in content-disposition 2004-02-29 Christian Persch * embed/mozilla/EphyHeaderSniffer.cpp: (PerformSave): Decode RFC 2231 and RFC 2047 encoded filenames in content-disposition headers. Ported from mozilla Camino, see http://bugzilla.mozilla.org/show_bug.cgi?id=233798 . --- embed/mozilla/EphyHeaderSniffer.cpp | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'embed') diff --git a/embed/mozilla/EphyHeaderSniffer.cpp b/embed/mozilla/EphyHeaderSniffer.cpp index c9240c1b3..35af9763f 100644 --- a/embed/mozilla/EphyHeaderSniffer.cpp +++ b/embed/mozilla/EphyHeaderSniffer.cpp @@ -67,6 +67,9 @@ #include "nsIMIMEInfo.h" #include "nsIDOMHTMLDocument.h" #include "nsIDownload.h" +#if MOZILLA_SNAPSHOT > 10 +#include "nsIMIMEHeaderParam.h" +#endif #include #include @@ -242,6 +245,36 @@ nsresult EphyHeaderSniffer::PerformSave (nsIURI* inOriginalURI) if (defaultFileName.IsEmpty() && !mContentDisposition.IsEmpty()) { /* 1 Use the HTTP header suggestion. */ +#if MOZILLA_SNAPSHOT > 10 + nsCOMPtr mimehdrpar = + do_GetService("@mozilla.org/network/mime-hdrparam;1"); + + if (mimehdrpar) + {g_print ("Using nsIMIMEHeaderParam!\n"); + nsCAutoString fallbackCharset; + if (mURL) + { + mURL->GetOriginCharset(fallbackCharset); + } + + nsAutoString fileName; + + rv = mimehdrpar->GetParameter (mContentDisposition, "filename", + fallbackCharset, PR_TRUE, nsnull, + fileName); + if (NS_FAILED(rv) || fileName.IsEmpty()) + { + rv = mimehdrpar->GetParameter (mContentDisposition, "name", + fallbackCharset, PR_TRUE, nsnull, + fileName); + } + + if (NS_SUCCEEDED(rv) && !fileName.IsEmpty()) + { + defaultFileName = fileName; + } + } +#else PRInt32 index = mContentDisposition.Find("filename="); if (index >= 0) { @@ -251,6 +284,7 @@ nsresult EphyHeaderSniffer::PerformSave (nsIURI* inOriginalURI) mContentDisposition.Right(filename, mContentDisposition.Length() - index); defaultFileName = NS_ConvertUTF8toUCS2(filename); } +#endif } if (defaultFileName.IsEmpty()) @@ -262,6 +296,9 @@ nsresult EphyHeaderSniffer::PerformSave (nsIURI* inOriginalURI) { nsCAutoString fileNameCString; url->GetFileName(fileNameCString); + /* FIXME: when we can depend on moz >= 1.5, use + * CopyUTF8toUTF16 instead + */ defaultFileName = NS_ConvertUTF8toUCS2(fileNameCString); } } @@ -282,6 +319,9 @@ nsresult EphyHeaderSniffer::PerformSave (nsIURI* inOriginalURI) /* 4 Use the host. */ nsCAutoString hostName; mURL->GetHost(hostName); + /* FIXME: when we can depend on moz >= 1.5, use + * CopyUTF8toUTF16 instead + */ defaultFileName = NS_ConvertUTF8toUCS2(hostName); } -- cgit v1.2.3