From 33672e6f764b85f14d8b323523972aeb5cae0348 Mon Sep 17 00:00:00 2001 From: "jefft%netscape.com" Date: Thu, 7 Oct 1999 14:27:11 +0000 Subject: [PATCH] fixed bug 10801 -- [Featuure] Save Messages, bug 14794 - message sent from unsent folder display as raw message; we need to pay attention to where we want to save the message as template, if the message goes to the local mail folder we have to add the dummy envelope header plus the x mozilla status lines; when sending unsent messages we need to set from/sender information to pass the sanity check at the send time; reviewed by rhp --- mailnews/base/src/nsMessenger.cpp | 44 +++++++++++++++--------- mailnews/compose/src/nsMsgSendLater.cpp | 6 ++++ mailnews/imap/src/nsImapMailFolder.cpp | 23 +++++++++++++ mailnews/local/src/nsMailboxProtocol.cpp | 21 +++++++++-- mailnews/news/src/nsNNTPProtocol.cpp | 25 ++++++++++++++ 5 files changed, 100 insertions(+), 19 deletions(-) diff --git a/mailnews/base/src/nsMessenger.cpp b/mailnews/base/src/nsMessenger.cpp index ec8d8520727e..686378dc9cfb 100644 --- a/mailnews/base/src/nsMessenger.cpp +++ b/mailnews/base/src/nsMessenger.cpp @@ -668,24 +668,36 @@ nsMessenger::SaveAs(const char* url, PRBool asFile) } else { - // ** save as Template - nsSaveAsListener *aListener = new nsSaveAsListener(aSpec); - if (aListener) - { - rv = aListener->QueryInterface( - nsCOMTypeInfo::GetIID(), - getter_AddRefs(urlListener)); - if (NS_FAILED(rv)) + // ** save as Template + PRBool needDummyHeader = PR_TRUE; + char * templateUri = nsnull; + NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &rv); + if (NS_FAILED(rv)) goto done; + prefs->CopyCharPref("mail.default_templates_uri", &templateUri); + if (!templateUri || !*templateUri) + return NS_ERROR_FAILURE; + needDummyHeader = + PL_strcasestr(templateUri, "mailbox") != nsnull; + nsCRT::free(templateUri); + nsSaveAsListener *aListener = new nsSaveAsListener(aSpec); + if (aListener) { - delete aListener; - return rv; + rv = aListener->QueryInterface( + nsCOMTypeInfo::GetIID(), + getter_AddRefs(urlListener)); + if (NS_FAILED(rv)) + { + delete aListener; + return rv; + } + NS_ADDREF(aListener); + // nsUrlListenerManager uses nsVoidArray + // to keep trach of all listeners we have + // to manually add refs ourself + messageService->SaveMessageToDisk(url, aSpec, + needDummyHeader, + urlListener, nsnull); } - NS_ADDREF(aListener); // nsUrlListenerManager uses nsVoidArray - // to keep trach of all listeners we have - // to manually add refs ourself - messageService->SaveMessageToDisk(url, aSpec, PR_TRUE, - urlListener, nsnull); - } } } } diff --git a/mailnews/compose/src/nsMsgSendLater.cpp b/mailnews/compose/src/nsMsgSendLater.cpp index 4492ddf7e3dd..605a507ac1e5 100644 --- a/mailnews/compose/src/nsMsgSendLater.cpp +++ b/mailnews/compose/src/nsMsgSendLater.cpp @@ -473,7 +473,13 @@ nsCOMPtr pMsgSend = nsnull; // Since we have already parsed all of the headers, we are simply going to // set the composition fields and move on. // + nsString author; + mMessage->GetAuthor(&author); + nsMsgCompFields * fields = (nsMsgCompFields *)compFields.get(); + + fields->SetFrom(author.ToNewUnicode()); + if (m_to) fields->SetTo(m_to); diff --git a/mailnews/imap/src/nsImapMailFolder.cpp b/mailnews/imap/src/nsImapMailFolder.cpp index 8dd9ca29db81..86849f68a566 100644 --- a/mailnews/imap/src/nsImapMailFolder.cpp +++ b/mailnews/imap/src/nsImapMailFolder.cpp @@ -2259,6 +2259,29 @@ nsImapMailFolder::SetupMsgWriteStream(const char * aNativeString, PRBool addDumm nsCOMPtr supports; NS_NewIOFileStream(getter_AddRefs(supports), fileSpec, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 00700); m_tempMessageStream = do_QueryInterface(supports); + if (m_tempMessageStream && addDummyEnvelope) + { + nsCString result; + char *ct; + PRUint32 writeCount; + time_t now = time ((time_t*) 0); + ct = ctime(&now); + ct[24] = 0; + result = "From - "; + result += ct; + result += MSG_LINEBREAK; + + m_tempMessageStream->Write(result.GetBuffer(), result.Length(), + &writeCount); + result = "X-Mozilla-Status: 0001"; + result += MSG_LINEBREAK; + m_tempMessageStream->Write(result.GetBuffer(), result.Length(), + &writeCount); + result = "X-Mozilla-Status2: 00000000"; + result += MSG_LINEBREAK; + m_tempMessageStream->Write(result.GetBuffer(), result.Length(), + &writeCount); + } return NS_OK; } diff --git a/mailnews/local/src/nsMailboxProtocol.cpp b/mailnews/local/src/nsMailboxProtocol.cpp index 8eebb1303c1b..56b33aceaea8 100644 --- a/mailnews/local/src/nsMailboxProtocol.cpp +++ b/mailnews/local/src/nsMailboxProtocol.cpp @@ -259,10 +259,25 @@ nsresult nsMailboxProtocol::LoadUrl(nsIURI * aURL, nsISupports * aConsumer) // create a temp file to write the message into. We need to do this because // we don't have pluggable converters yet. We want to let mkfile do the work of // converting the message from RFC-822 to HTML before displaying it... - if (m_mailboxAction == nsIMailboxUrl::ActionSaveMessageToDisk) - SetFlag(MAILBOX_MSG_PARSE_FIRST_LINE); + if (m_mailboxAction == + nsIMailboxUrl::ActionSaveMessageToDisk) + { + nsCOMPtr messageUrl = + do_QueryInterface(aURL, &rv); + if (NS_SUCCEEDED(rv)) + { + PRBool addDummyEnvelope = PR_FALSE; + messageUrl->GetAddDummyEnvelope(&addDummyEnvelope); + if (addDummyEnvelope) + SetFlag(MAILBOX_MSG_PARSE_FIRST_LINE); + else + ClearFlag(MAILBOX_MSG_PARSE_FIRST_LINE); + } + } else - ClearFlag(MAILBOX_MSG_PARSE_FIRST_LINE); + { + ClearFlag(MAILBOX_MSG_PARSE_FIRST_LINE); + } m_nextState = MAILBOX_READ_MESSAGE; break; diff --git a/mailnews/news/src/nsNNTPProtocol.cpp b/mailnews/news/src/nsNNTPProtocol.cpp index 6fb93b43ac2a..eb755466207f 100644 --- a/mailnews/news/src/nsNNTPProtocol.cpp +++ b/mailnews/news/src/nsNNTPProtocol.cpp @@ -2057,6 +2057,31 @@ PRInt32 nsNNTPProtocol::BeginArticle() NS_NewIOFileStream(getter_AddRefs(supports), fileSpec, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 00700); m_tempArticleStream = do_QueryInterface(supports); + PRBool needDummyHeaders = PR_FALSE; + msgurl->GetAddDummyEnvelope(&needDummyHeaders); + if (needDummyHeaders) + { + nsCString result; + char *ct; + PRUint32 writeCount; + time_t now = time ((time_t*) 0); + ct = ctime(&now); + ct[24] = 0; + result = "From - "; + result += ct; + result += MSG_LINEBREAK; + + m_tempArticleStream->Write(result.GetBuffer(), result.Length(), + &writeCount); + result = "X-Mozilla-Status: 0001"; + result += MSG_LINEBREAK; + m_tempArticleStream->Write(result.GetBuffer(), result.Length(), + &writeCount); + result = "X-Mozilla-Status2: 00000000"; + result += MSG_LINEBREAK; + m_tempArticleStream->Write(result.GetBuffer(), result.Length(), + &writeCount); + } } } m_nextState = NNTP_READ_ARTICLE;