CFPropertyListRef CopyPListFromFile(nsILocalFile* aPListFile) { PRBool exists; aPListFile->Exists(&exists); nsCAutoString filePath; aPListFile->GetNativePath(filePath); if (!exists) return nsnull; nsCOMPtr<nsILocalFileMac> macFile(do_QueryInterface(aPListFile)); CFURLRef urlRef; macFile->GetCFURL(&urlRef); CFDataRef resourceData; SInt32 errorCode; Boolean status = ::CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, urlRef, &resourceData, NULL, NULL, &errorCode); if (!status) return nsnull; CFPropertyListRef result = ::CFPropertyListCreateFromXMLData(kCFAllocatorDefault, resourceData, kCFPropertyListImmutable, NULL); ::CFRelease(resourceData); ::CFRelease(urlRef); return result; }
CFPropertyListRef CopyPListFromFile(nsILocalFile* aPListFile) { bool exists; aPListFile->Exists(&exists); if (!exists) return nsnull; nsCAutoString filePath; aPListFile->GetNativePath(filePath); nsCOMPtr<nsILocalFileMac> macFile(do_QueryInterface(aPListFile)); CFURLRef urlRef; macFile->GetCFURL(&urlRef); // It is possible for CFURLCreateDataAndPropertiesFromResource to allocate resource // data and then return a failure so be careful to check both and clean up properly. SInt32 errorCode; CFDataRef resourceData = NULL; Boolean dataSuccess = ::CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, urlRef, &resourceData, NULL, NULL, &errorCode); CFPropertyListRef propertyList = NULL; if (resourceData) { if (dataSuccess) { propertyList = ::CFPropertyListCreateFromXMLData(kCFAllocatorDefault, resourceData, kCFPropertyListImmutable, NULL); } ::CFRelease(resourceData); } ::CFRelease(urlRef); return propertyList; }
nsresult nsMsgAttachmentHandler::SnarfAttachment(nsMsgCompFields *compFields) { NS_ASSERTION (! m_done, "Already done"); if (!mURL) return SnarfMsgAttachment(compFields); mCompFields = compFields; // First, get as file spec and create the stream for the // temp file where we will save this data nsCOMPtr <nsIFile> tmpFile; nsresult rv = nsMsgCreateTempFile("nsmail.tmp", getter_AddRefs(tmpFile)); NS_ENSURE_SUCCESS(rv, rv); mTmpFile = do_QueryInterface(tmpFile); mDeleteFile = true; rv = MsgNewBufferedFileOutputStream(getter_AddRefs(mOutFile), mTmpFile, -1, 00600); if (NS_FAILED(rv) || !mOutFile) { if (m_mime_delivery_state) { nsCOMPtr<nsIMsgSendReport> sendReport; m_mime_delivery_state->GetSendReport(getter_AddRefs(sendReport)); if (sendReport) { nsAutoString error_msg; nsMsgBuildMessageWithTmpFile(mTmpFile, error_msg); sendReport->SetMessage(nsIMsgSendReport::process_Current, error_msg.get(), false); } } mTmpFile->Remove(false); mTmpFile = nsnull; return NS_MSG_UNABLE_TO_OPEN_TMP_FILE; } nsCString sourceURISpec; mURL->GetSpec(sourceURISpec); #ifdef XP_MACOSX if (!m_bogus_attachment && StringBeginsWith(sourceURISpec, NS_LITERAL_CSTRING("file://"))) { // Unescape the path (i.e. un-URLify it) before making a FSSpec nsCAutoString filePath; filePath.Adopt(nsMsgGetLocalFileFromURL(sourceURISpec.get())); nsCAutoString unescapedFilePath; MsgUnescapeString(filePath, 0, unescapedFilePath); nsCOMPtr<nsILocalFile> sourceFile; NS_NewNativeLocalFile(unescapedFilePath, true, getter_AddRefs(sourceFile)); if (!sourceFile) return NS_ERROR_FAILURE; // check if it is a bundle. if it is, we'll zip it. // if not, we'll apple encode it (applesingle or appledouble) nsCOMPtr<nsILocalFileMac> macFile(do_QueryInterface(sourceFile)); bool isPackage; macFile->IsPackage(&isPackage); if (isPackage) rv = ConvertToZipFile(macFile); else rv = ConvertToAppleEncoding(sourceURISpec, unescapedFilePath, macFile); NS_ENSURE_SUCCESS(rv, rv); } #endif /* XP_MACOSX */ // // Ok, here we are, we need to fire the URL off and get the data // in the temp file // // Create a fetcher for the URL attachment... nsCOMPtr<nsIURLFetcher> fetcher = do_CreateInstance(NS_URLFETCHER_CONTRACTID, &rv); if (NS_FAILED(rv) || !fetcher) { if (NS_SUCCEEDED(rv)) return NS_ERROR_UNEXPECTED; else return rv; } return fetcher->FireURLRequest(mURL, mTmpFile, mOutFile, FetcherURLDoneCallback, this); }