From 0d7587bd28bbd8df5334a98fc31b7cc107c05582 Mon Sep 17 00:00:00 2001 From: "jefft%netscape.com" Date: Wed, 29 Sep 1999 20:43:50 +0000 Subject: [PATCH] implemented forward messages as attachments & inline; a=mcafee --- mailnews/base/resources/content/widgetglue.js | 15 +- mailnews/base/src/nsMessenger.cpp | 218 ++++++++++++------ mailnews/compose/public/nsIMsgCompose.idl | 4 +- mailnews/compose/public/nsIMsgDraft.idl | 3 +- .../resources/content/MsgComposeCommands.js | 8 + .../compose/src/nsMsgAttachmentHandler.cpp | 60 ++++- mailnews/compose/src/nsMsgAttachmentHandler.h | 2 + mailnews/compose/src/nsMsgCreate.cpp | 13 +- mailnews/compose/src/nsMsgCreate.h | 5 +- mailnews/compose/src/nsMsgSend.cpp | 74 +++--- mailnews/compose/src/nsURLFetcher.cpp | 17 ++ mailnews/compose/src/nsURLFetcher.h | 5 +- mailnews/imap/src/nsImapUndoTxn.cpp | 2 + mailnews/local/src/nsLocalMailFolder.cpp | 2 + mailnews/local/src/nsLocalUndoTxn.cpp | 4 + .../mime/public/nsIMimeStreamConverter.idl | 5 + mailnews/mime/src/mimedrft.cpp | 42 +++- mailnews/mime/src/nsStreamConverter.cpp | 16 ++ mailnews/mime/src/nsStreamConverter.h | 9 +- 19 files changed, 378 insertions(+), 126 deletions(-) diff --git a/mailnews/base/resources/content/widgetglue.js b/mailnews/base/resources/content/widgetglue.js index e726a1dd6778..1a16e6760b76 100644 --- a/mailnews/base/resources/content/widgetglue.js +++ b/mailnews/base/resources/content/widgetglue.js @@ -264,19 +264,28 @@ function MsgReplyToAllMessage() function MsgForwardMessage() { dump("\nMsgForwardMessage from XUL\n"); - MsgForwardAsInline(); + var tree = GetThreadTree(); + //get the selected elements + var messageList = tree.selectedItems; + messenger.forwardMessages(messageList, -1); } function MsgForwardAsAttachment() { dump("\nMsgForwardAsAttachment from XUL\n"); - ComposeMessage(4, 0); + var tree = GetThreadTree(); + //get the selected elements + var messageList = tree.selectedItems; + messenger.forwardMessages(messageList, 0); } function MsgForwardAsInline() { dump("\nMsgForwardAsInline from XUL\n"); - ComposeMessage(3, 0); + var tree = GetThreadTree(); + //get the selected elements + var messageList = tree.selectedItems; + messenger.forwardMessages(messageList, 1); } function MsgCopyMessage(destFolder) diff --git a/mailnews/base/src/nsMessenger.cpp b/mailnews/base/src/nsMessenger.cpp index a9f252917dd7..6094378013ca 100644 --- a/mailnews/base/src/nsMessenger.cpp +++ b/mailnews/base/src/nsMessenger.cpp @@ -92,6 +92,10 @@ #include "nsEscape.h" #include "nsIStreamListener.h" #include "nsIStreamConverterService.h" +#include "nsIMsgCompose.h" +#include "nsIMsgCompFields.h" +#include "nsIMsgComposeService.h" +#include "nsMsgCompFieldsFact.h" static NS_DEFINE_CID(kIStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID); static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); @@ -109,6 +113,9 @@ static NS_DEFINE_CID(kPrintPreviewContextCID, NS_PRINT_PREVIEW_CONTEXT_CID); static NS_DEFINE_IID(kIPresContextIID, NS_IPRESCONTEXT_IID); static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID); static NS_DEFINE_CID(kMsgCopyServiceCID, NS_MSGCOPYSERVICE_CID); +static NS_DEFINE_CID(kMsgComposeServiceCID, NS_MSGCOMPOSESERVICE_CID); +static NS_DEFINE_CID(kMsgComposeCID, NS_MSGCOMPOSE_CID); +static NS_DEFINE_CID(kMsgCompFieldsCID, NS_MSGCOMPFIELDS_CID); #if defined(DEBUG_seth_) || defined(DEBUG_sspitzer_) || defined(DEBUG_jefft) #define DEBUG_MESSENGER @@ -794,7 +801,6 @@ NS_IMETHODIMP nsMessenger::CopyMessages(nsIRDFCompositeDataSource *database, nsIDOMXULElement *srcFolderElement, nsIDOMXULElement *dstFolderElement, nsIDOMNodeList *messages, PRBool isMove) { -#if 1 nsresult rv; if(!srcFolderElement || !dstFolderElement || !messages) @@ -836,76 +842,6 @@ nsMessenger::CopyMessages(nsIRDFCompositeDataSource *database, nsIDOMXULElement rv = DoCommand(database, isMove ? (char *)NC_RDF_MOVE : (char *)NC_RDF_COPY, folderArray, argumentArray); return rv; -#else - nsresult rv; - - if(!srcFolderElement || !dstFolderElement || !messages) - return NS_ERROR_NULL_POINTER; - - nsCOMPtr srcResource, dstResource; - nsCOMPtr dstFolder; - nsCOMPtr srcFolder; - nsCOMPtr resourceArray; - - rv = dstFolderElement->GetResource(getter_AddRefs(dstResource)); - if(NS_FAILED(rv)) - return rv; - - dstFolder = do_QueryInterface(dstResource); - if(!dstFolder) - return NS_ERROR_NO_INTERFACE; - - rv = srcFolderElement->GetResource(getter_AddRefs(srcResource)); - if(NS_FAILED(rv)) - return rv; - - srcFolder = do_QueryInterface(srcResource); - if(!srcFolder) - return NS_ERROR_NO_INTERFACE; - - rv =ConvertDOMListToResourceArray(messages, getter_AddRefs(resourceArray)); - if(NS_FAILED(rv)) - return rv; - - //Call the mailbox service to copy first message. In the future we should call CopyMessages. - //And even more in the future we need to distinguish between the different types of URI's, i.e. - //local, imap, and news, and call the appropriate copy function. - - PRUint32 cnt; - rv = resourceArray->Count(&cnt); - if (NS_SUCCEEDED(rv) && cnt > 0) - { - nsCOMPtr msgSupports = getter_AddRefs(resourceArray->ElementAt(0)); - nsCOMPtr firstMessage(do_QueryInterface(msgSupports)); - char *uri; - firstMessage->GetValue(&uri); - nsCOMPtr copyStreamListener; - rv = nsComponentManager::CreateInstance(kCopyMessageStreamListenerCID, NULL, - nsCOMTypeInfo::GetIID(), - getter_AddRefs(copyStreamListener)); - if(NS_FAILED(rv)) - return rv; - - rv = copyStreamListener->Init(srcFolder, dstFolder, nsnull); - if(NS_FAILED(rv)) - return rv; - nsIMsgMessageService * messageService = nsnull; - rv = GetMessageServiceFromURI(uri, &messageService); - - if (NS_SUCCEEDED(rv) && messageService) - { - nsIURI * url = nsnull; - nsCOMPtr streamListener(do_QueryInterface(copyStreamListener)); - if(!streamListener) - return NS_ERROR_NO_INTERFACE; - messageService->CopyMessage(uri, streamListener, isMove, nsnull, &url); - ReleaseMessageServiceFromURI(uri, messageService); - } - - } - - return rv; -#endif } NS_IMETHODIMP @@ -1441,7 +1377,7 @@ nsMessenger::LoadFirstDraft() // This should really pass in a URI, but for now, just to test, we can pass in nsnull - rv = pMsgDraft->OpenDraftMsg(nsnull, nsnull); + rv = pMsgDraft->OpenDraftMsg(nsnull, nsnull, PR_FALSE); } return rv; @@ -1646,3 +1582,141 @@ nsSaveAsListener::OnDataAvailable(nsIChannel* aChannel, } return rv; } + +// **** ForwardMessages **** +// type: -1: base on prefs 0: as attachment 1: as quoted 2: as inline +NS_IMETHODIMP +nsMessenger::ForwardMessages(nsIDOMNodeList *domNodeList, + PRInt32 type) +{ + nsresult rv = NS_ERROR_NULL_POINTER; + nsCOMPtr messageArray; + + if (!domNodeList) return rv; + rv = ConvertDOMListToResourceArray(domNodeList, + getter_AddRefs(messageArray)); + if (NS_FAILED(rv)) return rv; + PRUint32 cnt = 0, i; + rv = messageArray->Count(&cnt); + if (NS_FAILED(rv)) return rv; + if (!cnt) return NS_ERROR_NULL_POINTER; + + if (type < 0 || type > 2) + { + NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &rv); + if (NS_FAILED(rv)) return rv; + rv = prefs->GetIntPref("mail.forward_message_mode", &type); + if (NS_FAILED(rv)) return rv; + } + + NS_WITH_SERVICE(nsIMsgMailSession, mailSession, kCMsgMailSessionCID, &rv); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr identity; + rv = mailSession->GetCurrentIdentity(getter_AddRefs(identity)); + if (NS_FAILED(rv)) return rv; + + NS_WITH_SERVICE (nsIMsgComposeService, composeService, + kMsgComposeServiceCID, &rv); + if (NS_FAILED(rv)) return rv; + + NS_WITH_SERVICE (nsIComponentManager, compMgr, kComponentManagerCID, &rv); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr compFields; + nsCOMPtr rdfResource; + nsCOMPtr msgSupport; + char *msgUri = nsnull; + + switch (type) + { + case 0: // forward as attachments + { + if (NS_SUCCEEDED(rv)) + { + rv = compMgr->CreateInstance(kMsgCompFieldsCID, nsnull, + nsCOMTypeInfo::GetIID(), + getter_AddRefs(compFields)); + if (NS_FAILED(rv)) return rv; + } + nsString attachments; + for (i=0; iElementAt(i)); + if (msgSupport) + { + rdfResource = do_QueryInterface(msgSupport, &rv); + if (NS_SUCCEEDED(rv)) + { + rv = rdfResource->GetValue(&msgUri); + if (msgUri) + { + if (attachments.Length()) + attachments += ','; + attachments += msgUri; + nsCRT::free(msgUri); + } + } + } + } + nsString subject; + nsString fwdSubject; + msgSupport = getter_AddRefs(messageArray->ElementAt(0)); + nsCOMPtr aMessage = do_QueryInterface(msgSupport); + if (aMessage) + { + nsCOMPtr aMsgHdr; + aMessage->GetMsgDBHdr(getter_AddRefs(aMsgHdr)); + if (aMsgHdr) + { + aMsgHdr->GetSubject(&subject); + fwdSubject = "[Fwd: "; + fwdSubject += subject; + fwdSubject += "]"; + } + } + if (fwdSubject.Length()) + compFields->SetSubject(fwdSubject.ToNewUnicode()); + compFields->SetAttachments(attachments.ToNewUnicode()); + rv = composeService->OpenComposeWindowWithCompFields(nsnull, + MSGCOMP_FORMAT_Default, compFields); + break; + } + case 1: // forward as inline + { + for (i=0; iElementAt(i)); + if (msgSupport) + { + rdfResource = do_QueryInterface(msgSupport, &rv); + if(NS_SUCCEEDED(rv)) + { + rv = rdfResource->GetValue(&msgUri); + if (NS_SUCCEEDED(rv) && msgUri) + { + nsAutoString str (msgUri); + nsCOMPtr pMsgDraft; + rv = compMgr->CreateInstance(kMsgDraftCID, + nsnull, + nsCOMTypeInfo::GetIID(), + getter_AddRefs(pMsgDraft)); + if (NS_SUCCEEDED(rv) && pMsgDraft) + pMsgDraft->OpenDraftMsg(str.ToNewUnicode(), + nsnull, PR_TRUE); + } + } + } + } + break; + } + + default: + { + rv = NS_ERROR_FAILURE; + break; + } + } + + return rv; +} diff --git a/mailnews/compose/public/nsIMsgCompose.idl b/mailnews/compose/public/nsIMsgCompose.idl index fbebb3add7ea..ec8e52692f9d 100644 --- a/mailnews/compose/public/nsIMsgCompose.idl +++ b/mailnews/compose/public/nsIMsgCompose.idl @@ -35,8 +35,8 @@ enum MSGCOMP_TYPE_New = 0, MSGCOMP_TYPE_Reply, MSGCOMP_TYPE_ReplyAll, - MSGCOMP_TYPE_ForwardInline, - MSGCOMP_TYPE_ForwardAsAttachment + MSGCOMP_TYPE_ForwardAsAttachment, + MSGCOMP_TYPE_ForwardInline }; %} diff --git a/mailnews/compose/public/nsIMsgDraft.idl b/mailnews/compose/public/nsIMsgDraft.idl index 25d8c502fc90..a78325bb743e 100644 --- a/mailnews/compose/public/nsIMsgDraft.idl +++ b/mailnews/compose/public/nsIMsgDraft.idl @@ -34,7 +34,8 @@ interface nsIMsgDraft : nsISupports * This is the primary interface for drafts and templates, loaded by * a URI */ - void OpenDraftMsg(in wstring msgURI, out nsIMessage aMsgToReplace); + void OpenDraftMsg(in wstring msgURI, out nsIMessage aMsgToReplace, + in PRBool addInlineHeaders); void OpenEditorTemplate(in wstring msgURI, out nsIMessage aMsgReplace); }; diff --git a/mailnews/compose/resources/content/MsgComposeCommands.js b/mailnews/compose/resources/content/MsgComposeCommands.js index bda47bc0b7e9..77fa0da28870 100644 --- a/mailnews/compose/resources/content/MsgComposeCommands.js +++ b/mailnews/compose/resources/content/MsgComposeCommands.js @@ -220,6 +220,14 @@ function ComposeStartup() if (subjectValue != "") { document.getElementById("msgSubject").value = subjectValue; } + var attachmentValue = msgCompFields.GetAttachments(); + if (attachmentValue != "") { + var atts = attachmentValue.split(","); + for (var i=0; i < atts.length; i++) + { + AddAttachment(atts[i]); + } + } } // Now that we have an Editor AppCore, we can finish to initialize the Compose AppCore diff --git a/mailnews/compose/src/nsMsgAttachmentHandler.cpp b/mailnews/compose/src/nsMsgAttachmentHandler.cpp index 61d9be79a2f6..25407fea822c 100644 --- a/mailnews/compose/src/nsMsgAttachmentHandler.cpp +++ b/mailnews/compose/src/nsMsgAttachmentHandler.cpp @@ -27,6 +27,8 @@ #include "nsMimeTypes.h" #include "nsMsgComposeStringBundle.h" #include "nsXPIDLString.h" +#include "nsIMsgMessageService.h" +#include "nsMsgUtils.h" static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); @@ -110,10 +112,12 @@ nsMsgAttachmentHandler::nsMsgAttachmentHandler() #endif mDeleteFile = PR_FALSE; + m_uri = nsnull; } nsMsgAttachmentHandler::~nsMsgAttachmentHandler() { + PR_FREEIF(m_uri); } void @@ -413,6 +417,60 @@ FetcherURLDoneCallback(nsIURI* aURL, nsresult aStatus, else return NS_OK; } +nsresult +nsMsgAttachmentHandler::SnarfMsgAttachment(nsMsgCompFields *compFields) +{ + nsresult rv = NS_ERROR_INVALID_ARG; + nsIMsgMessageService *messageService = nsnull; + + if (PL_strcasestr(m_uri, "_message:")) + { + mFileSpec = nsMsgCreateTempFileSpec("nsmail.tmp"); + mCompFields = compFields; + PR_FREEIF(m_real_name); + m_real_name = PL_strdup("forward.msg"); + PR_FREEIF(m_type); + m_type = PL_strdup("message/rfc822"); + PR_FREEIF(m_override_type); + m_override_type = PL_strdup("message/rfc822"); + if (!mFileSpec) + { + rv = NS_ERROR_FAILURE; + goto done; + } + mOutFile = new nsOutputFileStream(*mFileSpec, PR_WRONLY | PR_CREATE_FILE); + if (!mOutFile) + { + rv = NS_MSG_UNABLE_TO_OPEN_TMP_FILE; + goto done; + } + mFetcher = new nsURLFetcher(); + if (!mFetcher) + { + rv = NS_ERROR_OUT_OF_MEMORY; + goto done; + } + NS_ADDREF(mFetcher); // to keep us around; very awkward way + rv = mFetcher->Initialize(mOutFile, FetcherURLDoneCallback, this); + rv = GetMessageServiceFromURI(m_uri, &messageService); + if (NS_SUCCEEDED(rv) && messageService) + rv = messageService->DisplayMessage(m_uri, mFetcher, nsnull, nsnull); + } +done: + if (NS_FAILED(rv)) + { + mOutFile->close(); + delete mOutFile; + mOutFile = nsnull; + mFileSpec->Delete(PR_FALSE); + delete mFileSpec; + mFileSpec = nsnull; + } + if (messageService) + ReleaseMessageServiceFromURI(m_uri, messageService); + + return rv; +} nsresult nsMsgAttachmentHandler::SnarfAttachment(nsMsgCompFields *compFields) @@ -424,7 +482,7 @@ nsMsgAttachmentHandler::SnarfAttachment(nsMsgCompFields *compFields) NS_ASSERTION (! m_done, "Already done"); if (!mURL) - return NS_ERROR_INVALID_ARG; + return SnarfMsgAttachment(compFields); tempName = GenerateFileNameFromURI(mURL); // Make it a sane name diff --git a/mailnews/compose/src/nsMsgAttachmentHandler.h b/mailnews/compose/src/nsMsgAttachmentHandler.h index 4ae04596606d..ec6a1645909a 100644 --- a/mailnews/compose/src/nsMsgAttachmentHandler.h +++ b/mailnews/compose/src/nsMsgAttachmentHandler.h @@ -42,6 +42,7 @@ public: ////////////////////////////////////////////////////////////////////// // nsresult SnarfAttachment(nsMsgCompFields *compFields); + nsresult SnarfMsgAttachment(nsMsgCompFields *compFields); nsresult UrlExit(nsresult status, const PRUnichar* aMsg); PRBool UseUUEncode_p(void); @@ -116,6 +117,7 @@ public: PRBool m_file_analyzed; MimeEncoderData *m_encoder_data; /* Opaque state for base64/qp encoder. */ + char * m_uri; // original uri string }; diff --git a/mailnews/compose/src/nsMsgCreate.cpp b/mailnews/compose/src/nsMsgCreate.cpp index 4b76a3c5970c..4913ccb782c8 100644 --- a/mailnews/compose/src/nsMsgCreate.cpp +++ b/mailnews/compose/src/nsMsgCreate.cpp @@ -67,6 +67,7 @@ nsMsgDraft::nsMsgDraft() mURI = nsnull; mMessageService = nsnull; mOutType = nsMimeOutput::nsMimeMessageDraftOrTemplate; + mAddInlineHeaders = PR_FALSE; } nsMsgDraft::~nsMsgDraft() @@ -257,7 +258,11 @@ SaveDraftMessageCompleteCallback(nsIURI *aURL, nsresult aExitCode, void *tagData // Set us as the output stream for HTML data from libmime... nsCOMPtr mimeConverter = do_QueryInterface(mimeParser); if (mimeConverter) - mimeConverter->SetMimeOutputType(ptr->mOutType); // Set the type of output for libmime + { + mimeConverter->SetMimeOutputType(ptr->mOutType); // Set the type of + // output for libmime + mimeConverter->SetForwardInline(ptr->mAddInlineHeaders); + } nsCOMPtr dummyChannel; NS_WITH_SERVICE(nsIIOService, netService, kIOServiceCID, &rv); @@ -359,7 +364,8 @@ nsresult rv; } nsresult -nsMsgDraft::OpenDraftMsg(const PRUnichar *msgURI, nsIMessage **aMsgToReplace) +nsMsgDraft::OpenDraftMsg(const PRUnichar *msgURI, nsIMessage **aMsgToReplace, + PRBool addInlineHeaders) { PRUnichar *HackUpAURIToPlayWith(void); // RICHIE - forward declare for now @@ -368,7 +374,8 @@ PRUnichar *HackUpAURIToPlayWith(void); // RICHIE - forward declare for printf("RICHIE: DO THIS UNTIL THE FE CAN REALLY SUPPORT US!\n"); msgURI = HackUpAURIToPlayWith(); } - + + mAddInlineHeaders = addInlineHeaders; return ProcessDraftOrTemplateOperation(msgURI, nsMimeOutput::nsMimeMessageDraftOrTemplate, aMsgToReplace); } diff --git a/mailnews/compose/src/nsMsgCreate.h b/mailnews/compose/src/nsMsgCreate.h index 3100f817edb6..e60422870ae3 100644 --- a/mailnews/compose/src/nsMsgCreate.h +++ b/mailnews/compose/src/nsMsgCreate.h @@ -34,7 +34,9 @@ public: NS_DECL_ISUPPORTS /* long QuoteMessage (in wstring msgURI, in nsIOutputStream outStream, nsIMessage **aMsgToReplace); */ - NS_IMETHOD OpenDraftMsg(const PRUnichar *msgURI, nsIMessage **aMsgToReplace); + NS_IMETHOD OpenDraftMsg(const PRUnichar *msgURI, + nsIMessage **aMsgToReplace, + PRBool addInlineHeaders); /* long QuoteMessage (in wstring msgURI, in nsIOutputStream outStream, nsIMessage **aMsgToReplace); */ NS_IMETHOD OpenEditorTemplate(const PRUnichar *msgURI, nsIMessage **aMsgToReplace); @@ -50,6 +52,7 @@ public: char *mURI; nsIMsgMessageService *mMessageService; nsMimeOutputType mOutType; + PRBool mAddInlineHeaders; }; // Will be used by factory to generate a nsMsgQuote class... diff --git a/mailnews/compose/src/nsMsgSend.cpp b/mailnews/compose/src/nsMsgSend.cpp index 84eba82d0f0e..fbbb00ace881 100644 --- a/mailnews/compose/src/nsMsgSend.cpp +++ b/mailnews/compose/src/nsMsgSend.cpp @@ -1138,18 +1138,24 @@ nsMsgComposeAndSend::PreProcessPart(nsMsgAttachmentHandler *ma, part->SetPartSeparator(aSeparator); nsXPIDLCString turl; - ma->mURL->GetSpec(getter_Copies(turl)); - hdrs = mime_generate_attachment_headers (ma->m_type, ma->m_encoding, - ma->m_description, - ma->m_x_mac_type, - ma->m_x_mac_creator, - ma->m_real_name, - turl, - m_digest_p, - ma, - ma->m_charset, // rhp - this needs to be the charset we determine from - // the file or none at all! - ma->m_content_id); + if (!ma->mURL) + turl.Copy(ma->m_uri); + else + ma->mURL->GetSpec(getter_Copies(turl)); + hdrs = mime_generate_attachment_headers (ma->m_type, ma->m_encoding, + ma->m_description, + ma->m_x_mac_type, + ma->m_x_mac_creator, + ma->m_real_name, + turl, + m_digest_p, + ma, + ma->m_charset, // rhp - this needs + // to be the charset + // we determine from + // the file or none + // at all! + ma->m_content_id); if (!hdrs) return 0; @@ -1657,6 +1663,9 @@ nsMsgComposeAndSend::AddCompFieldLocalAttachments() { #ifdef NS_DEBUG printf("Adding LOCAL attachment %d: %s\n", newLoc, str.GetBuffer()); +#endif +#ifdef XP_WIN + str.ReplaceChar('|', ':'); #endif // // Now we have to setup the m_attachments entry for the file:// @@ -1771,28 +1780,31 @@ nsMsgComposeAndSend::AddCompFieldRemoteAttachments(PRUint32 aStartLocation, nsMsgNewURL(&(m_attachments[newLoc].mURL), str); - PR_FREEIF(m_attachments[newLoc].m_charset); - m_attachments[newLoc].m_charset = PL_strdup (mCompFields->GetCharacterSet()); - PR_FREEIF(m_attachments[newLoc].m_encoding); - m_attachments[newLoc].m_encoding = PL_strdup ("7bit"); - - /* Count up attachments which are going to come from mail folders - and from NNTP servers. */ + PR_FREEIF(m_attachments[newLoc].m_charset); + m_attachments[newLoc].m_charset = PL_strdup(mCompFields->GetCharacterSet()); + PR_FREEIF(m_attachments[newLoc].m_encoding); + m_attachments[newLoc].m_encoding = PL_strdup ("7bit"); + + /* Count up attachments which are going to come from mail folders + and from NNTP servers. */ nsXPIDLCString turl; if (m_attachments[newLoc].mURL) { - m_attachments[newLoc].mURL->GetSpec(getter_Copies(turl)); - if (PL_strncasecmp(turl, "mailbox:",8) || - PL_strncasecmp(turl, "IMAP:",5)) - (*aMailboxCount)++; - else - if (PL_strncasecmp(turl, "news:",5) || - PL_strncasecmp(turl, "snews:",6)) - (*aNewsCount)++; - - msg_pick_real_name(&m_attachments[newLoc], mCompFields->GetCharacterSet()); - - ++newLoc; + msg_pick_real_name(&m_attachments[newLoc], + mCompFields->GetCharacterSet()); + ++newLoc; + } + else if (str.Find("_message:") != -1) + { + if (str.Find("mailbox_message:") != -1 || + str.Find("imap_message:") != -1) + (*aMailboxCount)++; + else if (str.Find("news_message:") != -1 || + str.Find("snews_message:") != -1) + (*aNewsCount)++; + + m_attachments[newLoc].m_uri = str.ToNewCString(); + ++newLoc; } } diff --git a/mailnews/compose/src/nsURLFetcher.cpp b/mailnews/compose/src/nsURLFetcher.cpp index 133429b1dcbd..a7c4119eac8f 100644 --- a/mailnews/compose/src/nsURLFetcher.cpp +++ b/mailnews/compose/src/nsURLFetcher.cpp @@ -163,6 +163,23 @@ nsURLFetcher::OnStopRequest(nsIChannel *aChannel, nsISupports * /* ctxt */, nsre return NS_OK; } +nsresult +nsURLFetcher::Initialize(nsOutputFileStream *fOut, + nsAttachSaveCompletionCallback cb, + void *tagData) +{ + if (!fOut) + return NS_ERROR_INVALID_ARG; + + if (!fOut->is_open()) + return NS_ERROR_FAILURE; + + mOutStream = fOut; + mCallback = cb; + mTagData = tagData; + return NS_OK; +} + nsresult nsURLFetcher::FireURLRequest(nsIURI *aURL, nsOutputFileStream *fOut, nsAttachSaveCompletionCallback cb, void *tagData) diff --git a/mailnews/compose/src/nsURLFetcher.h b/mailnews/compose/src/nsURLFetcher.h index 9d252ea1a1e8..bd4de42645c4 100644 --- a/mailnews/compose/src/nsURLFetcher.h +++ b/mailnews/compose/src/nsURLFetcher.h @@ -1,4 +1,4 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * The contents of this file are subject to the Netscape Public License * Version 1.0 (the "NPL"); you may not use this file except in @@ -49,6 +49,9 @@ public: NS_IMETHOD FireURLRequest(nsIURI *aURL, nsOutputFileStream *fOut, nsAttachSaveCompletionCallback cb, void *tagData); + NS_IMETHOD Initialize(nsOutputFileStream *fOut, + nsAttachSaveCompletionCallback cb, + void *tagData); // Methods for nsIStreamListener NS_DECL_NSISTREAMLISTENER diff --git a/mailnews/imap/src/nsImapUndoTxn.cpp b/mailnews/imap/src/nsImapUndoTxn.cpp index 270d35ac2fdf..faa8f200ce0c 100644 --- a/mailnews/imap/src/nsImapUndoTxn.cpp +++ b/mailnews/imap/src/nsImapUndoTxn.cpp @@ -340,6 +340,7 @@ nsImapMoveCopyMsgTxn::UndoMailboxDelete() } } } + srcDB->SetSummaryValid(PR_TRUE); srcDB->Commit(nsMsgDBCommitType::kLargeCommit); return NS_OK; // always return NS_OK } @@ -362,6 +363,7 @@ nsImapMoveCopyMsgTxn::RedoMailboxDelete() if (NS_SUCCEEDED(rv)) { srcDB->DeleteMessages(&m_srcKeyArray, nsnull); + srcDB->SetSummaryValid(PR_TRUE); srcDB->Commit(nsMsgDBCommitType::kLargeCommit); } return NS_OK; // always return NS_OK diff --git a/mailnews/local/src/nsLocalMailFolder.cpp b/mailnews/local/src/nsLocalMailFolder.cpp index 6a3e6450641e..476385972a82 100644 --- a/mailnews/local/src/nsLocalMailFolder.cpp +++ b/mailnews/local/src/nsLocalMailFolder.cpp @@ -1705,6 +1705,7 @@ NS_IMETHODIMP nsMsgLocalMailFolder::EndCopy(PRBool copySucceeded) rv = mDatabase->CopyHdrFromExistingHdr(mCopyState->m_curDstKey, msgDBHdr, getter_AddRefs(newHdr)); + mDatabase->SetSummaryValid(PR_TRUE); mDatabase->Commit(nsMsgDBCommitType::kLargeCommit); } } @@ -1750,6 +1751,7 @@ NS_IMETHODIMP nsMsgLocalMailFolder::EndCopy(PRBool copySucceeded) newHdr->GetMessageSize(&msgSize); localUndoTxn->AddDstMsgSize(msgSize); } + msgDb->SetSummaryValid(PR_TRUE); msgDb->Commit(nsMsgDBCommitType::kLargeCommit); } } diff --git a/mailnews/local/src/nsLocalUndoTxn.cpp b/mailnews/local/src/nsLocalUndoTxn.cpp index b4fc8c3cf50c..57cf82f09754 100644 --- a/mailnews/local/src/nsLocalUndoTxn.cpp +++ b/mailnews/local/src/nsLocalUndoTxn.cpp @@ -267,10 +267,12 @@ nsLocalMoveCopyMsgTxn::Undo() } } } + srcDB->SetSummaryValid(PR_TRUE); srcDB->Commit(nsMsgDBCommitType::kLargeCommit); } dstDB->DeleteMessages(&m_dstKeyArray, nsnull); + dstDB->SetSummaryValid(PR_TRUE); dstDB->Commit(nsMsgDBCommitType::kLargeCommit); return rv; @@ -314,6 +316,7 @@ nsLocalMoveCopyMsgTxn::Redo() } } } + dstDB->SetSummaryValid(PR_TRUE); dstDB->Commit(nsMsgDBCommitType::kLargeCommit); if (m_isMove) @@ -325,6 +328,7 @@ nsLocalMoveCopyMsgTxn::Redo() else { rv = srcDB->DeleteMessages(&m_srcKeyArray, nsnull); + srcDB->SetSummaryValid(PR_TRUE); srcDB->Commit(nsMsgDBCommitType::kLargeCommit); } } diff --git a/mailnews/mime/public/nsIMimeStreamConverter.idl b/mailnews/mime/public/nsIMimeStreamConverter.idl index 0f64ddfcacd7..2a4b06ebf413 100644 --- a/mailnews/mime/public/nsIMimeStreamConverter.idl +++ b/mailnews/mime/public/nsIMimeStreamConverter.idl @@ -71,4 +71,9 @@ interface nsIMimeStreamConverter : nsISupports { * This is used to extract headers while parsing a message */ void SetMimeHeadersListener(in nsIMimeStreamConverterListener listener); + + /* + * This is used for forward inline + */ + attribute PRBool forwardInline; }; diff --git a/mailnews/mime/src/mimedrft.cpp b/mailnews/mime/src/mimedrft.cpp index bb61690170fa..0c57838e9c2a 100644 --- a/mailnews/mime/src/mimedrft.cpp +++ b/mailnews/mime/src/mimedrft.cpp @@ -181,7 +181,9 @@ struct mime_draft_data nsOutputFileStream *tmpFileStream; // output file handle MimeDecoderData *decoder_data; - char *mailcharset; // get it from CHARSET of Content-Type + char *mailcharset; // get it from CHARSET of + // Content-Type + PRBool forwardInline; }; // RICHIE - PROBABLY BELONGS IN A HEADER SOMEWHERE!!! @@ -245,10 +247,34 @@ printf("RICHIE: Need to do something with the attachment data!!!!\n"); mime_dump_attachments ( attachmentList ); #endif - NS_WITH_SERVICE(nsIMsgComposeService, msgComposeService, kCMsgComposeServiceCID, &rv); + nsMsgAttachmentData *curAttachment = attachmentList; + if (curAttachment) + { + nsString attachments; + char* spec = nsnull; + + while (curAttachment && curAttachment->real_name) + { + rv = curAttachment->url->GetSpec(&spec); + if (NS_SUCCEEDED(rv) && spec) + { + if (attachments.Length()) + attachments += ','; + attachments += spec; + nsCRT::free(spec); + spec = nsnull; + } + curAttachment++; + } + if (attachments.Length()) + compFields->SetAttachments(attachments.ToNewUnicode()); + } + + NS_WITH_SERVICE(nsIMsgComposeService, msgComposeService, + kCMsgComposeServiceCID, &rv); if ((NS_FAILED(rv)) || (!msgComposeService)) return rv; - + if (editorType == nsMsgPlainTextEditor) format = MSGCOMP_FORMAT_PlainText; else if (editorType == nsMsgHTMLEditor) @@ -1111,7 +1137,8 @@ mime_parse_stream_complete (nsMIMESession *stream) // We need to figure out how to pass the forwarded flag along with this // operation. - // forward_inline = (mdd->format_out != FO_CMDLINE_ATTACHMENTS); + //forward_inline = (mdd->format_out != FO_CMDLINE_ATTACHMENTS); + forward_inline = mdd->forwardInline; if (forward_inline) { #ifdef MOZ_SECURITY @@ -1657,11 +1684,15 @@ mime_decompose_file_init_fn ( void *stream_closure, MimeHeaders *headers ) if (tmpSpecStr) { - char *slashPtr = tmpSpecStr; + char *slashPtr = tmpSpecStr+7; while (*slashPtr) { if (*slashPtr == '\\') *slashPtr = '/'; +#ifdef XP_WIN + if (*slashPtr == ':') + *slashPtr = '|'; +#endif slashPtr++; } @@ -1810,6 +1841,7 @@ mime_bridge_create_draft_stream( } } + newPluginObj2->GetForwardInline(&mdd->forwardInline); mdd->format_out = format_out; mdd->options = PR_NEWZAP ( MimeDisplayOptions ); if ( !mdd->options ) diff --git a/mailnews/mime/src/nsStreamConverter.cpp b/mailnews/mime/src/nsStreamConverter.cpp index cf06386b079c..0a76b367fbf6 100644 --- a/mailnews/mime/src/nsStreamConverter.cpp +++ b/mailnews/mime/src/nsStreamConverter.cpp @@ -335,6 +335,7 @@ nsStreamConverter::nsStreamConverter() mDoneParsing = PR_FALSE; mAlreadyKnowOutputType = PR_FALSE; mMimeStreamConverterListener = nsnull; + mForwardInline = PR_FALSE; } nsStreamConverter::~nsStreamConverter() @@ -559,6 +560,21 @@ nsStreamConverter::SetMimeHeadersListener(nsIMimeStreamConverterListener *listen return NS_OK; } +NS_IMETHODIMP +nsStreamConverter::SetForwardInline(PRBool forwardInline) +{ + mForwardInline = forwardInline; + return NS_OK; +} + +NS_IMETHODIMP +nsStreamConverter::GetForwardInline(PRBool *result) +{ + if (!result) return NS_ERROR_NULL_POINTER; + *result = mForwardInline; + return NS_OK; +} + ///////////////////////////////////////////////////////////////////////////// // Methods for nsIStreamListener... ///////////////////////////////////////////////////////////////////////////// diff --git a/mailnews/mime/src/nsStreamConverter.h b/mailnews/mime/src/nsStreamConverter.h index f7bf5f2dbc4b..d5cc21d170a7 100644 --- a/mailnews/mime/src/nsStreamConverter.h +++ b/mailnews/mime/src/nsStreamConverter.h @@ -1,4 +1,4 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * The contents of this file are subject to the Netscape Public License * Version 1.0 (the "NPL"); you may not use this file except in @@ -39,11 +39,7 @@ public: NS_DECL_ISUPPORTS // nsIMimeStreamConverter support - NS_IMETHOD SetMimeOutputType(nsMimeOutputType aType); - NS_IMETHOD GetMimeOutputType(nsMimeOutputType *aOutFormat); - NS_IMETHOD SetStreamURI(nsIURI *aURI); - NS_IMETHOD SetMimeHeadersListener(nsIMimeStreamConverterListener* listener); - + NS_DECL_NSIMIMESTREAMCONVERTER // nsIStreamConverter methods NS_DECL_NSISTREAMCONVERTER // nsIStreamListener methods @@ -85,6 +81,7 @@ private: PRBool mDoneParsing; // If this is true, we've already been told by libmime to stop sending // data so don't feed the parser any more! nsIMimeStreamConverterListener* mMimeStreamConverterListener; + PRBool mForwardInline; }; // factory method