Bug 1733849 - Use nsIMsgFolder.getSlicedOfflineFileStream() instead of getOfflineFileStream(). r=mkmelin
This is an intermediate step. We want to get all the message-reading code working with streams that contain just a single message, rather than with an unwieldly mbox stream + offset/size combo. Then we'll remove getOfflineFileStream() entirely and rename getSlicedOfflineFileStream() to replace it. Differential Revision: https://phabricator.services.mozilla.com/D127372
This commit is contained in:
Родитель
651805cbdc
Коммит
f4bc63cba0
|
@ -8454,10 +8454,7 @@ NS_IMETHODIMP nsImapMailFolder::FetchMsgPreviewText(
|
|||
nsMsgKey msgKey;
|
||||
msgHdr->GetMessageKey(&msgKey);
|
||||
if (msgFlags & nsMsgMessageFlags::Offline) {
|
||||
int64_t messageOffset;
|
||||
uint32_t messageSize;
|
||||
rv = GetOfflineFileStream(msgKey, &messageOffset, &messageSize,
|
||||
getter_AddRefs(inputStream));
|
||||
rv = GetSlicedOfflineFileStream(msgKey, getter_AddRefs(inputStream));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = GetMsgPreviewTextFromStream(msgHdr, inputStream);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
@ -8845,10 +8842,12 @@ NS_IMETHODIMP nsImapMailFolder::GetOfflineFileStream(
|
|||
rv = GetDatabase();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (offlineFolder == this)
|
||||
if (offlineFolder == this) {
|
||||
return nsMsgDBFolder::GetOfflineFileStream(msgKey, offset, size,
|
||||
aFileStream);
|
||||
}
|
||||
|
||||
// The message we want is stored in a different folder (hackery for gmail).
|
||||
nsCOMPtr<nsIMsgDBHdr> hdr;
|
||||
rv = mDatabase->GetMsgHdrForKey(msgKey, getter_AddRefs(hdr));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
|
|
@ -9685,29 +9685,19 @@ bool nsImapMockChannel::ReadFromLocalCache() {
|
|||
return false;
|
||||
}
|
||||
// we want to create a file channel and read the msg from there.
|
||||
nsCOMPtr<nsIInputStream> fileStream;
|
||||
nsMsgKey msgKey = strtoul(messageIdString.get(), nullptr, 10);
|
||||
uint32_t size;
|
||||
int64_t offset;
|
||||
rv = folder->GetOfflineFileStream(msgKey, &offset, &size,
|
||||
getter_AddRefs(fileStream));
|
||||
nsCOMPtr<nsIInputStream> msgStream;
|
||||
rv = folder->GetSlicedOfflineFileStream(msgKey, getter_AddRefs(msgStream));
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
// get the file channel from the folder, somehow (through the message or
|
||||
// folder sink?) We also need to set the transfer offset to the message
|
||||
// offset
|
||||
// dougt - This may break the ablity to "cancel" a read from offline
|
||||
// mail reading. fileChannel->SetLoadGroup(m_loadGroup);
|
||||
RefPtr<nsImapCacheStreamListener> cacheListener =
|
||||
new nsImapCacheStreamListener();
|
||||
cacheListener->Init(m_channelListener, this);
|
||||
|
||||
// create a stream pump that will async read the specified amount of
|
||||
// data.
|
||||
// XXX make size 64-bit int
|
||||
RefPtr<SlicedInputStream> slicedStream = new SlicedInputStream(
|
||||
fileStream.forget(), uint64_t(offset), uint64_t(size));
|
||||
// create a stream pump that will async read the message.
|
||||
nsCOMPtr<nsIInputStreamPump> pump;
|
||||
rv = NS_NewInputStreamPump(getter_AddRefs(pump), slicedStream.forget());
|
||||
rv = NS_NewInputStreamPump(getter_AddRefs(pump), msgStream.forget());
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
rv = pump->AsyncRead(cacheListener);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
|
|
|
@ -1175,10 +1175,7 @@ NS_IMETHODIMP nsImapService::StreamHeaders(const char* aMessageURI,
|
|||
bool hasMsgOffline = false;
|
||||
folder->HasMsgOffline(key, &hasMsgOffline);
|
||||
if (hasMsgOffline) {
|
||||
int64_t messageOffset;
|
||||
uint32_t messageSize;
|
||||
rv = folder->GetOfflineFileStream(key, &messageOffset, &messageSize,
|
||||
getter_AddRefs(inputStream));
|
||||
rv = folder->GetSlicedOfflineFileStream(key, getter_AddRefs(inputStream));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return MsgStreamMsgHeaders(inputStream, aConsumer);
|
||||
}
|
||||
|
|
|
@ -59,8 +59,6 @@ function addGeneratedMessagesToServer(messages, mailbox) {
|
|||
|
||||
function checkOfflineStore(prevOfflineStoreSize) {
|
||||
dump("checking offline store\n");
|
||||
let offset = {};
|
||||
let size = {};
|
||||
let enumerator = IMAPPump.inbox.msgDatabase.EnumerateMessages();
|
||||
if (enumerator) {
|
||||
for (let header of enumerator) {
|
||||
|
@ -70,9 +68,7 @@ function checkOfflineStore(prevOfflineStoreSize) {
|
|||
header instanceof Ci.nsIMsgDBHdr &&
|
||||
header.flags & Ci.nsMsgMessageFlags.Offline
|
||||
) {
|
||||
IMAPPump.inbox
|
||||
.getOfflineFileStream(header.messageKey, offset, size)
|
||||
.close();
|
||||
IMAPPump.inbox.getSlicedOfflineFileStream(header.messageKey).close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,17 +53,13 @@ async function downloadAllForOffline() {
|
|||
|
||||
function verifyDownloaded() {
|
||||
// verify that the message headers have the offline flag set.
|
||||
let offset = {};
|
||||
let size = {};
|
||||
for (let header of IMAPPump.inbox.msgDatabase.EnumerateMessages()) {
|
||||
// Verify that each message has been downloaded and looks OK.
|
||||
if (
|
||||
header instanceof Ci.nsIMsgDBHdr &&
|
||||
header.flags & Ci.nsMsgMessageFlags.Offline
|
||||
) {
|
||||
IMAPPump.inbox
|
||||
.getOfflineFileStream(header.messageKey, offset, size)
|
||||
.close();
|
||||
IMAPPump.inbox.getSlicedOfflineFileStream(header.messageKey).close();
|
||||
} else {
|
||||
do_throw("Message not downloaded for offline use");
|
||||
}
|
||||
|
|
|
@ -123,8 +123,6 @@ function* check_result() {
|
|||
Assert.ok(offlineStoreSize > gOfflineStoreSize);
|
||||
|
||||
// Verify that the message headers have the offline flag set.
|
||||
let offset = {};
|
||||
let size = {};
|
||||
for (let header of IMAPPump.inbox.msgDatabase.EnumerateMessages()) {
|
||||
// Verify that each message has been downloaded and looks OK.
|
||||
if (
|
||||
|
@ -136,10 +134,8 @@ function* check_result() {
|
|||
do_throw("Message not downloaded for offline use");
|
||||
}
|
||||
|
||||
IMAPPump.inbox
|
||||
.getOfflineFileStream(header.messageKey, offset, size)
|
||||
.close();
|
||||
info("Msg hdr offset = " + offset.value);
|
||||
// Make sure we don't fall over if we ask to read the message.
|
||||
IMAPPump.inbox.getSlicedOfflineFileStream(header.messageKey).close();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -139,8 +139,7 @@ nsresult nsMailboxService::FetchMessage(
|
|||
const char* aMessageURI, nsISupports* aDisplayConsumer,
|
||||
nsIMsgWindow* aMsgWindow, nsIUrlListener* aUrlListener,
|
||||
const char* aFileName, /* only used by open attachment... */
|
||||
nsMailboxAction mailboxAction, bool aOverrideCharset,
|
||||
nsIURI** aURL) {
|
||||
nsMailboxAction mailboxAction, bool aOverrideCharset, nsIURI** aURL) {
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsIMailboxUrl> mailboxurl;
|
||||
nsMailboxAction actionToUse = mailboxAction;
|
||||
|
@ -274,8 +273,7 @@ nsMailboxService::StreamMessage(const char* aMessageURI, nsISupports* aConsumer,
|
|||
}
|
||||
|
||||
return FetchMessage(aURIString.get(), aConsumer, aMsgWindow, aUrlListener,
|
||||
nullptr, nsIMailboxUrl::ActionFetchMessage, false,
|
||||
aURL);
|
||||
nullptr, nsIMailboxUrl::ActionFetchMessage, false, aURL);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMailboxService::StreamHeaders(const char* aMessageURI,
|
||||
|
@ -292,10 +290,7 @@ NS_IMETHODIMP nsMailboxService::StreamHeaders(const char* aMessageURI,
|
|||
if (msgKey == nsMsgKey_None) return NS_MSG_MESSAGE_NOT_FOUND;
|
||||
|
||||
nsCOMPtr<nsIInputStream> inputStream;
|
||||
int64_t messageOffset;
|
||||
uint32_t messageSize;
|
||||
rv = folder->GetOfflineFileStream(msgKey, &messageOffset, &messageSize,
|
||||
getter_AddRefs(inputStream));
|
||||
rv = folder->GetSlicedOfflineFileStream(msgKey, getter_AddRefs(inputStream));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return MsgStreamMsgHeaders(inputStream, aConsumer);
|
||||
}
|
||||
|
|
|
@ -650,58 +650,51 @@ nsresult nsNNTPProtocol::ReadFromNewsConnection() {
|
|||
// download because this method does the rest of the work.
|
||||
bool nsNNTPProtocol::ReadFromLocalCache() {
|
||||
bool msgIsInLocalCache = false;
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsIMsgMailNewsUrl> mailnewsUrl = do_QueryInterface(m_runningURL);
|
||||
mailnewsUrl->GetMsgIsInLocalCache(&msgIsInLocalCache);
|
||||
|
||||
if (msgIsInLocalCache) {
|
||||
nsCOMPtr<nsIMsgFolder> folder = do_QueryInterface(m_newsFolder);
|
||||
if (folder && NS_SUCCEEDED(rv)) {
|
||||
// we want to create a file channel and read the msg from there.
|
||||
nsCOMPtr<nsIInputStream> fileStream;
|
||||
int64_t offset = 0;
|
||||
uint32_t size = 0;
|
||||
rv = folder->GetOfflineFileStream(m_key, &offset, &size,
|
||||
getter_AddRefs(fileStream));
|
||||
if (!msgIsInLocalCache) {
|
||||
return false;
|
||||
}
|
||||
nsCOMPtr<nsIMsgFolder> folder = do_QueryInterface(m_newsFolder);
|
||||
MOZ_ASSERT(folder);
|
||||
|
||||
// get the file stream from the folder, somehow (through the message or
|
||||
// folder sink?) We also need to set the transfer offset to the message
|
||||
// offset
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// dougt - This may break the ablity to "cancel" a read from offline
|
||||
// mail reading. fileChannel->SetLoadGroup(m_loadGroup);
|
||||
// Attempt to get locally-stored message.
|
||||
nsCOMPtr<nsIInputStream> msgStream;
|
||||
nsresult rv =
|
||||
folder->GetSlicedOfflineFileStream(m_key, getter_AddRefs(msgStream));
|
||||
|
||||
m_typeWanted = ARTICLE_WANTED;
|
||||
|
||||
RefPtr<nsNntpCacheStreamListener> cacheListener =
|
||||
new nsNntpCacheStreamListener();
|
||||
|
||||
cacheListener->Init(m_channelListener, static_cast<nsIChannel*>(this),
|
||||
mailnewsUrl);
|
||||
|
||||
// create a stream pump that will async read the specified amount of
|
||||
// data.
|
||||
// XXX make size 64-bit int
|
||||
RefPtr<SlicedInputStream> slicedStream = new SlicedInputStream(
|
||||
fileStream.forget(), uint64_t(offset), uint64_t(size));
|
||||
nsCOMPtr<nsIInputStreamPump> pump;
|
||||
rv = NS_NewInputStreamPump(getter_AddRefs(pump), slicedStream.forget());
|
||||
if (NS_SUCCEEDED(rv)) rv = pump->AsyncRead(cacheListener);
|
||||
|
||||
if (NS_SUCCEEDED(rv)) // ONLY if we succeeded in actually starting the
|
||||
// read should we return
|
||||
{
|
||||
mContentType.Truncate();
|
||||
m_channelListener = nullptr;
|
||||
NNTP_LOG_NOTE("Loading message from offline storage");
|
||||
return true;
|
||||
}
|
||||
} else
|
||||
mailnewsUrl->SetMsgIsInLocalCache(false);
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
mailnewsUrl->SetMsgIsInLocalCache(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
// dougt - This may break the ablity to "cancel" a read from offline
|
||||
// mail reading. fileChannel->SetLoadGroup(m_loadGroup);
|
||||
|
||||
m_typeWanted = ARTICLE_WANTED;
|
||||
|
||||
RefPtr<nsNntpCacheStreamListener> cacheListener =
|
||||
new nsNntpCacheStreamListener();
|
||||
|
||||
cacheListener->Init(m_channelListener, static_cast<nsIChannel*>(this),
|
||||
mailnewsUrl);
|
||||
|
||||
// Create a stream pump that will async read the message.
|
||||
nsCOMPtr<nsIInputStreamPump> pump;
|
||||
rv = NS_NewInputStreamPump(getter_AddRefs(pump), msgStream.forget());
|
||||
if (NS_SUCCEEDED(rv)) rv = pump->AsyncRead(cacheListener);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
mailnewsUrl->SetMsgIsInLocalCache(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Started streaming the offline copy, so we're done.
|
||||
mContentType.Truncate();
|
||||
m_channelListener = nullptr;
|
||||
NNTP_LOG_NOTE("Loading message from offline storage");
|
||||
return true;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -1422,10 +1422,8 @@ NS_IMETHODIMP nsNntpService::StreamHeaders(const char* aMessageURI,
|
|||
bool hasMsgOffline = false;
|
||||
folder->HasMsgOffline(key, &hasMsgOffline);
|
||||
if (hasMsgOffline) {
|
||||
int64_t messageOffset;
|
||||
uint32_t messageSize;
|
||||
nsresult rv = folder->GetOfflineFileStream(
|
||||
key, &messageOffset, &messageSize, getter_AddRefs(inputStream));
|
||||
nsresult rv =
|
||||
folder->GetSlicedOfflineFileStream(key, getter_AddRefs(inputStream));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return MsgStreamMsgHeaders(inputStream, aConsumer);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче