make backend base and db [noscript] methods scriptable, bug 661682, r=rkent, sr=standard8

This commit is contained in:
David Bienvenu 2011-06-24 16:58:10 -07:00
Родитель 1854317b2d
Коммит 3b505900f0
32 изменённых файлов: 518 добавлений и 251 удалений

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

@ -67,6 +67,7 @@ XPIDLSRCS = \
nsIMsgFolderCompactor.idl \
nsIMsgIdentity.idl \
nsIMsgIncomingServer.idl \
nsIMsgKeyArray.idl \
nsIMsgMailSession.idl \
nsIMsgMessageService.idl \
nsIMsgTagService.idl \

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

@ -37,18 +37,12 @@
#include "nsISupports.idl"
%{C++
#include "MailNewsTypes.h"
%}
#include "MailNewsTypes2.idl"
[ptr] native octetPtr(PRUint8);
interface nsIMsgFolder;
interface nsIUTF8StringEnumerator;
[scriptable, uuid(574611fe-f170-4eb4-a30c-a26e2c62703a)]
[scriptable, uuid(36adf826-73f4-48e7-a444-318242ea8a8e)]
interface nsIMsgDBHdr : nsISupports
{
/* general property routines - I think this can retrieve any
@ -119,10 +113,13 @@ interface nsIMsgDBHdr : nsISupports
readonly attribute AString mime2DecodedSubject;
readonly attribute AString mime2DecodedRecipients;
[noscript] void getAuthorCollationKey(out octetPtr key, out unsigned long len);
[noscript] void getSubjectCollationKey(out octetPtr key, out unsigned long len);
[noscript] void getRecipientsCollationKey(out octetPtr key, out unsigned long len);
void getAuthorCollationKey(out unsigned long aCount,
[array, size_is(aCount)] out octet aKey);
void getSubjectCollationKey(out unsigned long aCount,
[array, size_is(aCount)] out octet aKey);
void getRecipientsCollationKey(out unsigned long aCount,
[array, size_is(aCount)] out octet aKey);
attribute string Charset;
attribute nsMsgLabelValue label;
attribute string accountKey;

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

@ -0,0 +1,81 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* David Bienvenu <bienvenu@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
* This interface wraps an nsTArray<nsMsgKey> so that we can pass arrays
* back and forth between c++ and js (or via xpconnect generally).
*/
#include "nsISupports.idl"
#include "MailNewsTypes2.idl"
[scriptable, uuid(e8fcaada-64b7-4e39-9f1d-10ddb0f1de64)]
interface nsIMsgKeyArray : nsISupports {
/**
* Get the key at the specified 0-based array index.
*
* @param aIndex 0-based index.
* @returns key at the specified index.
*/
nsMsgKey getKeyAt(in long aIndex);
readonly attribute unsigned long length;
void setCapacity(in unsigned long aCapacity);
/**
* Adds a key to the end of the array
* @param key to append to the array.
*/
void appendElement(in nsMsgKey aMsgKey);
/**
* Sort the array by key.
*/
void sort();
/**
* Retrieves the entire array in such a way that xpconnect can easily
* create a js array of the keys.
*
* @returns array of the keys
*/
void getArray(out unsigned long aCount,
[array, size_is(aCount)] out nsMsgKey aKeys);
};

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

@ -36,7 +36,7 @@
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
#include "MailNewsTypes2.idl"
interface nsIURI;
interface nsIUrlListener;
interface nsIStreamListener;
@ -50,13 +50,9 @@ interface nsICacheEntryDescriptor;
%{C++
#include "MailNewsTypes.h"
#include "nsTArray.h"
%}
[ref] native nsMsgKeyArrayRef(nsTArray<nsMsgKey>);
[scriptable, uuid(5f173e8d-0046-4eec-b178-b850a7211654)]
[scriptable, uuid(ac7b56c2-cf42-4ee3-a3b1-9ae64a90861c)]
interface nsIMsgMessageService : nsISupports {
/**
@ -91,10 +87,15 @@ interface nsIMsgMessageService : nsISupports {
* @param aMoveMessage
* @param aUrlListener
* @param aMsgWindow
* @param aURL
* @returns URI that's run to perform the copy
*/
[noscript] void CopyMessages(in nsMsgKeyArrayRef keys, in nsIMsgFolder srcFolder, in nsIStreamListener aCopyListener, in boolean aMoveMessage,
in nsIUrlListener aUrlListener, in nsIMsgWindow aMsgWindow, out nsIURI aURL);
nsIURI CopyMessages(in unsigned long aNumKeys,
[array, size_is (aNumKeys)] in nsMsgKey aKeys,
in nsIMsgFolder srcFolder,
in nsIStreamListener aCopyListener,
in boolean aMoveMessage,
in nsIUrlListener aUrlListener,
in nsIMsgWindow aMsgWindow);
/**

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

@ -283,6 +283,17 @@
{ 0xbd85a417, 0x5433, 0x11d3, \
{0x8a, 0xc5, 0x0, 0x60, 0xb0, 0xfc, 0x4, 0xd2} }
//
// nsMsgKeyArray
//
#define NS_MSGKEYARRAY_CONTRACTID \
"@mozilla.org/messenger/msgkeyarray;1"
/* 86989d1d-c8a1-4e8e-aae6-d0dabcacd8c2 */
#define NS_MSGKEYARRAY_CID \
{ 0x86989d1d, 0xc8a1, 0x4e8e, \
{0xaa, 0xe6, 0xd0, 0xda, 0xbc, 0xac, 0xd8, 0xc2 }}
//
//nsMsgWindow
//

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

@ -3765,7 +3765,8 @@ nsMsgDBView::FnSortIdKey(const void *pItem1, const void *pItem2, void *privateDa
nsIMsgDatabase *db = sortInfo->db;
rv = db->CompareCollationKeys((*p1)->key, (*p1)->dword, (*p2)->key, (*p2)->dword, &retVal);
rv = db->CompareCollationKeys((*p1)->dword, (*p1)->key, (*p2)->dword,
(*p2)->key, &retVal);
NS_ASSERTION(NS_SUCCEEDED(rv),"compare failed");
if (retVal)
@ -3790,7 +3791,8 @@ nsMsgDBView::FnSortIdKeyPtr(const void *pItem1, const void *pItem2, void *privat
nsIMsgDatabase *db = sortInfo->db;
rv = db->CompareCollationKeys((*p1)->key, (*p1)->dword, (*p2)->key, (*p2)->dword, &retVal);
rv = db->CompareCollationKeys((*p1)->dword, (*p1)->key, (*p2)->dword,
(*p2)->key, &retVal);
NS_ASSERTION(NS_SUCCEEDED(rv),"compare failed");
if (retVal)
@ -4122,16 +4124,16 @@ nsMsgDBView::GetCollationKey(nsIMsgDBHdr *msgHdr, nsMsgViewSortTypeValue sortTyp
switch (sortType)
{
case nsMsgViewSortType::bySubject:
rv = msgHdr->GetSubjectCollationKey(result, len);
rv = msgHdr->GetSubjectCollationKey(len, result);
break;
case nsMsgViewSortType::byLocation:
rv = GetLocationCollationKey(msgHdr, result, len);
break;
case nsMsgViewSortType::byRecipient:
rv = msgHdr->GetRecipientsCollationKey(result, len);
rv = msgHdr->GetRecipientsCollationKey(len, result);
break;
case nsMsgViewSortType::byAuthor:
rv = msgHdr->GetAuthorCollationKey(result, len);
rv = msgHdr->GetAuthorCollationKey(len, result);
break;
case nsMsgViewSortType::byAccount:
case nsMsgViewSortType::byTags:
@ -4147,7 +4149,7 @@ nsMsgDBView::GetCollationKey(nsIMsgDBHdr *msgHdr, nsMsgViewSortTypeValue sortTyp
: FetchTags(msgHdr, str);
if (NS_SUCCEEDED(rv) && dbToUse)
rv = dbToUse->CreateCollationKey(str, result, len);
rv = dbToUse->CreateCollationKey(str, len, result);
}
break;
case nsMsgViewSortType::byCustom:
@ -4164,7 +4166,7 @@ nsMsgDBView::GetCollationKey(nsIMsgDBHdr *msgHdr, nsMsgViewSortTypeValue sortTyp
rv = GetDBForHeader(msgHdr, getter_AddRefs(dbToUse));
NS_ENSURE_SUCCESS(rv,rv);
}
rv = dbToUse->CreateCollationKey(strKey, result, len);
rv = dbToUse->CreateCollationKey(strKey, len, result);
}
else
{
@ -4205,7 +4207,7 @@ nsMsgDBView::GetLocationCollationKey(nsIMsgDBHdr *msgHdr, PRUint8 **result, PRUi
rv = folder->GetPrettiestName(locationString);
NS_ENSURE_SUCCESS(rv,rv);
return dbToUse->CreateCollationKey(locationString, result, len);
return dbToUse->CreateCollationKey(locationString, len, result);
}
nsresult nsMsgDBView::SaveSortInfo(nsMsgViewSortTypeValue sortType, nsMsgViewSortOrderValue sortOrder)

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

@ -38,6 +38,7 @@
#include "msgCore.h" // precompiled header...
#include "nsCOMPtr.h"
#include "nsIMsgFolder.h"
#include "nsAutoPtr.h"
#include "nsILocalFile.h"
#include "nsNetUtil.h"
#include "nsIMsgHdr.h"
@ -48,7 +49,6 @@
#include "nsISeekableStream.h"
#include "nsIDBFolderInfo.h"
#include "nsIDocShell.h"
#include "nsMsgFolderCompactor.h"
#include "nsIPrompt.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIMsgLocalMailFolder.h"
@ -63,6 +63,7 @@
#include "nsIMsgStatusFeedback.h"
#include "nsMsgBaseCID.h"
#include "nsIMsgFolderNotificationService.h"
#include "nsMsgFolderCompactor.h"
//////////////////////////////////////////////////////////////////////////////
// nsFolderCompactState
@ -88,7 +89,6 @@ nsFolderCompactState::nsFolderCompactState()
nsFolderCompactState::~nsFolderCompactState()
{
CloseOutputStream();
if (NS_FAILED(m_status))
{
CleanupTempFilesAfterError();
@ -130,9 +130,10 @@ nsresult
nsFolderCompactState::InitDB(nsIMsgDatabase *db)
{
nsCOMPtr<nsIMsgDatabase> mailDBFactory;
nsresult rv = db->ListAllKeys(m_keyArray);
NS_ENSURE_SUCCESS(rv, rv);
m_size = m_keyArray->m_keys.Length();
db->ListAllKeys(m_keyArray);
nsresult rv;
nsCOMPtr<nsIMsgDBService> msgDBService = do_GetService(NS_MSGDB_SERVICE_CONTRACTID, &rv);
if (msgDBService)
{
@ -302,7 +303,8 @@ nsFolderCompactState::Init(nsIMsgFolder *folder, const char *baseMsgUri, nsIMsgD
m_file->SetNativeLeafName(NS_LITERAL_CSTRING("nstmp"));
m_file->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 00600); //make sure we are not crunching existing nstmp file
m_window = aMsgWindow;
m_keyArray.Clear();
m_keyArray = new nsMsgKeyArray;
m_size = 0;
m_totalMsgSize = 0;
rv = InitDB(db);
if (NS_FAILED(rv))
@ -311,9 +313,8 @@ nsFolderCompactState::Init(nsIMsgFolder *folder, const char *baseMsgUri, nsIMsgD
return rv;
}
m_size = m_keyArray.Length();
m_curIndex = 0;
rv = MsgNewBufferedFileOutputStream(getter_AddRefs(m_fileStream), m_file, -1, 00600);
if (NS_FAILED(rv))
m_folder->ThrowAlertMsg("compactFolderWriteFailed", m_window);
@ -380,12 +381,13 @@ nsresult nsFolderCompactState::StartCompacting()
nsnull);
if (m_size > 0)
{
nsCOMPtr<nsIURI> notUsed;
ShowCompactingStatusMsg();
AddRef();
rv = m_messageService->CopyMessages(m_keyArray, m_folder, this, PR_FALSE, nsnull, m_window, nsnull);
// m_curIndex = m_size; // advance m_curIndex to the end - we're done
rv = m_messageService->CopyMessages(m_size, m_keyArray->m_keys.Elements(),
m_folder, this,
PR_FALSE, nsnull, m_window,
getter_AddRefs(notUsed));
}
else
{ // no messages to copy with
@ -666,7 +668,7 @@ nsFolderCompactState::OnDataAvailable(nsIRequest *request, nsISupports *ctxt,
m_statusOffset = 0;
m_addedHeaderSize = 0;
m_messageUri.Truncate(); // clear the previous message uri
if (NS_SUCCEEDED(BuildMessageURI(m_baseMessageUri.get(), m_keyArray[m_curIndex],
if (NS_SUCCEEDED(BuildMessageURI(m_baseMessageUri.get(), m_keyArray->m_keys[m_curIndex],
m_messageUri)))
{
rv = GetMessage(getter_AddRefs(m_curSrcHdr));
@ -887,27 +889,8 @@ nsOfflineStoreCompactState::InitDB(nsIMsgDatabase *db)
{
// Start with the list of messages we have offline as the possible
// message to keep when compacting the offline store.
db->ListAllOfflineMsgs(&m_keyArray);
// Filter out msgs that have the "pendingRemoval" attribute set.
nsCOMPtr<nsIMsgDBHdr> hdr;
nsString pendingRemoval;
for (PRInt32 i = m_keyArray.Length() - 1; i >= 0; i--)
{
nsresult rv = db->GetMsgHdrForKey(m_keyArray[i], getter_AddRefs(hdr));
NS_ENSURE_SUCCESS(rv, rv);
hdr->GetProperty("pendingRemoval", pendingRemoval);
if (!pendingRemoval.IsEmpty())
{
m_keyArray.RemoveElementAt(i);
// Turn off offline flag for message, since after the compact is completed;
// we won't have the message in the offline store.
PRUint32 resultFlags;
hdr->AndFlags(~nsMsgMessageFlags::Offline, &resultFlags);
// We need to clear this in case the user changes the offline retention
// settings.
hdr->SetStringProperty("pendingRemoval", "");
}
}
db->ListAllOfflineMsgs(m_keyArray);
m_size = m_keyArray->m_keys.Length();
m_db = db;
return NS_OK;
}
@ -921,8 +904,26 @@ nsresult nsOfflineStoreCompactState::CopyNextMessage(PRBool &done)
{
while (m_curIndex < m_size)
{
// Filter out msgs that have the "pendingRemoval" attribute set.
nsCOMPtr<nsIMsgDBHdr> hdr;
nsString pendingRemoval;
nsresult rv = m_db->GetMsgHdrForKey(m_keyArray->m_keys[m_curIndex], getter_AddRefs(hdr));
NS_ENSURE_SUCCESS(rv, rv);
hdr->GetProperty("pendingRemoval", pendingRemoval);
if (!pendingRemoval.IsEmpty())
{
m_curIndex++;
// Turn off offline flag for message, since after the compact is completed;
// we won't have the message in the offline store.
PRUint32 resultFlags;
hdr->AndFlags(~nsMsgMessageFlags::Offline, &resultFlags);
// We need to clear this in case the user changes the offline retention
// settings.
hdr->SetStringProperty("pendingRemoval", "");
continue;
}
m_messageUri.Truncate(); // clear the previous message uri
nsresult rv = BuildMessageURI(m_baseMessageUri.get(), m_keyArray[m_curIndex],
rv = BuildMessageURI(m_baseMessageUri.get(), m_keyArray->m_keys[m_curIndex],
m_messageUri);
NS_ENSURE_SUCCESS(rv, rv);
m_startOfMsg = PR_TRUE;
@ -1183,7 +1184,7 @@ nsOfflineStoreCompactState::OnDataAvailable(nsIRequest *request, nsISupports *ct
m_statusOffset = 0;
m_offlineMsgSize = 0;
m_messageUri.Truncate(); // clear the previous message uri
if (NS_SUCCEEDED(BuildMessageURI(m_baseMessageUri.get(), m_keyArray[m_curIndex],
if (NS_SUCCEEDED(BuildMessageURI(m_baseMessageUri.get(), m_keyArray->m_keys[m_curIndex],
m_messageUri)))
{
rv = GetMessage(getter_AddRefs(m_curSrcHdr));

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

@ -43,6 +43,7 @@
#include "nsIStreamListener.h"
#include "nsIMsgFolderCompactor.h"
#include "nsICopyMsgStreamListener.h"
#include "nsMsgKeyArray.h"
#include "nsIMsgWindow.h"
#include "nsIStringBundle.h"
#include "nsIMsgMessageService.h"
@ -88,8 +89,9 @@ protected:
nsCOMPtr<nsIMsgDatabase> m_db; // new database for the compact folder
nsCOMPtr <nsILocalFile> m_file; // new mailbox for the compact folder
nsCOMPtr <nsIOutputStream> m_fileStream; // output file stream for writing
nsTArray<nsMsgKey> m_keyArray; // all message keys need to be copied over
PRInt32 m_size; // size of the message key array
// all message keys that need to be copied over
nsRefPtr<nsMsgKeyArray> m_keyArray;
PRUint32 m_size;
// sum of the sizes of the messages, accumulated as we visit each msg.
PRUint32 m_totalMsgSize;

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

@ -52,6 +52,7 @@ endif
CPPSRCS = \
nsMsgLineBuffer.cpp \
nsMsgDBFolder.cpp \
nsMsgKeyArray.cpp \
nsMsgKeySet.cpp \
nsMsgIdentity.cpp \
nsMsgIncomingServer.cpp \
@ -70,6 +71,7 @@ CPPSRCS = \
EXPORTS = \
nsMsgLineBuffer.h \
nsMsgKeyArray.h \
nsMsgKeySet.h \
nsMsgDBFolder.h \
nsMsgDBFolderAtomList.h \

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

@ -1415,44 +1415,51 @@ nsMsgDBFolder::AddMessageDispositionState(nsIMsgDBHdr *aMessage, nsMsgDispositio
return NS_OK;
}
nsresult nsMsgDBFolder::AddMarkAllReadUndoAction(nsIMsgWindow *msgWindow,
nsMsgKey *thoseMarked,
PRUint32 numMarked)
{
nsRefPtr<nsMsgReadStateTxn> readStateTxn = new nsMsgReadStateTxn();
if (!readStateTxn)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = readStateTxn->Init(this, numMarked, thoseMarked);
NS_ENSURE_SUCCESS(rv, rv);
rv = readStateTxn->SetTransactionType(nsIMessenger::eMarkAllMsg);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsITransactionManager> txnMgr;
rv = msgWindow->GetTransactionManager(getter_AddRefs(txnMgr));
NS_ENSURE_SUCCESS(rv, rv);
rv = txnMgr->DoTransaction(readStateTxn);
NS_ENSURE_SUCCESS(rv, rv);
return rv;
}
NS_IMETHODIMP
nsMsgDBFolder::MarkAllMessagesRead(nsIMsgWindow *aMsgWindow)
{
nsresult rv = GetDatabase();
m_newMsgs.Clear();
if (NS_SUCCEEDED(rv))
{
EnableNotifications(allMessageCountNotifications, PR_FALSE, PR_TRUE /*dbBatching*/);
nsTArray<nsMsgKey> thoseMarked;
rv = mDatabase->MarkAllRead(&thoseMarked);
nsMsgKey *thoseMarked;
PRUint32 numMarked;
rv = mDatabase->MarkAllRead(&numMarked, &thoseMarked);
NS_ENSURE_SUCCESS(rv, rv);
EnableNotifications(allMessageCountNotifications, PR_TRUE, PR_TRUE /*dbBatching*/);
// Setup a undo-state
if (aMsgWindow)
{
nsRefPtr<nsMsgReadStateTxn> readStateTxn = new nsMsgReadStateTxn();
if (!readStateTxn)
return NS_ERROR_OUT_OF_MEMORY;
rv = readStateTxn->Init(this, thoseMarked);
NS_ENSURE_SUCCESS(rv, rv);
rv = readStateTxn->SetTransactionType(nsIMessenger::eMarkAllMsg);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsITransactionManager> txnMgr;
rv = aMsgWindow->GetTransactionManager(getter_AddRefs(txnMgr));
NS_ENSURE_SUCCESS(rv, rv);
rv = txnMgr->DoTransaction(readStateTxn);
NS_ENSURE_SUCCESS(rv, rv);
}
rv = AddMarkAllReadUndoAction(aMsgWindow, thoseMarked, numMarked);
nsMemory::Free(thoseMarked);
}
SetHasNewMessages(PR_FALSE);
return rv;
}
@ -1460,7 +1467,12 @@ NS_IMETHODIMP nsMsgDBFolder::MarkThreadRead(nsIMsgThread *thread)
{
nsresult rv = GetDatabase();
if(NS_SUCCEEDED(rv))
return mDatabase->MarkThreadRead(thread, nsnull, nsnull);
{
nsMsgKey *keys;
PRUint32 numKeys;
rv = mDatabase->MarkThreadRead(thread, nsnull, &numKeys, &keys);
nsMemory::Free(keys);
}
return rv;
}

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

@ -168,6 +168,8 @@ protected:
nsresult GetPurgeThreshold(PRInt32 *aThreshold);
nsresult ApplyRetentionSettings(PRBool deleteViaFolder);
PRBool VerifyOfflineMessage(nsIMsgDBHdr *msgHdr, nsIInputStream *fileStream);
nsresult AddMarkAllReadUndoAction(nsIMsgWindow *msgWindow,
nsMsgKey *thoseMarked, PRUint32 numMarked);
nsresult PerformBiffNotifications(void); // if there are new, non spam messages, do biff
nsresult CloseDBIfFolderNotOpen();

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

@ -0,0 +1,94 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is MailNews nsMsgKeyArray
*
* The Initial Developer of the Original Code is
* the Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* David Bienvenu <bienvenu@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsMsgKeyArray.h"
#include "nsMemory.h"
NS_IMPL_ISUPPORTS1(nsMsgKeyArray, nsIMsgKeyArray)
nsMsgKeyArray::nsMsgKeyArray()
{
}
nsMsgKeyArray::~nsMsgKeyArray()
{
}
NS_IMETHODIMP nsMsgKeyArray::Sort()
{
m_keys.Sort();
return NS_OK;
}
NS_IMETHODIMP nsMsgKeyArray::GetKeyAt(PRInt32 aIndex, nsMsgKey *aKey)
{
NS_ENSURE_ARG_POINTER(aKey);
*aKey = m_keys[aIndex];
return NS_OK;
}
NS_IMETHODIMP nsMsgKeyArray::GetLength(PRUint32 *aLength)
{
NS_ENSURE_ARG_POINTER(aLength);
*aLength = m_keys.Length();
return NS_OK;
}
NS_IMETHODIMP nsMsgKeyArray::SetCapacity(PRUint32 aCapacity)
{
m_keys.SetCapacity(aCapacity);
return NS_OK;
}
NS_IMETHODIMP nsMsgKeyArray::AppendElement(nsMsgKey aKey)
{
m_keys.AppendElement(aKey);
return NS_OK;
}
NS_IMETHODIMP nsMsgKeyArray::GetArray(PRUint32 *aCount, nsMsgKey **aKeys)
{
NS_ENSURE_ARG_POINTER(aCount);
NS_ENSURE_ARG_POINTER(aKeys);
*aCount = m_keys.Length();
*aKeys =
(nsMsgKey *) nsMemory::Clone(&m_keys[0],
m_keys.Length() * sizeof(nsMsgKey));
return (*aKeys) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}

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

@ -0,0 +1,60 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is MailNews nsMsgKeyArray
*
* The Initial Developer of the Original Code is
* the Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* David Bienvenu <bienvenu@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsMsgKeyArray_h__
#define nsMsgKeyArray_h__
#include "nsIMsgKeyArray.h"
#include "nsTArray.h"
/*
* This class is a thin wrapper around an nsTArray<nsMsgKey>
*/
class nsMsgKeyArray : public nsIMsgKeyArray
{
public:
nsMsgKeyArray();
virtual ~nsMsgKeyArray();
NS_DECL_ISUPPORTS
NS_DECL_NSIMSGKEYARRAY
nsTArray<nsMsgKey> m_keys;
};
#endif

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

@ -52,13 +52,14 @@ nsMsgReadStateTxn::~nsMsgReadStateTxn()
}
nsresult
nsMsgReadStateTxn::Init(nsIMsgFolder *aParentFolder,
nsTArray<nsMsgKey> & aMsgKeyArray)
nsMsgReadStateTxn::Init(nsIMsgFolder *aParentFolder,
PRUint32 aNumKeys,
nsMsgKey *aMsgKeyArray)
{
NS_ENSURE_ARG_POINTER(aParentFolder);
mParentFolder = aParentFolder;
aMsgKeyArray.SwapElements(mMarkedMessages);
mMarkedMessages.AppendElements(aMsgKeyArray, aNumKeys);
return nsMsgTxn::Init();
}

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

@ -62,8 +62,9 @@ public:
nsMsgReadStateTxn();
virtual ~nsMsgReadStateTxn();
nsresult Init(nsIMsgFolder *aParentFolder,
nsTArray<nsMsgKey> & aMsgKeyArray);
nsresult Init(nsIMsgFolder *aParentFolder,
PRUint32 aNumKeys,
nsMsgKey *aMsgKeyArray);
NS_IMETHOD UndoTransaction();
NS_IMETHOD RedoTransaction();

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

@ -99,6 +99,7 @@
#include "nsMsgBiffManager.h"
#include "nsMsgPurgeService.h"
#include "nsStatusBarBiffManager.h"
#include "nsMsgKeyArray.h"
#include "nsCopyMessageStreamListener.h"
#include "nsMsgCopyService.h"
#include "nsMsgFolderCache.h"
@ -351,6 +352,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsCopyMessageStreamListener)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgCopyService)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgFolderCache)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgStatusFeedback)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgKeyArray)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsMsgWindow,Init)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsMsgServiceProviderService, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsSubscribeDataSource, Init)
@ -416,6 +418,7 @@ NS_DEFINE_NAMED_CID(NS_MSGCOPYSERVICE_CID);
NS_DEFINE_NAMED_CID(NS_MSGFOLDERCACHE_CID);
NS_DEFINE_NAMED_CID(NS_MSGSTATUSFEEDBACK_CID);
NS_DEFINE_NAMED_CID(NS_MSGWINDOW_CID);
NS_DEFINE_NAMED_CID(NS_MSGKEYARRAY_CID);
#ifdef NS_PRINTING
NS_DEFINE_NAMED_CID(NS_MSG_PRINTENGINE_CID);
#endif
@ -811,6 +814,7 @@ const mozilla::Module::CIDEntry kMailNewsCIDs[] = {
{ &kNS_MSGCOPYSERVICE_CID, false, NULL, nsMsgCopyServiceConstructor},
{ &kNS_MSGFOLDERCACHE_CID, false, NULL, nsMsgFolderCacheConstructor},
{ &kNS_MSGSTATUSFEEDBACK_CID, false, NULL, nsMsgStatusFeedbackConstructor},
{ &kNS_MSGKEYARRAY_CID, false, NULL, nsMsgKeyArrayConstructor},
{ &kNS_MSGWINDOW_CID, false, NULL, nsMsgWindowConstructor},
#ifdef NS_PRINTING
{ &kNS_MSG_PRINTENGINE_CID, false, NULL, nsMsgPrintEngineConstructor},
@ -1007,6 +1011,7 @@ const mozilla::Module::ContractIDEntry kMailNewsContracts[] = {
{ NS_MSGCOPYSERVICE_CONTRACTID, &kNS_MSGCOPYSERVICE_CID },
{ NS_MSGFOLDERCACHE_CONTRACTID, &kNS_MSGFOLDERCACHE_CID },
{ NS_MSGSTATUSFEEDBACK_CONTRACTID, &kNS_MSGSTATUSFEEDBACK_CID },
{ NS_MSGKEYARRAY_CONTRACTID, &kNS_MSGKEYARRAY_CID },
{ NS_MSGWINDOW_CONTRACTID, &kNS_MSGWINDOW_CID },
#ifdef NS_PRINTING
{ NS_MSGPRINTENGINE_CONTRACTID, &kNS_MSG_PRINTENGINE_CID },

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

@ -69,13 +69,12 @@ interface nsIMsgThread;
interface nsIDBFolderInfo;
interface nsIMsgOfflineImapOperation;
interface nsIMsgFolder;
interface nsIMsgKeyArray;
interface nsIOutputStream;
interface nsIUrlListener;
interface nsILocalFile;
interface nsIArray;
[ptr] native octetPtr(PRUint8);
typedef unsigned long nsMsgRetainByPreference;
@ -267,7 +266,7 @@ interface nsIMsgDBService : nsISupports
nsIMsgDatabase cachedDBForFolder(in nsIMsgFolder aFolder);
};
[scriptable, uuid(2DDC3EFE-743D-4b8c-B761-6ED75ED06737)]
[scriptable, uuid(19719187-6a85-4807-aeb6-421115240ba1)]
interface nsIMsgDatabase : nsIDBChangeAnnouncer {
/**
* Opens a database folder.
@ -315,7 +314,7 @@ interface nsIMsgDatabase : nsIDBChangeAnnouncer {
nsIMsgDBHdr CopyHdrFromExistingHdr(in nsMsgKey key, in nsIMsgDBHdr existingHdr, in boolean addHdrToDB);
[noscript] void ListAllKeys(in nsMsgKeyArrayRef outputKeys);
void ListAllKeys(in nsIMsgKeyArray array);
nsISimpleEnumerator EnumerateMessages();
nsISimpleEnumerator ReverseEnumerateMessages();
@ -403,8 +402,9 @@ interface nsIMsgDatabase : nsIDBChangeAnnouncer {
void MarkHasAttachments(in nsMsgKey key, in boolean bHasAttachments,
in nsIDBChangeListener instigator);
[noscript] void MarkThreadRead(in nsIMsgThread thread,
in nsIDBChangeListener instigator, in nsMsgKeyArrayPtr thoseMarked);
void MarkThreadRead(in nsIMsgThread thread, in nsIDBChangeListener instigator,
out unsigned long aCount,
[array, size_is(aCount)] out nsMsgKey aKeys);
void MarkThreadIgnored(in nsIMsgThread thread, in nsMsgKey threadKey, in boolean bIgnored,
in nsIDBChangeListener instigator);
@ -418,9 +418,8 @@ interface nsIMsgDatabase : nsIDBChangeAnnouncer {
boolean IsMarked(in nsMsgKey key);
boolean HasAttachments(in nsMsgKey key);
[noscript] void MarkAllRead(in nsMsgKeyArrayPtr thoseMarked);
[noscript] void MarkReadByDate (in PRTime startDate, in PRTime endDate, in nsMsgKeyArrayPtr markedIds);
void MarkAllRead(out unsigned long aCount,
[array, size_is(aCount)] out nsMsgKey aKeys);
void deleteMessages(in unsigned long aNumKeys,
[array, size_is(aNumKeys)] in nsMsgKey nsMsgKeys,
@ -497,7 +496,7 @@ interface nsIMsgDatabase : nsIDBChangeAnnouncer {
nsISimpleEnumerator EnumerateOfflineOps();
[noscript] void ListAllOfflineOpIds(in nsMsgKeyArrayPtr offlineOpIds);
[noscript] void ListAllOfflineDeletes(in nsMsgKeyArrayPtr offlineDeletes);
[noscript] void ListAllOfflineMsgs(in nsMsgKeyArrayPtr offlineMsgs);
void ListAllOfflineMsgs(in nsIMsgKeyArray aKeys);
void setAttributeOnPendingHdr(in nsIMsgDBHdr pendingHdr, in string property,
in string propertyVal);
@ -535,8 +534,12 @@ interface nsIMsgDatabase : nsIDBChangeAnnouncer {
attribute nsMsgKey nextPseudoMsgKey; //for undo-redo of move pop->imap
readonly attribute nsMsgKey nextFakeOfflineMsgKey; // for saving "fake" offline msg hdrs
// for sorting
[noscript] void createCollationKey(in AString sourceString, out octetPtr key, out unsigned long len);
[noscript] long compareCollationKeys(in octetPtr key1, in unsigned long len1, in octetPtr key2, in unsigned long len2);
void createCollationKey(in AString sourceString, out unsigned long aCount,
[array, size_is(aCount)] out octet aKey);
long compareCollationKeys(in unsigned long aLen1,
[array, size_is(aLen1)] in octet key1,
in unsigned long aLen2,
[array, size_is(aLen2)] in octet key2);
// when creating a view, the default sort order and view flags
// use these for the default. (this allows news to override, so that

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

@ -41,6 +41,7 @@
#include "nsIMsgDatabase.h"
#include "nsMsgHdr.h"
#include "nsStringGlue.h"
#include "nsAutoPtr.h"
#include "nsIDBChangeListener.h"
#include "nsIDBChangeAnnouncer.h"
#include "nsMsgMessageFlags.h"
@ -55,7 +56,6 @@
#include "pldhash.h"
#include "nsTArray.h"
#include "nsTObserverArray.h"
#include "nsAutoPtr.h"
class ListContext;
class nsMsgKeySet;
class nsMsgThread;

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

@ -66,7 +66,7 @@ public:
NS_IMETHOD GetHighWaterArticleNum(nsMsgKey *key);
NS_IMETHOD GetLowWaterArticleNum(nsMsgKey *key);
NS_IMETHOD MarkAllRead(nsTArray<nsMsgKey> *thoseMarked);
NS_IMETHOD MarkAllRead(PRUint32 *aNumMarked, nsMsgKey **thoseMarked);
virtual nsresult ExpireUpTo(nsMsgKey expireKey);
virtual nsresult ExpireRange(nsMsgKey startRange, nsMsgKey endRange);

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

@ -69,6 +69,7 @@
#include "nsIMsgFolderCacheElement.h"
#include "MailNewsTypes2.h"
#include "nsMsgUtils.h"
#include "nsMsgKeyArray.h"
#include "nsIMutableArray.h"
#include "nsComponentManagerUtils.h"
#include "nsServiceManagerUtils.h"
@ -2163,13 +2164,16 @@ NS_IMETHODIMP nsMsgDatabase::MarkHasAttachments(nsMsgKey key, PRBool bHasAttachm
}
NS_IMETHODIMP
nsMsgDatabase::MarkThreadRead(nsIMsgThread *thread, nsIDBChangeListener *instigator, nsTArray<nsMsgKey> *thoseMarked)
nsMsgDatabase::MarkThreadRead(nsIMsgThread *thread, nsIDBChangeListener *instigator,
PRUint32 *aNumMarked, nsMsgKey **aThoseMarked)
{
if (!thread)
return NS_ERROR_NULL_POINTER;
NS_ENSURE_ARG_POINTER(thread);
NS_ENSURE_ARG_POINTER(aNumMarked);
NS_ENSURE_ARG_POINTER(aThoseMarked);
nsresult rv = NS_OK;
PRUint32 numChildren;
nsTArray<nsMsgKey> thoseMarked;
thread->GetNumChildren(&numChildren);
for (PRUint32 curChildIndex = 0; curChildIndex < numChildren; curChildIndex++)
{
@ -2182,16 +2186,19 @@ nsMsgDatabase::MarkThreadRead(nsIMsgThread *thread, nsIDBChangeListener *instiga
IsHeaderRead(child, &isRead);
if (!isRead)
{
if (thoseMarked)
{
nsMsgKey key;
if (NS_SUCCEEDED(child->GetMessageKey(&key)))
thoseMarked->AppendElement(key);
}
nsMsgKey key;
if (NS_SUCCEEDED(child->GetMessageKey(&key)))
thoseMarked.AppendElement(key);
MarkHdrRead(child, PR_TRUE, instigator);
}
}
}
*aThoseMarked =
(nsMsgKey *) nsMemory::Clone(&thoseMarked[0],
thoseMarked.Length() * sizeof(nsMsgKey));
*aNumMarked = thoseMarked.Length();
if (!*aThoseMarked)
return NS_ERROR_OUT_OF_MEMORY;
return rv;
}
@ -2587,13 +2594,15 @@ nsMsgDatabase::MarkHdrNotNew(nsIMsgDBHdr *aMsgHdr,
return SetMsgHdrFlag(aMsgHdr, PR_FALSE, nsMsgMessageFlags::New, aInstigator);
}
NS_IMETHODIMP nsMsgDatabase::MarkAllRead(nsTArray<nsMsgKey> *thoseMarked)
NS_IMETHODIMP nsMsgDatabase::MarkAllRead(PRUint32 *aNumKeys, nsMsgKey **aThoseMarked)
{
nsresult rv;
NS_ENSURE_ARG_POINTER(aNumKeys);
NS_ENSURE_ARG_POINTER(aThoseMarked);
nsMsgHdr *pHeader;
nsCOMPtr <nsISimpleEnumerator> hdrs;
rv = EnumerateMessages(getter_AddRefs(hdrs));
nsCOMPtr<nsISimpleEnumerator> hdrs;
nsTArray<nsMsgKey> thoseMarked;
nsresult rv = EnumerateMessages(getter_AddRefs(hdrs));
if (NS_FAILED(rv))
return rv;
PRBool hasMore = PR_FALSE;
@ -2610,16 +2619,18 @@ NS_IMETHODIMP nsMsgDatabase::MarkAllRead(nsTArray<nsMsgKey> *thoseMarked)
if (!isRead)
{
if (thoseMarked)
{
nsMsgKey key;
(void)pHeader->GetMessageKey(&key);
thoseMarked->AppendElement(key);
}
nsMsgKey key;
(void)pHeader->GetMessageKey(&key);
thoseMarked.AppendElement(key);
rv = MarkHdrRead(pHeader, PR_TRUE, nsnull); // ### dmb - blow off error?
}
NS_RELEASE(pHeader);
}
*aThoseMarked = (nsMsgKey *) nsMemory::Clone(&thoseMarked[0],
thoseMarked.Length() * sizeof(nsMsgKey));
if (!*aThoseMarked)
return NS_ERROR_OUT_OF_MEMORY;
*aNumKeys = thoseMarked.Length();
// force num new to 0.
PRInt32 numUnreadMessages;
@ -2631,50 +2642,6 @@ NS_IMETHODIMP nsMsgDatabase::MarkAllRead(nsTArray<nsMsgKey> *thoseMarked)
return rv;
}
NS_IMETHODIMP nsMsgDatabase::MarkReadByDate (PRTime startDate, PRTime endDate, nsTArray<nsMsgKey> *markedIds)
{
nsresult rv;
nsMsgHdr *pHeader;
PRInt32 numChanged = 0;
nsISimpleEnumerator* hdrs;
rv = EnumerateMessages(&hdrs);
if (NS_FAILED(rv))
return rv;
PRBool hasMore = PR_FALSE;
while (NS_SUCCEEDED(rv = hdrs->HasMoreElements(&hasMore)) && hasMore)
{
rv = hdrs->GetNext((nsISupports**)&pHeader);
NS_ASSERTION(NS_SUCCEEDED(rv), "nsMsgDBEnumerator broken");
if (NS_FAILED(rv)) break;
PRTime headerDate;
(void)pHeader->GetDate(&headerDate);
if (headerDate > startDate && headerDate <= endDate)
{
PRBool isRead;
nsMsgKey key;
(void)pHeader->GetMessageKey(&key);
IsRead(key, &isRead);
if (!isRead)
{
numChanged++;
if (markedIds)
markedIds->AppendElement(key);
rv = MarkHdrRead(pHeader, PR_TRUE, NULL); // ### dmb - blow off error?
}
}
NS_RELEASE(pHeader);
}
if (numChanged > 0)
Commit(nsMsgDBCommitType::kSmallCommit);
return rv;
}
NS_IMETHODIMP nsMsgDatabase::AddToNewList(nsMsgKey key)
{
// we add new keys in increasing order...
@ -3078,31 +3045,34 @@ nsMsgDatabase::SyncCounts()
return NS_OK;
}
// resulting output array is sorted by key.
NS_IMETHODIMP nsMsgDatabase::ListAllKeys(nsTArray<nsMsgKey> &outputKeys)
NS_IMETHODIMP nsMsgDatabase::ListAllKeys(nsIMsgKeyArray *aKeys)
{
nsresult err = NS_OK;
nsIMdbTableRowCursor *rowCursor;
NS_ENSURE_ARG_POINTER(aKeys);
nsresult rv = NS_OK;
nsCOMPtr<nsIMdbTableRowCursor> rowCursor;
if (m_mdbAllMsgHeadersTable)
{
err = m_mdbAllMsgHeadersTable->GetTableRowCursor(GetEnv(), -1, &rowCursor);
while (err == NS_OK && rowCursor)
PRUint32 numMsgs = 0;
m_mdbAllMsgHeadersTable->GetCount(GetEnv(), &numMsgs);
aKeys->SetCapacity(numMsgs);
rv = m_mdbAllMsgHeadersTable->GetTableRowCursor(GetEnv(), -1,
getter_AddRefs(rowCursor));
while (NS_SUCCEEDED(rv) && rowCursor)
{
mdbOid outOid;
mdb_pos outPos;
err = rowCursor->NextRowOid(GetEnv(), &outOid, &outPos);
rv = rowCursor->NextRowOid(GetEnv(), &outOid, &outPos);
// is this right? Mork is returning a 0 id, but that should valid.
if (outPos < 0 || outOid.mOid_Id == (mdb_id) -1)
break;
if (err == NS_OK)
outputKeys.AppendElement(outOid.mOid_Id);
if (NS_SUCCEEDED(rv))
aKeys->AppendElement(outOid.mOid_Id);
}
rowCursor->Release();
aKeys->Sort();
}
outputKeys.Sort();
return err;
return rv;
}
class nsMsgDBThreadEnumerator : public nsISimpleEnumerator, public nsIDBChangeListener
@ -3573,7 +3543,7 @@ nsresult nsMsgDatabase::RowCellColumnToAddressCollationKey(nsIMdbRow *row, mdb_t
name);
if (NS_SUCCEEDED(rv))
return CreateCollationKey(NS_ConvertUTF8toUTF16(name), result, len);
return CreateCollationKey(NS_ConvertUTF8toUTF16(name), len, result);
return rv;
}
@ -3636,14 +3606,15 @@ nsresult nsMsgDatabase::RowCellColumnToCollationKey(nsIMdbRow *row, mdb_token co
charSet.get(), characterSetOverride, PR_TRUE,
getter_Copies(decodedStr));
if (NS_SUCCEEDED(err))
err = CreateCollationKey(NS_ConvertUTF8toUTF16(decodedStr), result, len);
err = CreateCollationKey(NS_ConvertUTF8toUTF16(decodedStr), len, result);
}
}
return err;
}
NS_IMETHODIMP
nsMsgDatabase::CompareCollationKeys(PRUint8 *key1, PRUint32 len1, PRUint8 *key2, PRUint32 len2, PRInt32 *result)
nsMsgDatabase::CompareCollationKeys(PRUint32 len1, PRUint8 *key1, PRUint32 len2,
PRUint8 *key2, PRInt32 *result)
{
nsresult rv = GetCollationKeyGenerator();
NS_ENSURE_SUCCESS(rv,rv);
@ -3655,7 +3626,8 @@ nsMsgDatabase::CompareCollationKeys(PRUint8 *key1, PRUint32 len1, PRUint8 *key2,
}
NS_IMETHODIMP
nsMsgDatabase::CreateCollationKey(const nsAString& sourceString, PRUint8 **result, PRUint32 *len)
nsMsgDatabase::CreateCollationKey(const nsAString& sourceString, PRUint32 *len,
PRUint8 **result)
{
nsresult err = GetCollationKeyGenerator();
NS_ENSURE_SUCCESS(err,err);
@ -4806,8 +4778,9 @@ NS_IMETHODIMP nsMsgDatabase::RemoveOfflineOp(nsIMsgOfflineImapOperation *op)
}
NS_IMETHODIMP nsMsgDatabase::ListAllOfflineMsgs(nsTArray<nsMsgKey> *outputKeys)
NS_IMETHODIMP nsMsgDatabase::ListAllOfflineMsgs(nsIMsgKeyArray *aKeys)
{
NS_ENSURE_ARG_POINTER(aKeys);
nsCOMPtr <nsISimpleEnumerator> enumerator;
PRUint32 flag = nsMsgMessageFlags::Offline;
// if we change this routine to return an enumerator that generates the keys
@ -4830,12 +4803,11 @@ NS_IMETHODIMP nsMsgDatabase::ListAllOfflineMsgs(nsTArray<nsMsgKey> *outputKeys)
{
nsMsgKey msgKey;
dbMessage->GetMessageKey(&msgKey);
outputKeys->AppendElement(msgKey);
aKeys->AppendElement(msgKey);
}
}
}
outputKeys->Sort();
aKeys->Sort();
return rv;
}
@ -4913,10 +4885,14 @@ nsresult nsMsgDatabase::DumpContents()
nsMsgKey key;
PRUint32 i;
nsTArray<nsMsgKey> keys;
nsRefPtr<nsMsgKeyArray> keys = new nsMsgKeyArray;
if (!keys)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = ListAllKeys(keys);
for (i = 0; i < keys.Length(); i++) {
key = keys[i];
PRUint32 numKeys;
keys->GetLength(&numKeys);
for (i = 0; i < numKeys; i++) {
key = keys->m_keys[i];
nsIMsgDBHdr *msg = NULL;
rv = GetMsgHdrForKey(key, &msg);
nsMsgHdr* msgHdr = static_cast<nsMsgHdr*>(msg); // closed system, cast ok

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

@ -724,17 +724,17 @@ NS_IMETHODIMP nsMsgHdr::GetMime2DecodedRecipients(nsAString &resultRecipients)
}
NS_IMETHODIMP nsMsgHdr::GetAuthorCollationKey(PRUint8 **resultAuthor, PRUint32 *len)
NS_IMETHODIMP nsMsgHdr::GetAuthorCollationKey(PRUint32 *len, PRUint8 **resultAuthor)
{
return m_mdb->RowCellColumnToAddressCollationKey(GetMDBRow(), m_mdb->m_senderColumnToken, resultAuthor, len);
}
NS_IMETHODIMP nsMsgHdr::GetSubjectCollationKey(PRUint8 **resultSubject, PRUint32 *len)
NS_IMETHODIMP nsMsgHdr::GetSubjectCollationKey(PRUint32 *len, PRUint8 **resultSubject)
{
return m_mdb->RowCellColumnToCollationKey(GetMDBRow(), m_mdb->m_subjectColumnToken, resultSubject, len);
}
NS_IMETHODIMP nsMsgHdr::GetRecipientsCollationKey(PRUint8 **resultRecipients, PRUint32 *len)
NS_IMETHODIMP nsMsgHdr::GetRecipientsCollationKey(PRUint32 *len, PRUint8 **resultRecipients)
{
return m_mdb->RowCellColumnToCollationKey(GetMDBRow(), m_mdb->m_recipientsColumnToken, resultRecipients, len);
}

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

@ -253,7 +253,8 @@ PRBool nsNewsDatabase::SetHdrReadFlag(nsIMsgDBHdr *msgHdr, PRBool bRead)
return PR_TRUE;
}
NS_IMETHODIMP nsNewsDatabase::MarkAllRead(nsTArray<nsMsgKey> *thoseMarked)
NS_IMETHODIMP nsNewsDatabase::MarkAllRead(PRUint32 *aNumMarked,
nsMsgKey **aThoseMarked)
{
nsMsgKey lowWater = nsMsgKey_None, highWater;
nsCString knownArts;
@ -271,7 +272,7 @@ NS_IMETHODIMP nsNewsDatabase::MarkAllRead(nsTArray<nsMsgKey> *thoseMarked)
GetHighWaterArticleNum(&highWater);
if (lowWater > 2)
m_readSet->AddRange(1, lowWater - 1);
nsresult err = nsMsgDatabase::MarkAllRead(thoseMarked);
nsresult err = nsMsgDatabase::MarkAllRead(aNumMarked, aThoseMarked);
if (NS_SUCCEEDED(err) && 1 <= highWater)
m_readSet->AddRange(1, highWater); // mark everything read in newsrc.

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

@ -38,6 +38,7 @@
#include "nsImapMailFolder.h"
#include "nsMsgImapCID.h"
#include "nsIMsgMailNewsUrl.h"
#include "nsMsgKeyArray.h"
#include "nsIMsgWindow.h"
#include "nsIMsgMailSession.h"
#include "nsMsgFolderFlags.h"
@ -368,8 +369,10 @@ NS_IMETHODIMP nsAutoSyncState::ProcessExistingHeaders(PRUint32 aNumOfHdrsToProce
// create a queue to process existing headers for the first time
if (mExistingHeadersQ.IsEmpty())
{
rv = database->ListAllKeys(mExistingHeadersQ);
nsRefPtr<nsMsgKeyArray> keys = new nsMsgKeyArray;
rv = database->ListAllKeys(keys);
NS_ENSURE_SUCCESS(rv, rv);
mExistingHeadersQ.AppendElements(keys->m_keys);
mProcessPointer = 0;
}

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

@ -64,6 +64,7 @@
#include "nsImapUtils.h"
#include "nsMsgUtils.h"
#include "nsIMsgMailSession.h"
#include "nsMsgKeyArray.h"
#include "nsMsgBaseCID.h"
#include "nsMsgLocalCID.h"
#include "nsImapUndoTxn.h"
@ -1954,36 +1955,21 @@ nsImapMailFolder::MarkAllMessagesRead(nsIMsgWindow *aMsgWindow)
nsresult rv = GetDatabase();
if(NS_SUCCEEDED(rv))
{
nsTArray<nsMsgKey> thoseMarked;
nsMsgKey *thoseMarked;
PRUint32 numMarked;
EnableNotifications(allMessageCountNotifications, PR_FALSE, PR_TRUE /*dbBatching*/);
rv = mDatabase->MarkAllRead(&thoseMarked);
rv = mDatabase->MarkAllRead(&numMarked, &thoseMarked);
EnableNotifications(allMessageCountNotifications, PR_TRUE, PR_TRUE /*dbBatching*/);
if (NS_SUCCEEDED(rv))
{
rv = StoreImapFlags(kImapMsgSeenFlag, PR_TRUE, thoseMarked.Elements(),
thoseMarked.Length(), nsnull);
rv = StoreImapFlags(kImapMsgSeenFlag, PR_TRUE, thoseMarked,
numMarked, nsnull);
mDatabase->Commit(nsMsgDBCommitType::kLargeCommit);
// Setup a undo-state
if (aMsgWindow)
{
nsRefPtr<nsMsgReadStateTxn> readStateTxn = new nsMsgReadStateTxn();
if (!readStateTxn)
return NS_ERROR_OUT_OF_MEMORY;
rv = readStateTxn->Init(this, thoseMarked);
NS_ENSURE_SUCCESS(rv, rv);
rv = readStateTxn->SetTransactionType(nsIMessenger::eMarkAllMsg);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsITransactionManager> txnMgr;
rv = aMsgWindow->GetTransactionManager(getter_AddRefs(txnMgr));
NS_ENSURE_SUCCESS(rv, rv);
rv = txnMgr->DoTransaction(readStateTxn);
NS_ENSURE_SUCCESS(rv, rv);
}
rv = AddMarkAllReadUndoAction(aMsgWindow, thoseMarked, numMarked);
nsMemory::Free(thoseMarked);
}
}
return rv;
@ -1994,13 +1980,14 @@ NS_IMETHODIMP nsImapMailFolder::MarkThreadRead(nsIMsgThread *thread)
nsresult rv = GetDatabase();
if(NS_SUCCEEDED(rv))
{
nsTArray<nsMsgKey> thoseMarked;
rv = mDatabase->MarkThreadRead(thread, nsnull, &thoseMarked);
nsMsgKey *keys;
PRUint32 numKeys;
rv = mDatabase->MarkThreadRead(thread, nsnull, &numKeys, &keys);
if (NS_SUCCEEDED(rv))
{
rv = StoreImapFlags(kImapMsgSeenFlag, PR_TRUE, thoseMarked.Elements(),
thoseMarked.Length(), nsnull);
rv = StoreImapFlags(kImapMsgSeenFlag, PR_TRUE, keys, numKeys, nsnull);
mDatabase->Commit(nsMsgDBCommitType::kLargeCommit);
nsMemory::Free(keys);
}
}
return rv;
@ -2726,8 +2713,13 @@ NS_IMETHODIMP nsImapMailFolder::UpdateImapMailboxInfo(nsIImapProtocol* aProtocol
PR_snprintf(intStrBuf, sizeof(intStrBuf), "%llu", mailboxHighestModSeq);
dbFolderInfo->SetCharProperty(kModSeqPropertyName, nsDependentCString(intStrBuf));
}
mDatabase->ListAllKeys(existingKeys);
PRInt32 keyCount = existingKeys.Length();
nsRefPtr<nsMsgKeyArray> keys = new nsMsgKeyArray;
if (!keys)
return NS_ERROR_OUT_OF_MEMORY;
rv = mDatabase->ListAllKeys(keys);
NS_ENSURE_SUCCESS(rv, rv);
existingKeys.AppendElements(keys->m_keys);
PRUint32 keyCount = existingKeys.Length();
mDatabase->ListAllOfflineDeletes(&existingKeys);
if (keyCount < existingKeys.Length())
existingKeys.Sort();

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

@ -769,15 +769,17 @@ NS_IMETHODIMP nsImapService::CopyMessage(const char *aSrcMailboxURI,
return rv;
}
NS_IMETHODIMP nsImapService::CopyMessages(nsTArray<nsMsgKey> &keys,
nsIMsgFolder *srcFolder,
nsIStreamListener *aMailboxCopy,
NS_IMETHODIMP nsImapService::CopyMessages(PRUint32 aNumKeys,
nsMsgKey*aKeys,
nsIMsgFolder *srcFolder,
nsIStreamListener *aMailboxCopy,
PRBool moveMessage,
nsIUrlListener *aUrlListener,
nsIUrlListener *aUrlListener,
nsIMsgWindow *aMsgWindow,
nsIURI **aURL)
{
NS_ENSURE_ARG_POINTER(aMailboxCopy);
NS_ENSURE_ARG_POINTER(aKeys);
nsresult rv;
nsCOMPtr<nsISupports> streamSupport = do_QueryInterface(aMailboxCopy, &rv);
@ -795,11 +797,10 @@ NS_IMETHODIMP nsImapService::CopyMessages(nsTArray<nsMsgKey> &keys,
// GetMessage in nsCopyMessageStreamListener will get an unescaped username
// and be able to find the msg hdr. See bug 259656 for details
nsCString uri;
srcFolder->GenerateMessageURI(keys[0], uri);
srcFolder->GenerateMessageURI(aKeys[0], uri);
nsCString messageIds;
PRUint32 numKeys = keys.Length();
AllocateImapUidString(keys.Elements(), numKeys, nsnull, messageIds);
AllocateImapUidString(aKeys, aNumKeys, nsnull, messageIds);
nsCOMPtr<nsIImapUrl> imapUrl;
nsCAutoString urlSpec;
char hierarchyDelimiter = GetHierarchyDelimiter(folder);

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

@ -3021,7 +3021,11 @@ nsresult nsMsgLocalMailFolder::CopyMessagesTo(nsIArray *messages, nsTArray<nsMsg
nsCOMPtr <nsIMsgLocalMailFolder> srcLocalFolder = do_QueryInterface(srcFolder);
if (srcLocalFolder)
StartMessage();
rv = mCopyState->m_messageService->CopyMessages(keyArray, srcFolder, streamListener, isMove, nsnull, aMsgWindow, nsnull);
rv = mCopyState->m_messageService->CopyMessages(keyArray.Length(),
keyArray.Elements(),
srcFolder, streamListener,
isMove, nsnull, aMsgWindow,
nsnull);
}
return rv;
}

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

@ -125,16 +125,18 @@ nsresult nsMailboxService::CopyMessage(const char * aSrcMailboxURI,
return FetchMessage(aSrcMailboxURI, aMailboxCopyHandler, aMsgWindow, aUrlListener, nsnull, mailboxAction, nsnull, aURL);
}
nsresult nsMailboxService::CopyMessages(nsTArray<nsMsgKey> &msgKeys,
nsIMsgFolder *srcFolder,
nsIStreamListener * aMailboxCopyHandler,
PRBool moveMessage,
nsIUrlListener * aUrlListener,
nsIMsgWindow *aMsgWindow,
nsIURI **aURL)
nsresult nsMailboxService::CopyMessages(PRUint32 aNumKeys,
nsMsgKey* aMsgKeys,
nsIMsgFolder *srcFolder,
nsIStreamListener * aMailboxCopyHandler,
PRBool moveMessage,
nsIUrlListener * aUrlListener,
nsIMsgWindow *aMsgWindow,
nsIURI **aURL)
{
nsresult rv = NS_OK;
NS_ENSURE_ARG(srcFolder);
NS_ENSURE_ARG(aMsgKeys);
nsCOMPtr<nsIMailboxUrl> mailboxurl;
nsMailboxAction actionToUse = nsIMailboxUrl::ActionMoveMessage;
@ -146,7 +148,7 @@ nsresult nsMailboxService::CopyMessages(nsTArray<nsMsgKey> &msgKeys,
srcFolder->GetMsgDatabase(getter_AddRefs(db));
if (db)
{
db->GetMsgHdrForKey(msgKeys[0], getter_AddRefs(msgHdr));
db->GetMsgHdrForKey(aMsgKeys[0], getter_AddRefs(msgHdr));
if (msgHdr)
{
nsCString uri;
@ -160,7 +162,7 @@ nsresult nsMailboxService::CopyMessages(nsTArray<nsMsgKey> &msgKeys,
nsCOMPtr<nsIMailboxUrl> mailboxUrl (do_QueryInterface(url));
msgUrl->SetMsgWindow(aMsgWindow);
mailboxUrl->SetMoveCopyMsgKeys(msgKeys.Elements(), msgKeys.Length());
mailboxUrl->SetMoveCopyMsgKeys(aMsgKeys, aNumKeys);
rv = RunMailboxUrl(url, aMailboxCopyHandler);
}
}

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

@ -48,6 +48,8 @@
#include "nsMsgLocalCID.h"
#include "nsMsgFolderFlags.h"
#include "nsPop3Protocol.h"
#include "nsAutoPtr.h"
#include "nsMsgKeyArray.h"
#include "nsIMsgLocalMailFolder.h"
#include "nsIMsgAccountManager.h"
#include "nsIMsgMailNewsUrl.h"
@ -193,10 +195,10 @@ NS_IMETHODIMP nsPop3IncomingServer::GetDeferredToAccount(nsACString& aRetVal)
{
// Copy any messages in this sub-folder of the hidden
// account to the corresponding folder in Local Folders.
nsTArray<nsMsgKey> keys;
nsRefPtr<nsMsgKeyArray> keys = new nsMsgKeyArray;
rv = subFolderDB->ListAllKeys(keys);
nsCOMPtr<nsIMutableArray> hdrsToCopy(do_CreateInstance(NS_ARRAY_CONTRACTID));
MsgGetHeadersFromKeys(subFolderDB, keys, hdrsToCopy);
MsgGetHeadersFromKeys(subFolderDB, keys->m_keys, hdrsToCopy);
PRUint32 numHdrs = 0;
if (hdrsToCopy)
hdrsToCopy->GetLength(&numHdrs);

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

@ -57,6 +57,7 @@
#include "nsIMsgDatabase.h"
#include "nsMsgFolderFlags.h"
#include "nsIMsgHdr.h"
#include "MailNewsTypes.h"
#include "nsMsgBaseCID.h"
#include "nsIMsgAccountManager.h"
#include "nsIMsgFolder.h"

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

@ -40,6 +40,8 @@
#include "nsCOMPtr.h"
#include "nsNNTPArticleList.h"
#include "nsIMsgFolder.h"
#include "nsAutoPtr.h"
#include "nsMsgKeyArray.h"
NS_IMPL_ISUPPORTS1(nsNNTPArticleList, nsINNTPArticleList)
@ -75,8 +77,10 @@ nsNNTPArticleList::Initialize(nsIMsgNewsFolder *newsFolder)
NS_ENSURE_SUCCESS(rv,rv);
if (!m_newsDB) return NS_ERROR_UNEXPECTED;
rv = m_newsDB->ListAllKeys(m_idsInDB);
nsRefPtr<nsMsgKeyArray> keys = new nsMsgKeyArray;
rv = m_newsDB->ListAllKeys(keys);
NS_ENSURE_SUCCESS(rv,rv);
m_idsInDB.AppendElements(keys->m_keys);
return NS_OK;
}

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

@ -1683,7 +1683,7 @@ NS_IMETHODIMP nsMsgNewsFolder::RemoveMessages(nsTArray<nsMsgKey> &aMsgKeys)
{
nsresult rv = GetDatabase();
NS_ENSURE_SUCCESS(rv, rv); // if GetDatabase succeeds, mDatabase will be non-null
// Notify listeners of a multiple message delete
nsCOMPtr<nsIMsgFolderNotificationService> notifier(do_GetService(NS_MSGNOTIFICATIONSERVICE_CONTRACTID));

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

@ -716,8 +716,13 @@ nsNntpService::CopyMessage(const char * aSrcMessageURI, nsIStreamListener * aMai
}
NS_IMETHODIMP
nsNntpService::CopyMessages(nsTArray<nsMsgKey> &keys, nsIMsgFolder *srcFolder, nsIStreamListener * aMailboxCopyHandler, PRBool moveMessage,
nsIUrlListener * aUrlListener, nsIMsgWindow *aMsgWindow, nsIURI **aURL)
nsNntpService::CopyMessages(PRUint32 aNumKeys, nsMsgKey *akeys,
nsIMsgFolder *srcFolder,
nsIStreamListener * aMailboxCopyHandler,
PRBool moveMessage,
nsIUrlListener * aUrlListener,
nsIMsgWindow *aMsgWindow,
nsIURI **aURL)
{
return NS_ERROR_NOT_IMPLEMENTED;
}