Bug 1799764 - Concrete implementation of nsIMsgDBHdr for file messages. r=BenC

Differential Revision: https://phabricator.services.mozilla.com/D161659

--HG--
extra : rebase_source : ca8e1a084267bfdac2e243ad7745de214fb4d473
This commit is contained in:
Geoff Lankow 2022-11-07 22:16:59 +13:00
Родитель 748d5d7eba
Коммит e1019aba91
11 изменённых файлов: 380 добавлений и 19 удалений

Просмотреть файл

@ -166,6 +166,8 @@ function displayExternalMessage(uri) {
let messageService = MailServices.messageServiceFromURI(uri);
messageService.DisplayMessage(uri, content.docShell, null, null, null, {});
gMessage = top.messenger.msgHdrFromURI(uri);
}
function displayMessage(uri, viewWrapper) {

Просмотреть файл

@ -3657,7 +3657,7 @@ const gMessageHeader = {
setTags() {
let msgHdr = gFolderDisplay.selectedMessage;
// Bail out if we don't have a message selected.
if (!msgHdr) {
if (!msgHdr || !gFolder) {
return;
}

Просмотреть файл

@ -342,9 +342,7 @@ Enigmail.msg = {
msgUri = this.getOriginalMsgUri();
}
if (msgUri) {
return MailServices.messageServiceFromURI(msgUri).messageURIToMsgHdr(
msgUri
);
return gMessenger.msgHdrFromURI(msgUri);
}
} catch (ex) {
// See also bug 1635648

Просмотреть файл

@ -26,7 +26,7 @@ var MailServices = {
}
let protocol = uri.substring(0, index);
if (protocol == "file" && uri.includes("application/x-message-display")) {
if (protocol == "file") {
protocol = "mailbox";
}
return Cc[

Просмотреть файл

@ -117,9 +117,9 @@ nsresult GetMessageServiceContractIDForURI(const char* uri,
nsAutoCString protocol(StringHead(uriStr, pos));
if (protocol.EqualsLiteral("file") &&
uriStr.Find("application/x-message-display") != -1)
if (protocol.EqualsLiteral("file")) {
protocol.AssignLiteral("mailbox");
}
// Build message service contractid
contractID = "@mozilla.org/messenger/messageservice;1?type=";
contractID += protocol.get();

Просмотреть файл

@ -51,12 +51,7 @@ add_task(function test_message_services() {
);
}
// Special case for files, requires the application/x-message-display.
// I'm not sure if this really should be this way, but it is.
check_message_service(
"file://it.does.not.matter/?type=application/x-message-display"
);
check_message_service("file://it.does.not.matter/");
check_message_service("imap://it.does.not.matter/");
check_message_service("imap-message://it.does.not.matter/");
check_message_service("mailbox://it.does.not.matter/");

Просмотреть файл

@ -2749,10 +2749,11 @@ nsresult nsMsgCompose::QuoteOriginalMessage() // New template
NS_ENSURE_SUCCESS(rv, rv);
}
bool fileUrl = StringBeginsWith(mOriginalMsgURI, "file:"_ns);
nsAutoCString msgUri(mOriginalMsgURI);
bool fileUrl = StringBeginsWith(msgUri, "file:"_ns);
if (fileUrl) {
mOriginalMsgURI.Replace(0, 5, "mailbox:"_ns);
mOriginalMsgURI.AppendLiteral("?number=0");
msgUri.Replace(0, 5, "mailbox:"_ns);
msgUri.AppendLiteral("?number=0");
}
// Create the consumer output stream.. this will receive all the HTML from
@ -2764,9 +2765,8 @@ nsresult nsMsgCompose::QuoteOriginalMessage() // New template
mQuoteStreamListener->SetComposeObj(this);
rv = mQuote->QuoteMessage(mOriginalMsgURI, mWhatHolder != 1,
mQuoteStreamListener, mCharsetOverride, !bAutoQuote,
originalMsgHdr);
rv = mQuote->QuoteMessage(msgUri, mWhatHolder != 1, mQuoteStreamListener,
mCharsetOverride, !bAutoQuote, originalMsgHdr);
return rv;
}

Просмотреть файл

@ -12,6 +12,7 @@ SOURCES += [
"nsMailboxService.cpp",
"nsMailboxUrl.cpp",
"nsMsgBrkMBoxStore.cpp",
"nsMsgFileHdr.cpp",
"nsMsgLocalStoreUtils.cpp",
"nsMsgMaildirStore.cpp",
"nsNoIncomingServer.cpp",

Просмотреть файл

@ -27,6 +27,7 @@
#include "mozilla/LoadInfo.h"
#include "nsDocShellLoadState.h"
#include "nsContentUtils.h"
#include "nsMsgFileHdr.h"
nsMailboxService::nsMailboxService() {}
@ -588,6 +589,12 @@ nsMailboxService::MessageURIToMsgHdr(const nsACString& uri,
nsIMsgDBHdr** _retval) {
NS_ENSURE_ARG_POINTER(_retval);
if (StringBeginsWith(uri, "file:"_ns)) {
nsCOMPtr<nsIMsgDBHdr> msgHdr = new nsMsgFileHdr(uri);
msgHdr.forget(_retval);
return NS_OK;
}
nsresult rv = NS_OK;
nsCOMPtr<nsIMsgFolder> folder;

Просмотреть файл

@ -0,0 +1,322 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsCOMPtr.h"
#include "nsMsgFileHdr.h"
#include "nsNetUtil.h"
#include "nsIFileURL.h"
#include "HeaderReader.h"
#include "nsIFileStreams.h"
#include "nsIMimeConverter.h"
NS_IMPL_ISUPPORTS(nsMsgFileHdr, nsIMsgDBHdr)
nsMsgFileHdr::nsMsgFileHdr(const nsACString& aUri) {
mUri = nsCString(aUri);
mDate = 0;
}
nsMsgFileHdr::~nsMsgFileHdr() {}
nsresult nsMsgFileHdr::ReadFile() {
if (mFile) {
return NS_OK;
}
nsresult rv;
nsCOMPtr<nsIURI> uri;
NS_NewURI(getter_AddRefs(uri), mUri);
nsCOMPtr<nsIFileURL> fileUrl = do_QueryInterface(uri);
rv = fileUrl->GetFile(getter_AddRefs(mFile));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIFileInputStream> fileStream =
do_CreateInstance(NS_LOCALFILEINPUTSTREAM_CONTRACTID);
rv = fileStream->Init(mFile, PR_RDONLY, 0664, 0);
NS_ENSURE_SUCCESS(rv, rv);
uint32_t count;
char buffer[8192];
rv = fileStream->Read(&buffer[0], 8192, &count);
NS_ENSURE_SUCCESS(rv, rv);
auto cb = [&](HeaderReader::Hdr const& hdr) {
auto name = hdr.Name(buffer);
if (name.EqualsLiteral("Subject") && mSubject.IsEmpty()) {
mSubject = hdr.Value(buffer);
}
if (name.EqualsLiteral("From") && mAuthor.IsEmpty()) {
mAuthor = hdr.Value(buffer);
}
if (name.EqualsLiteral("Date") && mDate == 0) {
PR_ParseTimeString(hdr.Value(buffer).get(), false, &mDate);
}
if (name.EqualsLiteral("Message-ID") && mMessageID.IsEmpty()) {
mMessageID = hdr.Value(buffer);
mMessageID.Trim("<>");
}
return true;
};
HeaderReader rdr;
rdr.Parse(buffer, cb);
nsCOMPtr<nsIMimeConverter> mimeConverter =
do_GetService("@mozilla.org/messenger/mimeconverter;1");
mimeConverter->DecodeMimeHeader(mSubject.get(), "UTF-8", false, true,
mDecodedSubject);
mimeConverter->DecodeMimeHeader(mAuthor.get(), "UTF-8", false, true,
mDecodedAuthor);
return rv;
}
NS_IMETHODIMP nsMsgFileHdr::GetProperty(const char* propertyName,
nsAString& _retval) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::SetProperty(const char* propertyName,
const nsAString& propertyStr) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::SetStringProperty(const char* propertyName,
const char* propertyValue) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::GetStringProperty(const char* propertyName,
char** _retval) {
*_retval = strdup("");
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::GetUint32Property(const char* propertyName,
uint32_t* _retval) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::SetUint32Property(const char* propertyName,
uint32_t propertyVal) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::GetIsRead(bool* aIsRead) { return NS_OK; }
NS_IMETHODIMP nsMsgFileHdr::GetIsFlagged(bool* aIsFlagged) { return NS_OK; }
NS_IMETHODIMP nsMsgFileHdr::GetIsKilled(bool* aIsKilled) { return NS_OK; }
NS_IMETHODIMP nsMsgFileHdr::MarkRead(bool read) { return NS_OK; }
NS_IMETHODIMP nsMsgFileHdr::MarkFlagged(bool flagged) { return NS_OK; }
NS_IMETHODIMP nsMsgFileHdr::MarkHasAttachments(bool hasAttachments) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::GetPriority(nsMsgPriorityValue* aPriority) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::SetPriority(nsMsgPriorityValue aPriority) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::SetPriorityString(const char* priority) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::GetFlags(uint32_t* aFlags) { return NS_OK; }
NS_IMETHODIMP nsMsgFileHdr::SetFlags(uint32_t aFlags) { return NS_OK; }
NS_IMETHODIMP nsMsgFileHdr::OrFlags(uint32_t flags, uint32_t* _retval) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::AndFlags(uint32_t flags, uint32_t* _retval) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::GetThreadId(nsMsgKey* aThreadId) { return NS_OK; }
NS_IMETHODIMP nsMsgFileHdr::SetThreadId(nsMsgKey aThreadId) { return NS_OK; }
NS_IMETHODIMP nsMsgFileHdr::GetMessageKey(nsMsgKey* aMessageKey) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::SetMessageKey(nsMsgKey aMessageKey) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::GetThreadParent(nsMsgKey* aThreadParent) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::SetThreadParent(nsMsgKey aThreadParent) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::GetMessageSize(uint32_t* aMessageSize) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::SetMessageSize(uint32_t aMessageSize) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::GetLineCount(uint32_t* aLineCount) { return NS_OK; }
NS_IMETHODIMP nsMsgFileHdr::SetLineCount(uint32_t aLineCount) { return NS_OK; }
NS_IMETHODIMP nsMsgFileHdr::GetMessageOffset(uint64_t* aMessageOffset) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::SetMessageOffset(uint64_t aMessageOffset) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::GetOfflineMessageSize(
uint32_t* aOfflineMessageSize) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::SetOfflineMessageSize(
uint32_t aOfflineMessageSize) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::GetDate(PRTime* aDate) {
nsresult rv = ReadFile();
NS_ENSURE_SUCCESS(rv, rv);
*aDate = mDate;
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::SetDate(PRTime aDate) { return NS_OK; }
NS_IMETHODIMP nsMsgFileHdr::GetDateInSeconds(uint32_t* aDateInSeconds) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::GetMessageId(char** aMessageId) {
nsresult rv = ReadFile();
NS_ENSURE_SUCCESS(rv, rv);
*aMessageId = strdup(mMessageID.get());
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::SetMessageId(const char* aMessageId) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::GetCcList(char** aCcList) { return NS_OK; }
NS_IMETHODIMP nsMsgFileHdr::SetCcList(const char* aCcList) { return NS_OK; }
NS_IMETHODIMP nsMsgFileHdr::GetBccList(char** aBccList) { return NS_OK; }
NS_IMETHODIMP nsMsgFileHdr::SetBccList(const char* aBccList) { return NS_OK; }
NS_IMETHODIMP nsMsgFileHdr::GetAuthor(char** aAuthor) { return NS_OK; }
NS_IMETHODIMP nsMsgFileHdr::SetAuthor(const char* aAuthor) { return NS_OK; }
NS_IMETHODIMP nsMsgFileHdr::GetSubject(char** aSubject) {
nsresult rv = ReadFile();
NS_ENSURE_SUCCESS(rv, rv);
*aSubject = strdup(mSubject.get());
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::SetSubject(const char* aSubject) { return NS_OK; }
NS_IMETHODIMP nsMsgFileHdr::GetRecipients(char** aRecipients) { return NS_OK; }
NS_IMETHODIMP nsMsgFileHdr::SetRecipients(const char* aRecipients) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::SetReferences(const nsACString& references) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::GetNumReferences(uint16_t* aNumReferences) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::GetStringReference(int32_t refNum,
nsACString& _retval) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::GetMime2DecodedAuthor(
nsAString& aMime2DecodedAuthor) {
nsresult rv = ReadFile();
NS_ENSURE_SUCCESS(rv, rv);
aMime2DecodedAuthor.Truncate();
aMime2DecodedAuthor.Assign(mDecodedAuthor);
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::GetMime2DecodedSubject(
nsAString& aMime2DecodedSubject) {
nsresult rv = ReadFile();
NS_ENSURE_SUCCESS(rv, rv);
aMime2DecodedSubject.Truncate();
aMime2DecodedSubject.Assign(mDecodedSubject);
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::GetMime2DecodedRecipients(
nsAString& aMime2DecodedRecipients) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::GetAuthorCollationKey(nsTArray<uint8_t>& _retval) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::GetSubjectCollationKey(nsTArray<uint8_t>& _retval) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::GetRecipientsCollationKey(
nsTArray<uint8_t>& _retval) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::GetCharset(char** aCharset) { return NS_OK; }
NS_IMETHODIMP nsMsgFileHdr::SetCharset(const char* aCharset) { return NS_OK; }
NS_IMETHODIMP nsMsgFileHdr::GetEffectiveCharset(nsACString& aEffectiveCharset) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::GetLabel(nsMsgLabelValue* aLabel) { return NS_OK; }
NS_IMETHODIMP nsMsgFileHdr::SetLabel(nsMsgLabelValue aLabel) { return NS_OK; }
NS_IMETHODIMP nsMsgFileHdr::GetAccountKey(char** aAccountKey) { return NS_OK; }
NS_IMETHODIMP nsMsgFileHdr::SetAccountKey(const char* aAccountKey) {
return NS_OK;
}
NS_IMETHODIMP nsMsgFileHdr::GetFolder(nsIMsgFolder** aFolder) { return NS_OK; }
NS_IMETHODIMP nsMsgFileHdr::GetPropertyEnumerator(
nsIUTF8StringEnumerator** aPropertyEnumerator) {
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,36 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef _nsMsgFileHdr_H
#define _nsMsgFileHdr_H
#include "nsIMsgHdr.h"
#include "nsString.h"
#include "nsTArray.h"
/* This mail-related class is a stub. You can help mailnews by expanding it. */
class nsMsgFileHdr : public nsIMsgDBHdr {
public:
explicit nsMsgFileHdr(const nsACString& aUri);
NS_DECL_NSIMSGDBHDR
NS_DECL_ISUPPORTS
private:
virtual ~nsMsgFileHdr();
nsresult ReadFile();
nsCString mUri;
nsCOMPtr<nsIFile> mFile;
nsCString mAuthor;
nsString mDecodedAuthor;
nsCString mSubject;
nsString mDecodedSubject;
PRTime mDate;
nsCString mMessageID;
};
#endif