nsresult nsMsgMdnGenerator::CreateMdnMsg()
{
    DEBUG_MDN("nsMsgMdnGenerator::CreateMdnMsg");
    nsresult rv;

    nsCOMPtr<nsIFile> tmpFile;
    rv = GetSpecialDirectoryWithFileName(NS_OS_TEMP_DIR,
                                         "mdnmsg",
                                         getter_AddRefs(m_file));
    NS_ENSURE_SUCCESS(rv, rv);

    rv = m_file->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 00600);
    nsCOMPtr <nsILocalFile> localFile = do_QueryInterface(m_file);
    NS_ENSURE_SUCCESS(rv, rv);
    rv = NS_NewLocalFileOutputStream(getter_AddRefs(m_outputStream),
                                     localFile,
                                     PR_CREATE_FILE | PR_WRONLY | PR_TRUNCATE,
                                     0664);
    NS_ASSERTION(NS_SUCCEEDED(rv),"creating mdn: failed to output stream");
    if (NS_FAILED(rv))
        return NS_OK;

    rv = CreateFirstPart();
    if (NS_SUCCEEDED(rv))
    {
        rv = CreateSecondPart();
        if (NS_SUCCEEDED(rv))
            rv = CreateThirdPart();
    }

    if (m_outputStream)
    {
        m_outputStream->Flush();
        m_outputStream->Close();
    }
    if (NS_FAILED(rv))
        m_file->Remove(false);
    else
        rv = SendMdnMsg();

    return NS_OK;
}
Beispiel #2
0
nsresult nsMsgMdnGenerator::CreateMdnMsg()
{
    DEBUG_MDN("nsMsgMdnGenerator::CreateMdnMsg");
    nsresult rv;
    if (!m_autoSend)
    {
        nsCOMPtr<nsIPrompt> dialog;
        rv = m_window->GetPromptDialog(getter_AddRefs(dialog));
        if (NS_SUCCEEDED(rv))
        {
            nsString wishToSend;
            nsString ignoreRequest;
            nsString sendReceipt;
            PRInt32 buttonPressed = 0;
            rv = GetStringFromName(NS_LITERAL_STRING("MsgMdnWishToSend").get(),
                                   getter_Copies(wishToSend));
            NS_ENSURE_SUCCESS(rv, rv);
            rv = GetStringFromName(NS_LITERAL_STRING("MsgMdnIgnoreRequest").get(), getter_Copies(ignoreRequest));
            NS_ENSURE_SUCCESS(rv, rv);
            rv = GetStringFromName(NS_LITERAL_STRING("MsgMdnSendReceipt").get(), getter_Copies(sendReceipt));
            NS_ENSURE_SUCCESS(rv, rv);

            // Default the dialog to "Ignore Request".
            rv = dialog->ConfirmEx(nsnull, wishToSend.get(),
                                   (nsIPrompt::BUTTON_POS_1_DEFAULT) +
                                   (nsIPrompt::BUTTON_TITLE_IS_STRING * nsIPrompt::BUTTON_POS_0) +
                                   (nsIPrompt::BUTTON_TITLE_IS_STRING * nsIPrompt::BUTTON_POS_1),
                                   sendReceipt.get(), 
                                   ignoreRequest.get(), 
                                   nsnull, nsnull, nsnull, &buttonPressed);

            NS_ENSURE_SUCCESS(rv, rv);
            m_reallySendMdn = !buttonPressed; // "Send Receipt" is in position 0
        }
    }
    if (!m_reallySendMdn)
        return NS_OK;

    nsCOMPtr<nsIFile> tmpFile;
    rv = GetSpecialDirectoryWithFileName(NS_OS_TEMP_DIR,
                                         "mdnmsg",
                                         getter_AddRefs(m_file));
    NS_ENSURE_SUCCESS(rv, rv);

    rv = m_file->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 00600);
    nsCOMPtr <nsILocalFile> localFile = do_QueryInterface(m_file);
    NS_ENSURE_SUCCESS(rv, rv);
    rv = NS_NewLocalFileOutputStream(getter_AddRefs(m_outputStream),
                                     localFile,
                                     PR_CREATE_FILE | PR_WRONLY | PR_TRUNCATE,
                                     0664);
    NS_ASSERTION(NS_SUCCEEDED(rv),"creating mdn: failed to output stream");
    if (NS_FAILED(rv))
        return NS_OK;

    rv = CreateFirstPart();
    if (NS_SUCCEEDED(rv))
    {
        rv = CreateSecondPart();
        if (NS_SUCCEEDED(rv))
            rv = CreateThirdPart();
    }

    if (m_outputStream)
    {
        m_outputStream->Flush();
        m_outputStream->Close();
    }
    if (NS_FAILED(rv))
        m_file->Remove(PR_FALSE);
    else
        rv = SendMdnMsg();

    return NS_OK;
}