Bug 1828331 - Some refactoring of nsIMsgMessageService. r=benc

Rename DisplayMessage to loadMessage + remove unused outUrl. This is a more appropriate name as it's strictly not just about displaying, but used for e.g. copying too.
OutUrl *was* passed around to CopyMessage.

Rename CopyMessage to copyMessage and remove unused outUrl.

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

--HG--
extra : rebase_source : 719233163affeeacc1d4094ce24328a7058fb534
This commit is contained in:
Magnus Melin 2023-04-27 16:15:06 +10:00
Родитель a3fe69d042
Коммит 660a2738d0
17 изменённых файлов: 78 добавлений и 131 удалений

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

@ -52,13 +52,12 @@ function ReloadMessage() {
function MailSetCharacterSet() {
let messageService = MailServices.messageServiceFromURI(gMessageURI);
gMessage = messageService.messageURIToMsgHdr(gMessageURI);
messageService.DisplayMessage(
messageService.loadMessage(
gMessageURI,
getMessagePaneBrowser().docShell,
null,
null,
true,
{}
true
);
autodetectCharset = true;
}
@ -183,7 +182,7 @@ function displayMessage(uri, viewWrapper) {
browser.docShell.allowDNSPrefetch = false;
try {
messageService.DisplayMessage(uri, browser.docShell, null, null, null, {});
messageService.loadMessage(uri, browser.docShell, null, null, null);
} catch (ex) {
if (ex.result != Cr.NS_ERROR_OFFLINE) {
throw ex;

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

@ -47,10 +47,9 @@ interface nsIMsgMessageService : nsISupports {
* FALSE leaves it as just a copy.
* @param aUrlListener
* @param aMsgWindow
* @param aURL
*/
void CopyMessage(in AUTF8String aSrcURI, in nsIStreamListener aCopyListener, in boolean aMoveMessage,
in nsIUrlListener aUrlListener, in nsIMsgWindow aMsgWindow, out nsIURI aURL);
void copyMessage(in AUTF8String aSrcURI, in nsIStreamListener aCopyListener, in boolean aMoveMessage,
in nsIUrlListener aUrlListener, in nsIMsgWindow aMsgWindow);
/**
* Copy multiple messages at a time
@ -71,7 +70,7 @@ interface nsIMsgMessageService : nsISupports {
in nsIMsgWindow aMsgWindow);
/**
* When you want a message displayed....
* When you want a message displayed.... this loads it into the consumer.
*
* @param aMessageURI Is a uri representing the message to display.
* @param aDisplayConsumer Is (for now) an nsIDocShell which we'll use to load
@ -80,14 +79,12 @@ interface nsIMsgMessageService : nsISupports {
* @param aMsgWindow
* @param aUrlListener
* @param aAutodetectCharset (optional) if the characterset should be auto-detected.
* @param aURL
*/
void DisplayMessage(in AUTF8String aMessageURI,
void loadMessage(in AUTF8String aMessageURI,
in nsISupports aDisplayConsumer,
in nsIMsgWindow aMsgWindow,
in nsIUrlListener aUrlListener,
in boolean aAutodetectCharset,
out nsIURI aURL);
in boolean aAutodetectCharset);
/**
* When you want to spool a message out to a file on disk.

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

@ -521,9 +521,8 @@ nsresult nsMessenger::SaveAttachment(nsIFile* aFile, const nsACString& aURL,
mMsgWindow, saveListener,
getter_AddRefs(dummyNull));
else
rv = messageService->DisplayMessage(fullMessageUri, convertedListener,
mMsgWindow, nullptr, false,
getter_AddRefs(dummyNull));
rv = messageService->LoadMessage(fullMessageUri, convertedListener,
mMsgWindow, nullptr, false);
} // if we got a message service
} // if we created a url
@ -889,10 +888,8 @@ nsMessenger::SaveAs(const nsACString& aURI, bool aAsFile,
NS_ASSERTION(NS_SUCCEEDED(rv), "AsyncConvertData failed");
if (NS_FAILED(rv)) goto done;
nsCOMPtr<nsIURI> dummyNull;
rv = messageService->DisplayMessage(urlString, convertedListener,
mMsgWindow, nullptr, false,
getter_AddRefs(dummyNull));
rv = messageService->LoadMessage(urlString, convertedListener, mMsgWindow,
nullptr, false);
}
} else {
// ** save as Template

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

@ -1205,7 +1205,7 @@ nsresult nsMsgComposeService::LoadDraftOrTemplate(
doing a command that opens the compose window,
* which means we switch the compose window used
* from the default.
* @param aMsgWindow msgWindow to pass into DisplayMessage.
* @param aMsgWindow msgWindow to pass into LoadMessage.
*/
nsresult nsMsgComposeService::RunMessageThroughMimeDraft(
const nsACString& aMsgURI, nsMimeOutputType aOutType,
@ -1288,10 +1288,8 @@ nsresult nsMsgComposeService::RunMessageThroughMimeDraft(
// Now, just plug the two together and get the hell out of the way!
nsCOMPtr<nsIStreamListener> streamListener = do_QueryInterface(mimeConverter);
nsCOMPtr<nsIURI> dummyNull;
return messageService->DisplayMessage(aMsgURI, streamListener, aMsgWindow,
nullptr, autodetectCharset,
getter_AddRefs(dummyNull));
return messageService->LoadMessage(aMsgURI, streamListener, aMsgWindow,
nullptr, autodetectCharset);
}
NS_IMETHODIMP

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

@ -587,12 +587,11 @@ nsresult nsMsgSendLater::StartNextMailFileSend(nsresult prevStatus) {
m_headersSize = 0;
PR_FREEIF(mLeftoverBuffer);
// Now, get our stream listener interface and plug it into the DisplayMessage
// Now, get our stream listener interface and plug it into the LoadMessage
// operation
nsCOMPtr<nsIURI> dummyNull;
rv = messageService->DisplayMessage(
messageURI, static_cast<nsIStreamListener*>(this), nullptr, nullptr,
false, getter_AddRefs(dummyNull));
rv = messageService->LoadMessage(messageURI,
static_cast<nsIStreamListener*>(this),
nullptr, nullptr, false);
return rv;
}

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

@ -26,15 +26,8 @@ class BaseMessageService {
_logger = ImapUtils.logger;
CopyMessage(
messageUri,
copyListener,
moveMessage,
urlListener,
msgWindow,
outUrl
) {
this._logger.debug("CopyMessage", messageUri, moveMessage);
copyMessage(messageUri, copyListener, moveMessage, urlListener, msgWindow) {
this._logger.debug("copyMessage", messageUri, moveMessage);
let { serverURI, folder, folderName, key } = this._decomposeMessageUri(
messageUri
);
@ -63,15 +56,14 @@ class BaseMessageService {
);
}
DisplayMessage(
loadMessage(
messageUri,
displayConsumer,
msgWindow,
urlListener,
autodetectCharset,
outURL
autodetectCharset
) {
this._logger.debug("DisplayMessage", messageUri);
this._logger.debug("loadMessage", messageUri);
let { serverURI, folder, folderName, key } = this._decomposeMessageUri(
messageUri
);

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

@ -7571,10 +7571,9 @@ nsresult nsImapMailFolder::CopyStreamMessage(
statusFeedback->ShowProgress(percent);
}
}
nsCOMPtr<nsIURI> dummyNull;
rv = m_copyState->m_msgService->CopyMessage(
uri, streamListener, isMove && !m_copyState->m_isCrossServerOp, nullptr,
aMsgWindow, getter_AddRefs(dummyNull));
aMsgWindow);
if (NS_FAILED(rv))
MOZ_LOG(IMAP, mozilla::LogLevel::Info,
("CopyMessage failed: uri %s", uri.get()));

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

@ -304,12 +304,11 @@ NS_IMETHODIMP nsImapService::FetchMimePart(
return rv;
}
NS_IMETHODIMP nsImapService::DisplayMessage(const nsACString& aMessageURI,
nsISupports* aDisplayConsumer,
nsIMsgWindow* aMsgWindow,
nsIUrlListener* aUrlListener,
bool aAutodetectCharset,
nsIURI** aURL) {
NS_IMETHODIMP nsImapService::LoadMessage(const nsACString& aMessageURI,
nsISupports* aDisplayConsumer,
nsIMsgWindow* aMsgWindow,
nsIUrlListener* aUrlListener,
bool aAutodetectCharset) {
nsresult rv;
nsCOMPtr<nsIMsgFolder> folder;
@ -329,7 +328,6 @@ NS_IMETHODIMP nsImapService::DisplayMessage(const nsACString& aMessageURI,
sizeof("&type=application/x-message-display") - 1);
rv = NS_NewURI(getter_AddRefs(uri), messageURI.get());
NS_ENSURE_SUCCESS(rv, rv);
if (aURL) NS_IF_ADDREF(*aURL = uri);
nsCOMPtr<nsIStreamListener> aStreamListener =
do_QueryInterface(aDisplayConsumer, &rv);
if (NS_SUCCEEDED(rv) && aStreamListener) {
@ -377,9 +375,10 @@ NS_IMETHODIMP nsImapService::DisplayMessage(const nsACString& aMessageURI,
EmptyCString());
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIURI> dummyURI;
return FetchMimePart(imapUrl, nsIImapUrl::nsImapMsgFetch, folder,
imapMessageSink, aURL, aDisplayConsumer, msgKey,
mimePart);
imapMessageSink, getter_AddRefs(dummyURI),
aDisplayConsumer, msgKey, mimePart);
}
nsCOMPtr<nsIMsgMailNewsUrl> msgurl(do_QueryInterface(imapUrl));
@ -419,11 +418,12 @@ NS_IMETHODIMP nsImapService::DisplayMessage(const nsACString& aMessageURI,
(dontMarkAsReadPos != kNotFound));
}
nsCOMPtr<nsIURI> dummyURI;
rv = FetchMessage(imapUrl,
forcePeek ? nsIImapUrl::nsImapMsgFetchPeek
: nsIImapUrl::nsImapMsgFetch,
folder, imapMessageSink, aMsgWindow, aDisplayConsumer,
msgKey, false, aURL);
msgKey, false, getter_AddRefs(dummyURI));
}
}
return rv;
@ -546,8 +546,7 @@ NS_IMETHODIMP nsImapService::CopyMessage(const nsACString& aSrcMailboxURI,
nsIStreamListener* aMailboxCopy,
bool moveMessage,
nsIUrlListener* aUrlListener,
nsIMsgWindow* aMsgWindow,
nsIURI** aURL) {
nsIMsgWindow* aMsgWindow) {
NS_ENSURE_ARG_POINTER(aMailboxCopy);
nsresult rv;
@ -578,11 +577,10 @@ NS_IMETHODIMP nsImapService::CopyMessage(const nsACString& aSrcMailboxURI,
// now try to download the message
nsImapAction imapAction = nsIImapUrl::nsImapOnlineToOfflineCopy;
if (moveMessage) imapAction = nsIImapUrl::nsImapOnlineToOfflineMove;
// clang-format off
rv = FetchMessage(imapUrl, imapAction, folder, imapMessageSink,
aMsgWindow, streamSupport, msgKey, false,
aURL);
// clang-format on
nsCOMPtr<nsIURI> dummyURI;
rv =
FetchMessage(imapUrl, imapAction, folder, imapMessageSink, aMsgWindow,
streamSupport, msgKey, false, getter_AddRefs(dummyURI));
} // if we got an imap message sink
} // if we decomposed the imap message
return rv;

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

@ -93,16 +93,14 @@ add_task(async function selectInboxMsg() {
].getService(Ci.nsIMsgMessageService);
let db = IMAPPump.inbox.msgDatabase;
let msg1 = db.getMsgHdrForMessageID(gMsgId1);
let url = {};
let streamListener = new PromiseTestUtils.PromiseStreamListener();
let urlListener = new PromiseTestUtils.PromiseUrlListener();
imapService.DisplayMessage(
imapService.loadMessage(
IMAPPump.inbox.getUriForMsg(msg1),
streamListener,
null,
urlListener,
null,
url
false
);
await urlListener.promise;
});
@ -165,16 +163,14 @@ add_task(async function selectFooMsg() {
"@mozilla.org/messenger/messageservice;1?type=imap"
].getService(Ci.nsIMsgMessageService);
let msg1 = fooFolder.msgDatabase.getMsgHdrForMessageID(gMsgId2);
let url = {};
let streamListener = new PromiseTestUtils.PromiseStreamListener();
let urlListener = new PromiseTestUtils.PromiseUrlListener();
imapService.DisplayMessage(
imapService.loadMessage(
fooFolder.getUriForMsg(msg1),
streamListener,
null,
urlListener,
null,
url
false
);
await urlListener.promise;
});

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

@ -86,7 +86,6 @@ add_task(async function selectFirstMsg() {
let db = IMAPPump.inbox.msgDatabase;
let msg1 = db.getMsgHdrForMessageID(gMsgId1);
let url = {};
let listener = new PromiseTestUtils.PromiseUrlListener({
OnStopRunningUrl: (aUrl, aExitCode) => {
Assert.equal(aExitCode, 0);
@ -94,13 +93,12 @@ add_task(async function selectFirstMsg() {
});
// We use the streamListener as a display consumer.
let streamListener = new PromiseTestUtils.PromiseStreamListener();
gIMAPService.DisplayMessage(
gIMAPService.loadMessage(
IMAPPump.inbox.getUriForMsg(msg1),
streamListener,
null,
listener,
null,
url
false
);
await listener.promise;
});
@ -110,7 +108,6 @@ add_task(async function select2ndMsg() {
Assert.notEqual(msg1.flags & Ci.nsMsgMessageFlags.Offline, 0);
let db = IMAPPump.inbox.msgDatabase;
let msg2 = db.getMsgHdrForMessageID(gMsgId2);
let url = {};
let listener = new PromiseTestUtils.PromiseUrlListener({
OnStopRunningUrl: (aUrl, aExitCode) => {
Assert.equal(aExitCode, 0);
@ -118,13 +115,12 @@ add_task(async function select2ndMsg() {
});
// We use the streamListener as a display consumer.
let streamListener = new PromiseTestUtils.PromiseStreamListener();
gIMAPService.DisplayMessage(
gIMAPService.loadMessage(
IMAPPump.inbox.getUriForMsg(msg2),
streamListener,
null,
listener,
null,
url
false
);
await listener.promise;
});
@ -134,17 +130,15 @@ add_task(async function select3rdMsg() {
Assert.notEqual(msg2.flags & Ci.nsMsgMessageFlags.Offline, 0);
let db = IMAPPump.inbox.msgDatabase;
let msg3 = db.getMsgHdrForMessageID(gMsgId3);
let url = {};
let listener = new PromiseTestUtils.PromiseUrlListener();
// We use the streamListener as a display consumer.
let streamListener = new PromiseTestUtils.PromiseStreamListener();
gIMAPService.DisplayMessage(
gIMAPService.loadMessage(
IMAPPump.inbox.getUriForMsg(msg3),
streamListener,
null,
listener,
null,
url
false
);
await listener.promise;
});

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

@ -2540,10 +2540,8 @@ nsresult nsMsgLocalMailFolder::CopyMessageTo(nsISupports* message,
nsCOMPtr<nsIStreamListener> streamListener(
do_QueryInterface(copyStreamListener, &rv));
NS_ENSURE_SUCCESS(rv, NS_ERROR_NO_INTERFACE);
nsCOMPtr<nsIURI> dummyNull;
rv = mCopyState->m_messageService->CopyMessage(uri, streamListener, isMove,
nullptr, aMsgWindow,
getter_AddRefs(dummyNull));
nullptr, aMsgWindow);
}
return rv;
}

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

@ -86,12 +86,13 @@ nsresult nsMailboxService::CopyMessage(const nsACString& aSrcMailboxURI,
nsIStreamListener* aMailboxCopyHandler,
bool moveMessage,
nsIUrlListener* aUrlListener,
nsIMsgWindow* aMsgWindow,
nsIURI** aURL) {
nsIMsgWindow* aMsgWindow) {
nsMailboxAction mailboxAction = nsIMailboxUrl::ActionMoveMessage;
nsCOMPtr<nsIURI> aURL; // unused...
if (!moveMessage) mailboxAction = nsIMailboxUrl::ActionCopyMessage;
return FetchMessage(aSrcMailboxURI, aMailboxCopyHandler, aMsgWindow,
aUrlListener, nullptr, mailboxAction, false, aURL);
aUrlListener, nullptr, mailboxAction, false,
getter_AddRefs(aURL));
}
nsresult nsMailboxService::CopyMessages(
@ -232,15 +233,15 @@ NS_IMETHODIMP nsMailboxService::FetchMimePart(
return RunMailboxUrl(msgUrl, aDisplayConsumer);
}
NS_IMETHODIMP nsMailboxService::DisplayMessage(const nsACString& aMessageURI,
nsISupports* aDisplayConsumer,
nsIMsgWindow* aMsgWindow,
nsIUrlListener* aUrlListener,
bool aOverideCharset,
nsIURI** aURL) {
NS_IMETHODIMP nsMailboxService::LoadMessage(const nsACString& aMessageURI,
nsISupports* aDisplayConsumer,
nsIMsgWindow* aMsgWindow,
nsIUrlListener* aUrlListener,
bool aOverideCharset) {
nsCOMPtr<nsIURI> aURL; // unused...
return FetchMessage(aMessageURI, aDisplayConsumer, aMsgWindow, aUrlListener,
nullptr, nsIMailboxUrl::ActionFetchMessage,
aOverideCharset, aURL);
aOverideCharset, getter_AddRefs(aURL));
}
NS_IMETHODIMP

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

@ -32,15 +32,14 @@ class BaseMessageService {
_logger = lazy.NntpUtils.logger;
/** @see nsIMsgMessageService */
DisplayMessage(
loadMessage(
messageURI,
displayConsumer,
msgWindow,
urlListener,
autodetectCharset,
outURL
autodetectCharset
) {
this._logger.debug("DisplayMessage", messageURI);
this._logger.debug("loadMessage", messageURI);
let uri = this.getUrlForUri(messageURI, msgWindow);
if (urlListener) {
@ -74,23 +73,9 @@ class BaseMessageService {
return folder?.GetMessageHeader(key);
}
CopyMessage(
messageUri,
copyListener,
moveMessage,
urlListener,
msgWindow,
outUrl
) {
this._logger.debug("CopyMessage", messageUri);
this.DisplayMessage(
messageUri,
copyListener,
msgWindow,
urlListener,
false,
outUrl
);
copyMessage(messageUri, copyListener, moveMessage, urlListener, msgWindow) {
this._logger.debug("copyMessage", messageUri);
this.loadMessage(messageUri, copyListener, msgWindow, urlListener, false);
}
SaveMessageToDisk(
@ -116,7 +101,7 @@ class BaseMessageService {
url.msgIsInLocalCache = folder.hasMsgOffline(key);
}
this.DisplayMessage(
this.loadMessage(
messageUri,
url.getSaveAsListener(addDummyEnvelope, file),
msgWindow,
@ -147,7 +132,7 @@ class BaseMessageService {
streamMessage(messageUri, consumer, msgWindow, urlListener, convertData) {
this._logger.debug("streamMessage", messageUri);
this.DisplayMessage(messageUri, consumer, msgWindow, urlListener, false);
this.loadMessage(messageUri, consumer, msgWindow, urlListener, false);
}
/**
@ -214,13 +199,7 @@ class BaseMessageService {
/** @see nsIMsgMessageFetchPartService */
fetchMimePart(uri, messageUri, displayConsumer, msgWindow, urlListener) {
this._logger.debug("fetchMimePart", uri.spec);
this.DisplayMessage(
uri.spec,
displayConsumer,
msgWindow,
urlListener,
false
);
this.loadMessage(uri.spec, displayConsumer, msgWindow, urlListener, false);
}
}

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

@ -4,7 +4,7 @@ const { PromiseTestUtils } = ChromeUtils.import(
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
);
add_task(async function testDisplayMessage() {
add_task(async function testloadMessage() {
let daemon = setupNNTPDaemon();
daemon.addGroup("dot.test");
daemon.addArticle(make_article(do_get_file("postings/post3.eml")));
@ -32,7 +32,7 @@ add_task(async function testDisplayMessage() {
// displayed directly and simultaneously saved in the offline storage.
{
let listener = new PromiseTestUtils.PromiseStreamListener();
msgService.DisplayMessage(uri, listener, null, null, null, {});
msgService.loadMessage(uri, listener, null, null, false);
let msgText = await listener.promise;
localserver.closeCachedConnections();
@ -46,7 +46,7 @@ add_task(async function testDisplayMessage() {
// In the second run, the offline store serves as the source of the article.
{
let listener = new PromiseTestUtils.PromiseStreamListener();
msgService.DisplayMessage(uri, listener, null, null, null, {});
msgService.loadMessage(uri, listener, null, null, false);
let msgText = await listener.promise;
localserver.closeCachedConnections();

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

@ -33,7 +33,7 @@ add_task(async function test403242() {
// Pretend to display the message
let listener = new PromiseTestUtils.PromiseStreamListener();
msgService.DisplayMessage(uri, listener, null, null, null, {});
msgService.loadMessage(uri, listener, null, null, false);
let msgText = await listener.promise;
localserver.closeCachedConnections();
server.stop();

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

@ -98,7 +98,7 @@ function run_test() {
Cc["@mozilla.org/messenger/messageservice;1?type=news"]
.getService(Ci.nsIMsgMessageService)
.DisplayMessage(messageUri, streamListener, null, null, null, {});
.loadMessage(messageUri, streamListener, null, null, false);
// Get the server to run
server.performTest();

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

@ -2,7 +2,7 @@
/*
* Tests:
* - getNewMessages for a newsgroup folder (single message).
* - DisplayMessage for a newsgroup message
* - loadMessage for a newsgroup message
* - Downloading a single message and checking content in stream is correct.
*/
@ -93,7 +93,7 @@ function run_test() {
Cc["@mozilla.org/messenger/messageservice;1?type=news"]
.getService(Ci.nsIMsgMessageService)
.DisplayMessage(messageUri, streamListener, null, null, null, {});
.loadMessage(messageUri, streamListener, null, null, false);
} catch (e) {
server.stop();
do_throw(e);