nsMsgSendPart::nsMsgSendPart(nsIMsgSend* state, const char *part_charset) { m_state = nsnull; PL_strncpy(m_charset_name, (part_charset ? part_charset : "us-ascii"), sizeof(m_charset_name)-1); m_charset_name[sizeof(m_charset_name)-1] = '\0'; m_children = nsnull; m_numchildren = 0; SetMimeDeliveryState(state); m_parent = nsnull; m_filespec = nsnull; m_buffer = nsnull; m_type = nsnull; m_other = nsnull; m_strip_sensitive_headers = PR_FALSE; m_encoder_data = nsnull; m_firstBlock = PR_FALSE; m_needIntlConversion = PR_FALSE; m_mainpart = PR_FALSE; m_just_hit_CR = PR_FALSE; }
nsMsgSendPart::nsMsgSendPart(nsIMsgSend* state, const char *part_charset) { PL_strncpy(m_charset_name, (part_charset ? part_charset : "us-ascii"), sizeof(m_charset_name)-1); m_charset_name[sizeof(m_charset_name)-1] = '\0'; m_children = nsnull; m_numchildren = 0; // if we're not added as a child, the default part number will be "1". m_partNum = "1"; SetMimeDeliveryState(state); m_parent = nsnull; m_buffer = nsnull; m_type = nsnull; m_other = nsnull; m_strip_sensitive_headers = false; m_encoder_data = nsnull; m_firstBlock = false; m_needIntlConversion = false; m_mainpart = false; m_just_hit_CR = false; }
nsresult nsMsgAttachmentHandler::UrlExit(nsresult status, const PRUnichar* aMsg) { NS_ASSERTION(m_mime_delivery_state != nsnull, "not-null m_mime_delivery_state"); // Close the file, but don't delete the disk file (or the file spec.) if (mOutFile) { mOutFile->Close(); mOutFile = nsnull; } // this silliness is because Windows nsILocalFile caches its file size // so if an output stream writes to it, it will still return the original // cached size. if (mTmpFile) { nsCOMPtr <nsIFile> tmpFile; mTmpFile->Clone(getter_AddRefs(tmpFile)); mTmpFile = do_QueryInterface(tmpFile); } mRequest = nsnull; // First things first, we are now going to see if this is an HTML // Doc and if it is, we need to see if we can determine the charset // for this part by sniffing the HTML file. // This is needed only when the charset is not set already. // (e.g. a charset may be specified in HTTP header) // if (!m_type.IsEmpty() && m_charset.IsEmpty() && m_type.LowerCaseEqualsLiteral(TEXT_HTML)) m_charset = nsMsgI18NParseMetaCharset(mTmpFile); nsresult mimeDeliveryStatus; m_mime_delivery_state->GetStatus(&mimeDeliveryStatus); if (mimeDeliveryStatus == NS_ERROR_ABORT) status = NS_ERROR_ABORT; if (NS_FAILED(status) && status != NS_ERROR_ABORT && NS_SUCCEEDED(mimeDeliveryStatus)) { // At this point, we should probably ask a question to the user // if we should continue without this attachment. // bool keepOnGoing = true; nsCString turl; nsString msg; PRUnichar *printfString = nsnull; nsresult rv; nsCOMPtr<nsIStringBundleService> bundleService(do_GetService("@mozilla.org/intl/stringbundle;1", &rv)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIStringBundle> bundle; rv = bundleService->CreateBundle("chrome://messenger/locale/messengercompose/composeMsgs.properties", getter_AddRefs(bundle)); NS_ENSURE_SUCCESS(rv, rv); nsMsgDeliverMode mode = nsIMsgSend::nsMsgDeliverNow; m_mime_delivery_state->GetDeliveryMode(&mode); if (mode == nsIMsgSend::nsMsgSaveAsDraft || mode == nsIMsgSend::nsMsgSaveAsTemplate) bundle->GetStringFromID(NS_MSG_FAILURE_ON_OBJ_EMBED_WHILE_SAVING, getter_Copies(msg)); else bundle->GetStringFromID(NS_MSG_FAILURE_ON_OBJ_EMBED_WHILE_SENDING, getter_Copies(msg)); if (!m_realName.IsEmpty()) printfString = nsTextFormatter::smprintf(msg.get(), m_realName.get()); else if (NS_SUCCEEDED(mURL->GetSpec(turl)) && !turl.IsEmpty()) { nsCAutoString unescapedUrl; MsgUnescapeString(turl, 0, unescapedUrl); if (unescapedUrl.IsEmpty()) printfString = nsTextFormatter::smprintf(msg.get(), turl.get()); else printfString = nsTextFormatter::smprintf(msg.get(), unescapedUrl.get()); } else printfString = nsTextFormatter::smprintf(msg.get(), "?"); nsCOMPtr<nsIPrompt> aPrompt; if (m_mime_delivery_state) m_mime_delivery_state->GetDefaultPrompt(getter_AddRefs(aPrompt)); nsMsgAskBooleanQuestionByString(aPrompt, printfString, &keepOnGoing); PR_FREEIF(printfString); if (keepOnGoing) { status = 0; m_bogus_attachment = true; //That will cause this attachment to be ignored. } else { status = NS_ERROR_ABORT; m_mime_delivery_state->SetStatus(status); nsresult ignoreMe; m_mime_delivery_state->Fail(status, nsnull, &ignoreMe); m_mime_delivery_state->NotifyListenerOnStopSending(nsnull, status, 0, nsnull); SetMimeDeliveryState(nsnull); return status; } } m_done = true; // // Ok, now that we have the file here on disk, we need to see if there was // a need to do conversion to plain text...if so, the magic happens here, // otherwise, just move on to other attachments... // if (NS_SUCCEEDED(status) && !m_type.LowerCaseEqualsLiteral(TEXT_PLAIN) && m_desiredType.LowerCaseEqualsLiteral(TEXT_PLAIN)) { // // Conversion to plain text desired. // PRInt32 width = 72; nsCOMPtr<nsIPrefBranch> pPrefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); if (pPrefBranch) pPrefBranch->GetIntPref("mailnews.wraplength", &width); // Let sanity reign! if (width == 0) width = 72; else if (width < 10) width = 10; else if (width > 30000) width = 30000; // // Now use the converter service here to do the right // thing and convert this data to plain text for us! // nsAutoString conData; if (NS_SUCCEEDED(LoadDataFromFile(mTmpFile, conData, true))) { if (NS_SUCCEEDED(ConvertBufToPlainText(conData, UseFormatFlowed(m_charset.get())))) { if (mDeleteFile) mTmpFile->Remove(false); nsCOMPtr<nsIOutputStream> outputStream; nsresult rv = NS_NewLocalFileOutputStream(getter_AddRefs(outputStream), mTmpFile, PR_WRONLY | PR_CREATE_FILE, 00600); if (NS_SUCCEEDED(rv)) { nsCAutoString tData; if (NS_FAILED(ConvertFromUnicode(m_charset.get(), conData, tData))) LossyCopyUTF16toASCII(conData, tData); if (!tData.IsEmpty()) { PRUint32 bytesWritten; (void) outputStream->Write(tData.get(), tData.Length(), &bytesWritten); } outputStream->Close(); // this silliness is because Windows nsILocalFile caches its file size // so if an output stream writes to it, it will still return the original // cached size. if (mTmpFile) { nsCOMPtr <nsIFile> tmpFile; mTmpFile->Clone(getter_AddRefs(tmpFile)); mTmpFile = do_QueryInterface(tmpFile); } } } } m_type = m_desiredType; m_desiredType.Truncate(); m_encoding.Truncate(); } PRUint32 pendingAttachmentCount = 0; m_mime_delivery_state->GetPendingAttachmentCount(&pendingAttachmentCount); NS_ASSERTION (pendingAttachmentCount > 0, "no more pending attachment"); m_mime_delivery_state->SetPendingAttachmentCount(pendingAttachmentCount - 1); bool processAttachmentsSynchronously = false; m_mime_delivery_state->GetProcessAttachmentsSynchronously(&processAttachmentsSynchronously); if (NS_SUCCEEDED(status) && processAttachmentsSynchronously) { /* Find the next attachment which has not yet been loaded, if any, and start it going. */ PRUint32 i; nsMsgAttachmentHandler *next = 0; nsMsgAttachmentHandler *attachments = nsnull; PRUint32 attachmentCount = 0; m_mime_delivery_state->GetAttachmentCount(&attachmentCount); if (attachmentCount) m_mime_delivery_state->GetAttachmentHandlers(&attachments); for (i = 0; i < attachmentCount; i++) { if (!attachments[i].m_done) { next = &attachments[i]; // // rhp: We need to get a little more understanding to failed URL // requests. So, at this point if most of next is NULL, then we // should just mark it fetched and move on! We probably ignored // this earlier on in the send process. // if ( (!next->mURL) && (next->m_uri.IsEmpty()) ) { attachments[i].m_done = true; m_mime_delivery_state->GetPendingAttachmentCount(&pendingAttachmentCount); m_mime_delivery_state->SetPendingAttachmentCount(pendingAttachmentCount - 1); next->mPartUserOmissionOverride = true; next = nsnull; continue; } break; } } if (next) { int status = next->SnarfAttachment(mCompFields); if (NS_FAILED(status)) { nsresult ignoreMe; m_mime_delivery_state->Fail(status, nsnull, &ignoreMe); m_mime_delivery_state->NotifyListenerOnStopSending(nsnull, status, 0, nsnull); SetMimeDeliveryState(nsnull); return NS_ERROR_UNEXPECTED; } } } m_mime_delivery_state->GetPendingAttachmentCount(&pendingAttachmentCount); if (pendingAttachmentCount == 0) { // If this is the last attachment, then either complete the // delivery (if successful) or report the error by calling // the exit routine and terminating the delivery. if (NS_FAILED(status)) { nsresult ignoreMe; m_mime_delivery_state->Fail(status, aMsg, &ignoreMe); m_mime_delivery_state->NotifyListenerOnStopSending(nsnull, status, aMsg, nsnull); SetMimeDeliveryState(nsnull); return NS_ERROR_UNEXPECTED; } else { status = m_mime_delivery_state->GatherMimeAttachments (); if (NS_FAILED(status)) { nsresult ignoreMe; m_mime_delivery_state->Fail(status, aMsg, &ignoreMe); m_mime_delivery_state->NotifyListenerOnStopSending(nsnull, status, aMsg, nsnull); SetMimeDeliveryState(nsnull); return NS_ERROR_UNEXPECTED; } } } else { // If this is not the last attachment, but it got an error, // then report that error and continue if (NS_FAILED(status)) { nsresult ignoreMe; m_mime_delivery_state->Fail(status, aMsg, &ignoreMe); } } SetMimeDeliveryState(nsnull); return NS_OK; }