Bug 1681009 - Remove nsIMutableArray use from nsIMsgMailView, nsIMsgFilter and nsIMsgSearchSession. r=mkmelin

This commit is contained in:
Ben Campbell 2020-12-07 17:26:44 +13:00
Родитель c07c94d0fd
Коммит ee79f6c3fd
40 изменённых файлов: 230 добавлений и 289 удалений

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

@ -4,9 +4,6 @@
const EXPORTED_SYMBOLS = ["SearchSpec"];
const { fixIterator } = ChromeUtils.import(
"resource:///modules/iteratorUtils.jsm"
);
const { MailServices } = ChromeUtils.import(
"resource:///modules/MailServices.jsm"
);
@ -158,7 +155,7 @@ SearchSpec.prototype = {
let iTerm = 0,
term;
let outTerms = aCloneTerms ? [] : aTerms;
for (term of fixIterator(aTerms, Ci.nsIMsgSearchTerm)) {
for (term of aTerms) {
if (aCloneTerms) {
let cloneTerm = this.session.createTerm();
cloneTerm.value = term.value;
@ -205,7 +202,7 @@ SearchSpec.prototype = {
let term;
let outTerms = aCloneTerms ? [] : aTerms;
let inGroup = false;
for (term of fixIterator(aTerms, Ci.nsIMsgSearchTerm)) {
for (term of aTerms) {
// If we're in a group, all that is forbidden is the creation of new
// groups.
if (inGroup) {
@ -363,27 +360,24 @@ SearchSpec.prototype = {
let session = this.session;
// clear out our current terms and scope
session.searchTerms.clear();
session.searchTerms = [];
session.clearScopes();
// -- apply terms
if (this._virtualFolderTerms) {
for (let term of fixIterator(
this._virtualFolderTerms,
Ci.nsIMsgSearchTerm
)) {
for (let term of this._virtualFolderTerms) {
session.appendTerm(term);
}
}
if (this._viewTerms) {
for (let term of fixIterator(this._viewTerms, Ci.nsIMsgSearchTerm)) {
for (let term of this._viewTerms) {
session.appendTerm(term);
}
}
if (this._userTerms) {
for (let term of fixIterator(this._userTerms, Ci.nsIMsgSearchTerm)) {
for (let term of this._userTerms) {
session.appendTerm(term);
}
}
@ -432,10 +426,7 @@ SearchSpec.prototype = {
let offlineValidityTable = validityManager.getTable(offlineScope);
let offlineAvailable = true;
let onlineAvailable = true;
for (let term of fixIterator(
session.searchTerms,
Ci.nsIMsgSearchTerm
)) {
for (let term of session.searchTerms) {
if (!term.matchAll) {
// for custom terms, we need to getAvailable from the custom term
if (term.attrib == Ci.nsMsgSearchAttrib.Custom) {
@ -489,7 +480,7 @@ SearchSpec.prototype = {
let s = "";
for (let term of fixIterator(aSearchTerms, Ci.nsIMsgSearchTerm)) {
for (let term of aSearchTerms) {
s += " " + term.termAsString + "\n";
}

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

@ -25,7 +25,6 @@ var searchSessionContractID = "@mozilla.org/messenger/searchSession;1";
var gSearchSession;
var nsMsgSearchScope = Ci.nsMsgSearchScope;
var nsIMsgSearchTerm = Ci.nsIMsgSearchTerm;
var nsMsgSearchOp = Ci.nsMsgSearchOp;
var nsMsgSearchAttrib = Ci.nsMsgSearchAttrib;
var nsIAbDirectory = Ci.nsIAbDirectory;
@ -186,15 +185,14 @@ function onSearch() {
var currentAbURI = document.getElementById("abPopup").getAttribute("value");
gSearchSession.addDirectoryScopeTerm(GetScopeForDirectoryURI(currentAbURI));
saveSearchTerms(gSearchSession.searchTerms, gSearchSession);
gSearchSession.searchTerms = saveSearchTerms(
gSearchSession.searchTerms,
gSearchSession
);
let searchUri = "?(";
for (let i = 0; i < gSearchSession.searchTerms.length; i++) {
let searchTerm = gSearchSession.searchTerms.queryElementAt(
i,
nsIMsgSearchTerm
);
let searchTerm = gSearchSession.searchTerms[i];
// get the "and" / "or" value from the first term
if (i == 0) {
if (searchTerm.booleanAnd) {

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

@ -55,7 +55,7 @@ function onOK() {
// reflect the search widgets back into the search session
var newMailView = null;
if (gMailView) {
saveSearchTerms(gMailView.searchTerms, gMailView);
gMailView.searchTerms = saveSearchTerms(gMailView.searchTerms, gMailView);
// if the name of the view has been changed...
if (gMailView.prettyName != dialog.nameField.value) {
gMailView.mailViewName = dialog.nameField.value;
@ -64,7 +64,10 @@ function onOK() {
// otherwise, create a new mail view
newMailView = mailViewList.createMailView();
saveSearchTerms(newMailView.searchTerms, newMailView);
newMailView.searchTerms = saveSearchTerms(
newMailView.searchTerms,
newMailView
);
newMailView.mailViewName = dialog.nameField.value;
// now add the mail view to our mail view list
mailViewList.addMailView(newMailView);

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

@ -71,10 +71,7 @@ function onLoad() {
if (windowArgs.searchTerms) {
// then add them to our search session
for (let searchTerm of fixIterator(
windowArgs.searchTerms,
Ci.nsIMsgSearchTerm
)) {
for (let searchTerm of windowArgs.searchTerms) {
gSearchTermSession.appendTerm(searchTerm);
}
}
@ -217,7 +214,10 @@ function onOK(event) {
if (window.arguments[0].editExistingFolder) {
// update the search terms
saveSearchTerms(gSearchTermSession.searchTerms, gSearchTermSession);
gSearchTermSession.searchTerms = saveSearchTerms(
gSearchTermSession.searchTerms,
gSearchTermSession
);
// save the settings
let virtualFolderWrapper = VirtualFolderHelper.wrapVirtualFolder(
window.arguments[0].folder
@ -274,7 +274,10 @@ function onOK(event) {
return;
}
saveSearchTerms(gSearchTermSession.searchTerms, gSearchTermSession);
gSearchTermSession.searchTerms = saveSearchTerms(
gSearchTermSession.searchTerms,
gSearchTermSession
);
VirtualFolderHelper.createNewVirtualFolder(
name,
parentFolder,

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

@ -29,8 +29,8 @@ var VirtualFolderHelper = {
* @param aSearchFolders A list of nsIMsgFolders that you want to use as the
* sources for the virtual folder OR a string that is the already '|'
* delimited list of folder URIs to use.
* @param aSearchTerms The search terms to use for the virtual folder. This
* should be a JS list/nsIMutableArray of nsIMsgSearchTerms.
* @param {nsIMsgSearchTerms[]} aSearchTerms - The search terms to
* use for the virtual folder.
* @param aOnlineSearch Should the search attempt to use the server's search
* capabilities when possible and appropriate?
*
@ -189,7 +189,7 @@ VirtualFolderWrapper.prototype = {
*/
set searchTerms(aTerms) {
let condition = "";
for (let term of fixIterator(aTerms, Ci.nsIMsgSearchTerm)) {
for (let term of aTerms) {
if (condition.length) {
condition += " ";
}

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

@ -2265,8 +2265,8 @@ nsresult VirtualFolderChangeListener::Init() {
m_searchSession = do_CreateInstance(NS_MSGSEARCHSESSION_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIMutableArray> searchTerms;
rv = tempFilter->GetSearchTerms(getter_AddRefs(searchTerms));
nsTArray<RefPtr<nsIMsgSearchTerm>> searchTerms;
rv = tempFilter->GetSearchTerms(searchTerms);
NS_ENSURE_SUCCESS(rv, rv);
// we add the search scope right before we match the header,
@ -2274,11 +2274,8 @@ nsresult VirtualFolderChangeListener::Init() {
// stream, because that holds onto the mailbox file, breaking
// compaction.
// add each item in termsArray to the search session
uint32_t numTerms;
searchTerms->Count(&numTerms);
for (uint32_t i = 0; i < numTerms; i++) {
nsCOMPtr<nsIMsgSearchTerm> searchTerm(do_QueryElementAt(searchTerms, i));
// add each search term to the search session
for (nsIMsgSearchTerm* searchTerm : searchTerms) {
nsMsgSearchAttribValue attrib;
searchTerm->GetAttrib(&attrib);
if (attrib == nsMsgSearchAttrib::MsgStatus) m_searchOnMsgStatus = true;

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

@ -1729,23 +1729,15 @@ nsresult nsMsgIncomingServer::ConfigureTemporaryServerSpamFilters(
*/
// get the list of search terms from the filter
nsCOMPtr<nsIMutableArray> searchTerms;
rv = newFilter->GetSearchTerms(getter_AddRefs(searchTerms));
nsTArray<RefPtr<nsIMsgSearchTerm>> searchTerms;
rv = newFilter->GetSearchTerms(searchTerms);
NS_ENSURE_SUCCESS(rv, rv);
uint32_t count = 0;
searchTerms->Count(&count);
uint32_t count = searchTerms.Length();
if (count > 1) // don't need to group a single term
{
// beginGrouping the first term, and endGrouping the last term
nsCOMPtr<nsIMsgSearchTerm> firstTerm(
do_QueryElementAt(searchTerms, 0, &rv));
NS_ENSURE_SUCCESS(rv, rv);
firstTerm->SetBeginsGrouping(true);
nsCOMPtr<nsIMsgSearchTerm> lastTerm(
do_QueryElementAt(searchTerms, count - 1, &rv));
NS_ENSURE_SUCCESS(rv, rv);
lastTerm->SetEndsGrouping(true);
searchTerms[0]->SetBeginsGrouping(true);
searchTerms[count - 1]->SetEndsGrouping(true);
}
// Create a new term, checking if the user set junk status. The term will
@ -1765,7 +1757,7 @@ nsresult nsMsgIncomingServer::ConfigureTemporaryServerSpamFilters(
searchValue->SetStr(u"user"_ns);
searchTerm->SetValue(searchValue);
searchTerms->InsertElementAt(searchTerm, count);
newFilter->AppendTerm(searchTerm);
bool moveOnSpam, markAsReadOnSpam;
spamSettings->GetMoveOnSpam(&moveOnSpam);

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

@ -1634,18 +1634,13 @@ NS_MSG_BASE PRTime MsgConvertAgeInDaysToCutoffDate(int32_t ageInDays) {
return now - PR_USEC_PER_DAY * ageInDays;
}
NS_MSG_BASE nsresult MsgTermListToString(nsIArray* aTermList,
nsCString& aOutString) {
uint32_t count;
aTermList->GetLength(&count);
NS_MSG_BASE nsresult
MsgTermListToString(nsTArray<RefPtr<nsIMsgSearchTerm>> const& aTermList,
nsCString& aOutString) {
nsresult rv = NS_OK;
for (uint32_t searchIndex = 0; searchIndex < count; searchIndex++) {
for (nsIMsgSearchTerm* term : aTermList) {
nsAutoCString stream;
nsCOMPtr<nsIMsgSearchTerm> term = do_QueryElementAt(aTermList, searchIndex);
if (!term) continue;
if (aOutString.Length() > 1) aOutString += ' ';
bool booleanAnd;

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

@ -37,6 +37,7 @@ class nsIMsgWindow;
class nsIStreamListener;
class nsICancelable;
class nsIProtocolProxyCallback;
class nsIMsgSearchTerm;
#define FILE_IO_BUFFER_SIZE (16 * 1024)
#define MSGS_URL "chrome://messenger/locale/messenger.properties"
@ -300,8 +301,8 @@ NS_MSG_BASE PRTime MsgConvertAgeInDaysToCutoffDate(int32_t ageInDays);
* @param[out] aOutString result representation of search terms.
*
*/
NS_MSG_BASE nsresult MsgTermListToString(nsIArray* aTermList,
nsCString& aOutString);
NS_MSG_BASE nsresult MsgTermListToString(
nsTArray<RefPtr<nsIMsgSearchTerm>> const& aTermList, nsCString& aOutString);
NS_MSG_BASE nsresult MsgStreamMsgHeaders(nsIInputStream* aInputStream,
nsIStreamListener* aConsumer);

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

@ -13,10 +13,10 @@
#include "nsIMsgCopyService.h"
#include "nsMsgUtils.h"
#include "nsIMsgSearchSession.h"
#include "nsIMsgSearchTerm.h"
#include "nsMsgDBCID.h"
#include "nsMsgMessageFlags.h"
#include "nsServiceManagerUtils.h"
#include "nsIMutableArray.h"
nsMsgXFVirtualFolderDBView::nsMsgXFVirtualFolderDBView() {
mSuppressMsgDisplay = false;
@ -380,8 +380,8 @@ nsMsgXFVirtualFolderDBView::OnNewSearch() {
nsCString terms;
dbFolderInfo->GetCharProperty("searchStr", terms);
nsCOMPtr<nsIMutableArray> searchTerms;
rv = searchSession->GetSearchTerms(getter_AddRefs(searchTerms));
nsTArray<RefPtr<nsIMsgSearchTerm>> searchTerms;
rv = searchSession->GetSearchTerms(searchTerms);
NS_ENSURE_SUCCESS(rv, rv);
nsCString curSearchAsString;

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

@ -6,7 +6,6 @@
#include "nsISupports.idl"
interface nsIMutableArray;
interface nsIMsgSearchTerm;
[scriptable, uuid(28AC84DF-CBE5-430d-A5C0-4FA63B5424DF)]
@ -15,7 +14,7 @@ interface nsIMsgMailView : nsISupports {
readonly attribute wstring prettyName; // localized pretty name
// the array of search terms
attribute nsIMutableArray searchTerms;
attribute Array<nsIMsgSearchTerm> searchTerms;
// these two helper methods are required to allow searchTermsOverlay.js to
// manipulate a mail view without knowing it is dealing with a mail view. nsIMsgFilter

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

@ -5,7 +5,6 @@
#include "nsMsgMailViewList.h"
#include "nsArray.h"
#include "nsIMutableArray.h"
#include "nsIMsgFilterService.h"
#include "nsIMsgMailSession.h"
#include "nsIMsgSearchTerm.h"
@ -16,7 +15,6 @@
#include "nsComponentManagerUtils.h"
#include "mozilla/Services.h"
#include "nsIMsgFilter.h"
#include "nsArrayUtils.h"
#define kDefaultViewPeopleIKnow "People I Know"
#define kDefaultViewRecent "Recent Mail"
@ -24,19 +22,13 @@
#define kDefaultViewNotJunk "Not Junk"
#define kDefaultViewHasAttachments "Has Attachments"
nsMsgMailView::nsMsgMailView() {
mViewSearchTerms = nsArray::Create();
NS_ASSERTION(mViewSearchTerms,
"Failed to allocate a nsIMutableArray for mViewSearchTerms");
}
nsMsgMailView::nsMsgMailView() {}
NS_IMPL_ADDREF(nsMsgMailView)
NS_IMPL_RELEASE(nsMsgMailView)
NS_IMPL_QUERY_INTERFACE(nsMsgMailView, nsIMsgMailView)
nsMsgMailView::~nsMsgMailView() {
if (mViewSearchTerms) mViewSearchTerms->Clear();
}
nsMsgMailView::~nsMsgMailView() {}
NS_IMETHODIMP nsMsgMailView::GetMailViewName(char16_t** aMailViewName) {
NS_ENSURE_ARG_POINTER(aMailViewName);
@ -90,21 +82,23 @@ NS_IMETHODIMP nsMsgMailView::GetPrettyName(char16_t** aMailViewName) {
return rv;
}
NS_IMETHODIMP nsMsgMailView::GetSearchTerms(nsIMutableArray** aSearchTerms) {
NS_ENSURE_ARG_POINTER(aSearchTerms);
NS_IF_ADDREF(*aSearchTerms = mViewSearchTerms);
NS_IMETHODIMP nsMsgMailView::GetSearchTerms(
nsTArray<RefPtr<nsIMsgSearchTerm>>& terms) {
terms = mViewSearchTerms.Clone();
return NS_OK;
}
NS_IMETHODIMP nsMsgMailView::SetSearchTerms(nsIMutableArray* aSearchTerms) {
mViewSearchTerms = aSearchTerms;
NS_IMETHODIMP nsMsgMailView::SetSearchTerms(
nsTArray<RefPtr<nsIMsgSearchTerm>> const& terms) {
mViewSearchTerms = terms.Clone();
return NS_OK;
}
NS_IMETHODIMP nsMsgMailView::AppendTerm(nsIMsgSearchTerm* aTerm) {
NS_ENSURE_TRUE(aTerm, NS_ERROR_NULL_POINTER);
return mViewSearchTerms->AppendElement(aTerm);
mViewSearchTerms.AppendElement(aTerm);
return NS_OK;
}
NS_IMETHODIMP nsMsgMailView::CreateTerm(nsIMsgSearchTerm** aResult) {
@ -195,8 +189,8 @@ nsresult nsMsgMailViewList::ConvertMailViewListToFilterList() {
mFilterList->CreateFilter(mailViewName, getter_AddRefs(newMailFilter));
if (!newMailFilter) continue;
nsCOMPtr<nsIMutableArray> searchTerms;
mailView->GetSearchTerms(getter_AddRefs(searchTerms));
nsTArray<RefPtr<nsIMsgSearchTerm>> searchTerms;
mailView->GetSearchTerms(searchTerms);
newMailFilter->SetSearchTerms(searchTerms);
mFilterList->InsertFilterAt(index, newMailFilter);
}
@ -274,8 +268,8 @@ nsresult nsMsgMailViewList::ConvertFilterListToMailViews() {
msgFilter->GetFilterName(filterName);
newMailView->SetMailViewName(filterName.get());
nsCOMPtr<nsIMutableArray> filterSearchTerms;
rv = msgFilter->GetSearchTerms(getter_AddRefs(filterSearchTerms));
nsTArray<RefPtr<nsIMsgSearchTerm>> filterSearchTerms;
rv = msgFilter->GetSearchTerms(filterSearchTerms);
NS_ENSURE_SUCCESS(rv, rv);
rv = newMailView->SetSearchTerms(filterSearchTerms);
NS_ENSURE_SUCCESS(rv, rv);

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

@ -10,7 +10,6 @@
#include "nsIMsgMailViewList.h"
#include "nsCOMPtr.h"
#include "nsCOMArray.h"
#include "nsIMutableArray.h"
#include "nsIStringBundle.h"
#include "nsString.h"
#include "nsIMsgFilterList.h"
@ -27,7 +26,7 @@ class nsMsgMailView : public nsIMsgMailView {
virtual ~nsMsgMailView();
nsString mName;
nsCOMPtr<nsIStringBundle> mBundle;
nsCOMPtr<nsIMutableArray> mViewSearchTerms;
nsTArray<RefPtr<nsIMsgSearchTerm>> mViewSearchTerms;
};
class nsMsgMailViewList : public nsIMsgMailViewList {

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

@ -681,16 +681,9 @@ NS_IMETHODIMP nsImapMailFolder::UpdateFolderWithListener(
bool enabled = false;
filter->GetEnabled(&enabled);
if (!enabled) continue;
nsCOMPtr<nsIMutableArray> searchTerms;
uint32_t numSearchTerms = 0;
filter->GetSearchTerms(getter_AddRefs(searchTerms));
if (searchTerms) searchTerms->Count(&numSearchTerms);
for (uint32_t termIndex = 0;
termIndex < numSearchTerms && !m_filterListRequiresBody;
termIndex++) {
nsCOMPtr<nsIMsgSearchTerm> term =
do_QueryElementAt(searchTerms, termIndex, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsTArray<RefPtr<nsIMsgSearchTerm>> searchTerms;
filter->GetSearchTerms(searchTerms);
for (nsIMsgSearchTerm* term : searchTerms) {
nsMsgSearchAttribValue attrib;
rv = term->GetAttrib(&attrib);
NS_ENSURE_SUCCESS(rv, rv);
@ -708,6 +701,9 @@ NS_IMETHODIMP nsImapMailFolder::UpdateFolderWithListener(
rv = customTerm->GetNeedsBody(&needsBody);
if (NS_SUCCEEDED(rv) && needsBody) m_filterListRequiresBody = true;
}
if (m_filterListRequiresBody) {
break;
}
}
// Also check if filter actions need the body, as this

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

@ -158,12 +158,7 @@ function filterEditorOnLoad() {
}
// copy the search terms
for (let i = 0; i < copiedFilter.searchTerms.length; i++) {
let searchTerm = copiedFilter.searchTerms.queryElementAt(
i,
Ci.nsIMsgSearchTerm
);
for (let searchTerm of copiedFilter.searchTerms) {
let newTerm = newFilter.createTerm();
newTerm.attrib = searchTerm.attrib;
newTerm.op = searchTerm.op;
@ -581,7 +576,7 @@ function saveFilter() {
}
gFilter.filterType = gFilterType;
saveSearchTerms(gFilter.searchTerms, gFilter);
gFilter.searchTerms = saveSearchTerms(gFilter.searchTerms, gFilter);
if (isNewFilter) {
// new filter - insert into gFilterList

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

@ -148,8 +148,6 @@ searchTermContainer.prototype = {
},
};
var nsIMsgSearchTerm = Ci.nsIMsgSearchTerm;
function initializeSearchWidgets() {
gSearchBooleanRadiogroup = document.getElementById("booleanAndGroup");
gSearchTermList = document.getElementById("searchTermList");
@ -192,7 +190,7 @@ function initializeBooleanWidgets() {
function initializeSearchRows(scope, searchTerms) {
for (let i = 0; i < searchTerms.length; i++) {
let searchTerm = searchTerms.queryElementAt(i, nsIMsgSearchTerm);
let searchTerm = searchTerms[i];
createSearchRow(i, scope, searchTerm, false);
gTotalSearchTerms++;
}
@ -513,17 +511,19 @@ function removeSearchRow(index) {
gSearchTerms.splice(index, 1);
}
// save the search terms from the UI back to the actual search terms
// searchTerms: nsIMutableArray of terms
// termOwner: object which can contain and create the terms
// (will be unnecessary if we just make terms creatable
// via XPCOM)
/**
* Save the search terms from the UI back to the actual search terms.
* @param {nsIMsgSearchTerm[]} searchTerms - Array of terms
* @param {Object} termOwner - Object which can contain and create the terms
* e.g. a nsIMsgSearchSession (will be unnecessary if we just make terms
* creatable via XPCOM).
* @returns {nsIMsgSearchTerm[]} The filtered searchTerms.
*/
function saveSearchTerms(searchTerms, termOwner) {
var matchAll = gSearchBooleanRadiogroup.value == "matchAll";
var i;
for (i = 0; i < gSearchRemovedTerms.length; i++) {
searchTerms.removeElementAt(searchTerms.indexOf(0, gSearchRemovedTerms[i]));
}
searchTerms = searchTerms.filter(t => !gSearchRemovedTerms.includes(t));
for (i = 0; i < gSearchTerms.length; i++) {
try {
@ -542,11 +542,12 @@ function saveSearchTerms(searchTerms, termOwner) {
// but we need to make the array longer anyway
termOwner.appendTerm(searchTerm);
}
searchTerms.replaceElementAt(searchTerm, i);
searchTerms[i] = searchTerm;
} catch (ex) {
dump("** Error saving element " + i + ": " + ex + "\n");
}
}
return searchTerms;
}
function onReset(event) {

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

@ -7,7 +7,6 @@
#include "nsISupports.idl"
#include "nsMsgFilterCore.idl"
interface nsIMutableArray;
interface nsIOutputStream;
interface nsIMsgFilterCustomAction;
interface nsIMsgFilterList;
@ -77,7 +76,7 @@ interface nsIMsgFilter : nsISupports {
nsIMsgSearchTerm createTerm();
attribute nsIMutableArray searchTerms;
attribute Array<nsIMsgSearchTerm> searchTerms;
attribute nsIMsgSearchScopeTerm scope;

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

@ -6,7 +6,6 @@
#include "nsISupports.idl"
#include "nsIMsgSearchValue.idl"
interface nsIMutableArray;
interface nsIMsgSearchAdapter;
interface nsIMsgSearchTerm;
interface nsIMsgSearchNotify;
@ -40,7 +39,7 @@ interface nsIMsgSearchSession : nsISupports {
in boolean BooleanAND,
in string customString);
attribute nsIMutableArray searchTerms;
attribute Array<nsIMsgSearchTerm> searchTerms;
nsIMsgSearchTerm createTerm();
void appendTerm(in nsIMsgSearchTerm term);

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

@ -28,20 +28,22 @@ class nsIMsgSearchScopeTerm;
class nsMsgSearchAdapter : public nsIMsgSearchAdapter {
public:
nsMsgSearchAdapter(nsIMsgSearchScopeTerm*, nsIArray*);
nsMsgSearchAdapter(nsIMsgSearchScopeTerm*,
nsTArray<RefPtr<nsIMsgSearchTerm>> const&);
NS_DECL_ISUPPORTS
NS_DECL_NSIMSGSEARCHADAPTER
nsIMsgSearchScopeTerm* m_scope;
nsCOMPtr<nsIArray> m_searchTerms; /* linked list of criteria terms */
nsTArray<RefPtr<nsIMsgSearchTerm>>
m_searchTerms; /* linked list of criteria terms */
nsString m_defaultCharset = u"UTF-8"_ns;
static nsresult EncodeImap(char** ppEncoding, nsIArray* searchTerms,
const char16_t* srcCharset,
const char16_t* destCharset,
bool reallyDredd = false);
static nsresult EncodeImap(
char** ppEncoding, nsTArray<RefPtr<nsIMsgSearchTerm>> const& searchTerms,
const char16_t* srcCharset, const char16_t* destCharset,
bool reallyDredd = false);
static nsresult EncodeImapValue(char* encoding, const char* value,
bool useQuotes, bool reallyDredd);

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

@ -25,7 +25,8 @@ class nsMsgSearchScopeTerm : public nsIMsgSearchScopeTerm {
NS_DECL_NSIMSGSEARCHSCOPETERM
nsresult TimeSlice(bool* aDone);
nsresult InitializeAdapter(nsIArray* termList);
nsresult InitializeAdapter(
nsTArray<RefPtr<nsIMsgSearchTerm>> const& termList);
char* GetStatusBarName();

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

@ -6,7 +6,6 @@
// this file implements the nsMsgFilter interface
#include "msgCore.h"
#include "nsArray.h"
#include "nsArrayUtils.h"
#include "nsMsgBaseCID.h"
#include "nsIMsgHdr.h"
@ -20,7 +19,6 @@
#include "nsMsgSearchValue.h"
#include "nsMsgI18N.h"
#include "nsNativeCharsetUtils.h"
#include "nsIMutableArray.h"
#include "nsIOutputStream.h"
#include "nsIStringBundle.h"
#include "nsComponentManagerUtils.h"
@ -157,10 +155,6 @@ nsMsgFilter::nsMsgFilter()
m_unparseable(false),
m_filterList(nullptr),
m_expressionTree(nullptr) {
m_termList = nsArray::Create();
NS_ASSERTION(m_termList,
"Failed to allocate a nsIMutableArray for m_termList");
m_type = nsMsgFilterType::InboxRule | nsMsgFilterType::Manual;
}
@ -220,7 +214,8 @@ NS_IMETHODIMP nsMsgFilter::AppendTerm(nsIMsgSearchTerm* aTerm) {
// invalidate expression tree if we're changing the terms
delete m_expressionTree;
m_expressionTree = nullptr;
return m_termList->AppendElement(aTerm);
m_termList.AppendElement(aTerm);
return NS_OK;
}
NS_IMETHODIMP
@ -363,34 +358,34 @@ NS_IMETHODIMP nsMsgFilter::GetTerm(
nsACString& arbitraryHeader) /* arbitrary header specified by user.ignore
unless attrib = attribOtherHeader */
{
nsresult rv;
nsCOMPtr<nsIMsgSearchTerm> term =
do_QueryElementAt(m_termList, termIndex, &rv);
if (NS_SUCCEEDED(rv) && term) {
if (attrib) term->GetAttrib(attrib);
if (op) term->GetOp(op);
if (value) term->GetValue(value);
if (booleanAnd) term->GetBooleanAnd(booleanAnd);
if (attrib && *attrib > nsMsgSearchAttrib::OtherHeader &&
*attrib < nsMsgSearchAttrib::kNumMsgSearchAttributes)
term->GetArbitraryHeader(arbitraryHeader);
if (termIndex >= (int32_t)m_termList.Length()) {
return NS_ERROR_INVALID_ARG;
}
nsIMsgSearchTerm* term = m_termList[termIndex];
if (attrib) term->GetAttrib(attrib);
if (op) term->GetOp(op);
if (value) term->GetValue(value);
if (booleanAnd) term->GetBooleanAnd(booleanAnd);
if (attrib && *attrib > nsMsgSearchAttrib::OtherHeader &&
*attrib < nsMsgSearchAttrib::kNumMsgSearchAttributes) {
term->GetArbitraryHeader(arbitraryHeader);
}
return NS_OK;
}
NS_IMETHODIMP nsMsgFilter::GetSearchTerms(nsIMutableArray** aResult) {
NS_ENSURE_ARG_POINTER(aResult);
// caller can change m_termList, which can invalidate m_expressionTree.
NS_IMETHODIMP nsMsgFilter::GetSearchTerms(
nsTArray<RefPtr<nsIMsgSearchTerm>>& terms) {
delete m_expressionTree;
m_expressionTree = nullptr;
NS_IF_ADDREF(*aResult = m_termList);
terms = m_termList.Clone();
return NS_OK;
}
NS_IMETHODIMP nsMsgFilter::SetSearchTerms(nsIMutableArray* aSearchList) {
NS_IMETHODIMP nsMsgFilter::SetSearchTerms(
nsTArray<RefPtr<nsIMsgSearchTerm>> const& terms) {
delete m_expressionTree;
m_expressionTree = nullptr;
m_termList = aSearchList;
m_termList = terms.Clone();
return NS_OK;
}

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

@ -91,8 +91,8 @@ class nsMsgFilter : public nsIMsgFilter {
bool m_enabled;
bool m_temporary;
bool m_unparseable;
nsIMsgFilterList* m_filterList; /* owning filter list */
nsCOMPtr<nsIMutableArray> m_termList; /* linked list of criteria terms */
nsIMsgFilterList* m_filterList; /* owning filter list */
nsTArray<RefPtr<nsIMsgSearchTerm>> m_termList; /* criteria terms */
nsCOMPtr<nsIMsgSearchScopeTerm>
m_scope; /* default for mail rules is inbox, but news rules could
have a newsgroup - LDAP would be invalid */

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

@ -446,8 +446,7 @@ int nsMsgFilterList::ReadChar(nsIInputStream* aStream) {
uint32_t bytesRead;
uint64_t bytesAvailable;
nsresult rv = aStream->Available(&bytesAvailable);
if (NS_FAILED(rv) || bytesAvailable == 0)
return EOF_CHAR;
if (NS_FAILED(rv) || bytesAvailable == 0) return EOF_CHAR;
rv = aStream->Read(&newChar, 1, &bytesRead);
if (NS_FAILED(rv) || !bytesRead) return EOF_CHAR;
@ -1106,11 +1105,9 @@ nsresult nsMsgFilterList::ComputeArbitraryHeaders() {
rv = GetFilterAt(index, getter_AddRefs(filter));
if (!(NS_SUCCEEDED(rv) && filter)) continue;
nsCOMPtr<nsIMutableArray> searchTerms;
uint32_t numSearchTerms = 0;
filter->GetSearchTerms(getter_AddRefs(searchTerms));
if (searchTerms) searchTerms->GetLength(&numSearchTerms);
for (uint32_t i = 0; i < numSearchTerms; i++) {
nsTArray<RefPtr<nsIMsgSearchTerm>> searchTerms;
filter->GetSearchTerms(searchTerms);
for (uint32_t i = 0; i < searchTerms.Length(); i++) {
filter->GetTerm(i, &attrib, nullptr, nullptr, nullptr, arbitraryHeader);
if (!arbitraryHeader.IsEmpty()) {
if (m_arbitraryHeaders.IsEmpty())

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

@ -458,8 +458,8 @@ nsresult nsMsgFilterAfterTheFact::RunNextFilter() {
("(Post) Filter name: %s", NS_ConvertUTF16toUTF8(filterName).get()));
// clang-format on
nsCOMPtr<nsIMutableArray> searchTerms;
rv = m_curFilter->GetSearchTerms(getter_AddRefs(searchTerms));
nsTArray<RefPtr<nsIMsgSearchTerm>> searchTerms;
rv = m_curFilter->GetSearchTerms(searchTerms);
CONTINUE_IF_FAILURE(rv, "Could not get searchTerms");
if (m_searchSession) m_searchSession->UnregisterListener(this);
@ -467,12 +467,7 @@ nsresult nsMsgFilterAfterTheFact::RunNextFilter() {
BREAK_IF_FAILURE(rv, "Failed to get search session");
nsMsgSearchScopeValue searchScope = nsMsgSearchScope::offlineMail;
uint32_t termCount = 0;
searchTerms->GetLength(&termCount);
for (uint32_t termIndex = 0; termIndex < termCount; termIndex++) {
nsCOMPtr<nsIMsgSearchTerm> term =
do_QueryElementAt(searchTerms, termIndex, &rv);
BREAK_IF_FAILURE(rv, "Could not get search term");
for (nsIMsgSearchTerm* term : searchTerms) {
rv = m_searchSession->AppendTerm(term);
BREAK_IF_FAILURE(rv, "Could not append search term");
}

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

@ -16,8 +16,9 @@
#include "nsIImapIncomingServer.h"
// Implementation of search for IMAP mail folders
nsMsgSearchOnlineMail::nsMsgSearchOnlineMail(nsMsgSearchScopeTerm* scope,
nsIArray* termList)
nsMsgSearchOnlineMail::nsMsgSearchOnlineMail(
nsMsgSearchScopeTerm* scope,
nsTArray<RefPtr<nsIMsgSearchTerm>> const& termList)
: nsMsgSearchAdapter(scope, termList) {}
nsMsgSearchOnlineMail::~nsMsgSearchOnlineMail() {}
@ -67,10 +68,9 @@ nsresult nsMsgSearchOnlineMail::Search(bool* aDone) {
return err;
}
nsresult nsMsgSearchOnlineMail::Encode(nsCString& pEncoding,
nsIArray* searchTerms,
const char16_t* destCharset,
nsIMsgSearchScopeTerm* scope) {
nsresult nsMsgSearchOnlineMail::Encode(
nsCString& pEncoding, nsTArray<RefPtr<nsIMsgSearchTerm>> const& searchTerms,
const char16_t* destCharset, nsIMsgSearchScopeTerm* scope) {
nsCString imapTerms;
// check if searchTerms are ascii only
@ -81,13 +81,7 @@ nsresult nsMsgSearchOnlineMail::Encode(nsCString& pEncoding,
// CODESET_MASK == WIDECHAR) )
// assume all single/multiple bytes charset has ascii as subset
{
uint32_t termCount;
searchTerms->GetLength(&termCount);
uint32_t i = 0;
for (i = 0; i < termCount && asciiOnly; i++) {
nsCOMPtr<nsIMsgSearchTerm> pTerm = do_QueryElementAt(searchTerms, i);
for (nsIMsgSearchTerm* pTerm : searchTerms) {
nsMsgSearchAttribValue attribute;
pTerm->GetAttrib(&attribute);
if (IS_STRING_ATTRIBUTE(attribute)) {
@ -101,6 +95,9 @@ nsresult nsMsgSearchOnlineMail::Encode(nsCString& pEncoding,
if (NS_FAILED(rv) || pchar.IsEmpty()) continue;
asciiOnly = mozilla::IsAsciiNullTerminated(
static_cast<const char16_t*>(pchar.get()));
if (!asciiOnly) {
break;
}
}
}
}

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

@ -14,8 +14,6 @@
#include "nsMsgSearchTerm.h"
#include "nsMsgResultElement.h"
#include "nsIDBFolderInfo.h"
#include "nsIArray.h"
#include "nsArrayUtils.h"
#include "nsMsgBaseCID.h"
#include "nsMsgSearchValue.h"
#include "nsIMsgLocalMailFolder.h"
@ -239,8 +237,9 @@ void nsMsgSearchBoolExpression::GenerateEncodeStr(nsCString* buffer)
NS_IMPL_ISUPPORTS_INHERITED(nsMsgSearchOfflineMail, nsMsgSearchAdapter,
nsIUrlListener)
nsMsgSearchOfflineMail::nsMsgSearchOfflineMail(nsIMsgSearchScopeTerm* scope,
nsIArray* termList)
nsMsgSearchOfflineMail::nsMsgSearchOfflineMail(
nsIMsgSearchScopeTerm* scope,
nsTArray<RefPtr<nsIMsgSearchTerm>> const& termList)
: nsMsgSearchAdapter(scope, termList) {}
nsMsgSearchOfflineMail::~nsMsgSearchOfflineMail() {
@ -301,8 +300,9 @@ nsresult nsMsgSearchOfflineMail::OpenSummaryFile() {
}
nsresult nsMsgSearchOfflineMail::MatchTermsForFilter(
nsIMsgDBHdr* msgToMatch, nsIArray* termList, const char* defaultCharset,
nsIMsgSearchScopeTerm* scope, nsIMsgDatabase* db, const nsACString& headers,
nsIMsgDBHdr* msgToMatch, nsTArray<RefPtr<nsIMsgSearchTerm>> const& termList,
const char* defaultCharset, nsIMsgSearchScopeTerm* scope,
nsIMsgDatabase* db, const nsACString& headers,
nsMsgSearchBoolExpression** aExpressionTree, bool* pResult) {
return MatchTerms(msgToMatch, termList, defaultCharset, scope, db, headers,
true, aExpressionTree, pResult);
@ -310,23 +310,23 @@ nsresult nsMsgSearchOfflineMail::MatchTermsForFilter(
// static method which matches a header against a list of search terms.
nsresult nsMsgSearchOfflineMail::MatchTermsForSearch(
nsIMsgDBHdr* msgToMatch, nsIArray* termList, const char* defaultCharset,
nsIMsgSearchScopeTerm* scope, nsIMsgDatabase* db,
nsMsgSearchBoolExpression** aExpressionTree, bool* pResult) {
nsIMsgDBHdr* msgToMatch, nsTArray<RefPtr<nsIMsgSearchTerm>> const& termList,
const char* defaultCharset, nsIMsgSearchScopeTerm* scope,
nsIMsgDatabase* db, nsMsgSearchBoolExpression** aExpressionTree,
bool* pResult) {
return MatchTerms(msgToMatch, termList, defaultCharset, scope, db,
EmptyCString(), false, aExpressionTree, pResult);
}
nsresult nsMsgSearchOfflineMail::ConstructExpressionTree(
nsIArray* termList, uint32_t termCount, uint32_t& aStartPosInList,
nsMsgSearchBoolExpression** aExpressionTree) {
nsTArray<RefPtr<nsIMsgSearchTerm>> const& termList, uint32_t termCount,
uint32_t& aStartPosInList, nsMsgSearchBoolExpression** aExpressionTree) {
nsMsgSearchBoolExpression* finalExpression = *aExpressionTree;
if (!finalExpression) finalExpression = new nsMsgSearchBoolExpression();
while (aStartPosInList < termCount) {
nsCOMPtr<nsIMsgSearchTerm> pTerm =
do_QueryElementAt(termList, aStartPosInList);
nsIMsgSearchTerm* pTerm = termList[aStartPosInList];
NS_ASSERTION(pTerm, "couldn't get term to match");
bool beginsGrouping;
@ -611,17 +611,16 @@ nsresult nsMsgSearchOfflineMail::ProcessSearchTerm(
}
nsresult nsMsgSearchOfflineMail::MatchTerms(
nsIMsgDBHdr* msgToMatch, nsIArray* termList, const char* defaultCharset,
nsIMsgSearchScopeTerm* scope, nsIMsgDatabase* db, const nsACString& headers,
bool Filtering, nsMsgSearchBoolExpression** aExpressionTree,
bool* pResult) {
nsIMsgDBHdr* msgToMatch, nsTArray<RefPtr<nsIMsgSearchTerm>> const& termList,
const char* defaultCharset, nsIMsgSearchScopeTerm* scope,
nsIMsgDatabase* db, const nsACString& headers, bool Filtering,
nsMsgSearchBoolExpression** aExpressionTree, bool* pResult) {
NS_ENSURE_ARG(aExpressionTree);
nsresult err;
if (!*aExpressionTree) {
uint32_t initialPos = 0;
uint32_t count;
termList->GetLength(&count);
uint32_t count = termList.Length();
err = ConstructExpressionTree(termList, count, initialPos, aExpressionTree);
if (NS_FAILED(err)) return err;
}
@ -750,8 +749,9 @@ NS_IMETHODIMP nsMsgSearchOfflineMail::OnStopRunningUrl(nsIURI* url,
return NS_OK;
}
nsMsgSearchOfflineNews::nsMsgSearchOfflineNews(nsIMsgSearchScopeTerm* scope,
nsIArray* termList)
nsMsgSearchOfflineNews::nsMsgSearchOfflineNews(
nsIMsgSearchScopeTerm* scope,
nsTArray<RefPtr<nsIMsgSearchTerm>> const& termList)
: nsMsgSearchOfflineMail(scope, termList) {}
nsMsgSearchOfflineNews::~nsMsgSearchOfflineNews() {}

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

@ -23,7 +23,8 @@ class nsMsgSearchBoolExpression;
class nsMsgSearchOfflineMail : public nsMsgSearchAdapter,
public nsIUrlListener {
public:
nsMsgSearchOfflineMail(nsIMsgSearchScopeTerm*, nsIArray*);
nsMsgSearchOfflineMail(nsIMsgSearchScopeTerm*,
nsTArray<RefPtr<nsIMsgSearchTerm>> const&);
NS_DECL_ISUPPORTS_INHERITED
@ -35,15 +36,18 @@ class nsMsgSearchOfflineMail : public nsMsgSearchAdapter,
NS_IMETHOD AddResultElement(nsIMsgDBHdr*) override;
static nsresult MatchTermsForFilter(
nsIMsgDBHdr* msgToMatch, nsIArray* termList, const char* defaultCharset,
nsIMsgSearchScopeTerm* scope, nsIMsgDatabase* db,
const nsACString& headers, nsMsgSearchBoolExpression** aExpressionTree,
bool* pResult);
nsIMsgDBHdr* msgToMatch,
nsTArray<RefPtr<nsIMsgSearchTerm>> const& termList,
const char* defaultCharset, nsIMsgSearchScopeTerm* scope,
nsIMsgDatabase* db, const nsACString& headers,
nsMsgSearchBoolExpression** aExpressionTree, bool* pResult);
static nsresult MatchTermsForSearch(
nsIMsgDBHdr* msgTomatch, nsIArray* termList, const char* defaultCharset,
nsIMsgSearchScopeTerm* scope, nsIMsgDatabase* db,
nsMsgSearchBoolExpression** aExpressionTree, bool* pResult);
nsIMsgDBHdr* msgTomatch,
nsTArray<RefPtr<nsIMsgSearchTerm>> const& termList,
const char* defaultCharset, nsIMsgSearchScopeTerm* scope,
nsIMsgDatabase* db, nsMsgSearchBoolExpression** aExpressionTree,
bool* pResult);
virtual nsresult OpenSummaryFile();
@ -57,7 +61,8 @@ class nsMsgSearchOfflineMail : public nsMsgSearchAdapter,
protected:
virtual ~nsMsgSearchOfflineMail();
static nsresult MatchTerms(nsIMsgDBHdr* msgToMatch, nsIArray* termList,
static nsresult MatchTerms(nsIMsgDBHdr* msgToMatch,
nsTArray<RefPtr<nsIMsgSearchTerm>> const& termList,
const char* defaultCharset,
nsIMsgSearchScopeTerm* scope, nsIMsgDatabase* db,
const nsACString& headers, bool ForFilters,
@ -65,8 +70,8 @@ class nsMsgSearchOfflineMail : public nsMsgSearchAdapter,
bool* pResult);
static nsresult ConstructExpressionTree(
nsIArray* termList, uint32_t termCount, uint32_t& aStartPosInList,
nsMsgSearchBoolExpression** aExpressionTree);
nsTArray<RefPtr<nsIMsgSearchTerm>> const& termList, uint32_t termCount,
uint32_t& aStartPosInList, nsMsgSearchBoolExpression** aExpressionTree);
nsCOMPtr<nsIMsgDatabase> m_db;
nsCOMPtr<nsISimpleEnumerator> m_listContext;
@ -75,7 +80,8 @@ class nsMsgSearchOfflineMail : public nsMsgSearchAdapter,
class nsMsgSearchOfflineNews : public nsMsgSearchOfflineMail {
public:
nsMsgSearchOfflineNews(nsIMsgSearchScopeTerm*, nsIArray*);
nsMsgSearchOfflineNews(nsIMsgSearchScopeTerm*,
nsTArray<RefPtr<nsIMsgSearchTerm>> const&);
virtual ~nsMsgSearchOfflineNews();
NS_IMETHOD ValidateTerms() override;

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

@ -24,8 +24,6 @@
#include "nsServiceManagerUtils.h"
#include "nsMemory.h"
#include "nsMsgMessageFlags.h"
#include "nsIArray.h"
#include "nsArrayUtils.h"
#include "mozilla/Attributes.h"
// This stuff lives in the base class because the IMAP search syntax
@ -80,11 +78,10 @@ NS_IMETHODIMP nsMsgSearchAdapter::OpenResultElement(nsMsgResultElement*) {
NS_IMPL_ISUPPORTS(nsMsgSearchAdapter, nsIMsgSearchAdapter)
nsMsgSearchAdapter::nsMsgSearchAdapter(nsIMsgSearchScopeTerm* scope,
nsIArray* searchTerms)
: m_searchTerms(searchTerms) {
m_scope = scope;
}
nsMsgSearchAdapter::nsMsgSearchAdapter(
nsIMsgSearchScopeTerm* scope,
nsTArray<RefPtr<nsIMsgSearchTerm>> const& searchTerms)
: m_scope(scope), m_searchTerms(searchTerms.Clone()) {}
nsMsgSearchAdapter::~nsMsgSearchAdapter() {}
@ -571,11 +568,9 @@ nsresult nsMsgSearchAdapter::EncodeImapValue(char* encoding, const char* value,
return NS_OK;
}
nsresult nsMsgSearchAdapter::EncodeImap(char** ppOutEncoding,
nsIArray* searchTerms,
const char16_t* srcCharset,
const char16_t* destCharset,
bool reallyDredd) {
nsresult nsMsgSearchAdapter::EncodeImap(
char** ppOutEncoding, nsTArray<RefPtr<nsIMsgSearchTerm>> const& searchTerms,
const char16_t* srcCharset, const char16_t* destCharset, bool reallyDredd) {
// i've left the old code (before using CBoolExpression for debugging purposes
// to make sure that the new code generates the same encoding string as the
// old code.....
@ -583,26 +578,23 @@ nsresult nsMsgSearchAdapter::EncodeImap(char** ppOutEncoding,
nsresult err = NS_OK;
*ppOutEncoding = nullptr;
uint32_t termCount;
searchTerms->GetLength(&termCount);
uint32_t i = 0;
// create our expression
nsMsgSearchBoolExpression* expression = new nsMsgSearchBoolExpression();
if (!expression) return NS_ERROR_OUT_OF_MEMORY;
for (i = 0; i < termCount && NS_SUCCEEDED(err); i++) {
char* termEncoding;
for (nsIMsgSearchTerm* pTerm : searchTerms) {
bool matchAll;
nsCOMPtr<nsIMsgSearchTerm> pTerm = do_QueryElementAt(searchTerms, i);
pTerm->GetMatchAll(&matchAll);
if (matchAll) continue;
char* termEncoding;
err = EncodeImapTerm(pTerm, reallyDredd, srcCharset, destCharset,
&termEncoding);
if (NS_SUCCEEDED(err) && nullptr != termEncoding) {
expression = nsMsgSearchBoolExpression::AddSearchTerm(expression, pTerm,
termEncoding);
delete[] termEncoding;
} else {
break;
}
}

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

@ -13,7 +13,8 @@
class nsMsgSearchOnlineMail : public nsMsgSearchAdapter {
public:
nsMsgSearchOnlineMail(nsMsgSearchScopeTerm* scope, nsIArray* termList);
nsMsgSearchOnlineMail(nsMsgSearchScopeTerm* scope,
nsTArray<RefPtr<nsIMsgSearchTerm>> const& termList);
virtual ~nsMsgSearchOnlineMail();
NS_IMETHOD ValidateTerms() override;
@ -21,7 +22,8 @@ class nsMsgSearchOnlineMail : public nsMsgSearchAdapter {
NS_IMETHOD GetEncoding(char** result) override;
NS_IMETHOD AddResultElement(nsIMsgDBHdr*) override;
static nsresult Encode(nsCString& ppEncoding, nsIArray* searchTerms,
static nsresult Encode(nsCString& ppEncoding,
nsTArray<RefPtr<nsIMsgSearchTerm>> const& searchTerms,
const char16_t* destCharset,
nsIMsgSearchScopeTerm* scope);

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

@ -15,7 +15,6 @@
#include "nsIMsgDatabase.h"
#include "nsMemory.h"
#include <ctype.h>
#include "nsIArray.h"
#include "nsArrayUtils.h"
// Implementation of search for IMAP mail folders
@ -30,8 +29,9 @@ const char* nsMsgSearchNews::m_kNntpFrom = "FROM ";
const char* nsMsgSearchNews::m_kNntpSubject = "SUBJECT ";
const char* nsMsgSearchNews::m_kTermSeparator = "/";
nsMsgSearchNews::nsMsgSearchNews(nsMsgSearchScopeTerm* scope,
nsIArray* termList)
nsMsgSearchNews::nsMsgSearchNews(
nsMsgSearchScopeTerm* scope,
nsTArray<RefPtr<nsIMsgSearchTerm>> const& termList)
: nsMsgSearchAdapter(scope, termList) {
m_searchType = ST_UNINITIALIZED;
}
@ -189,16 +189,14 @@ nsresult nsMsgSearchNews::Encode(nsCString* outEncoding) {
nsresult err = NS_OK;
uint32_t numTerms;
uint32_t numTerms = m_searchTerms.Length();
m_searchTerms->GetLength(&numTerms);
char** intermediateEncodings = new char*[numTerms];
if (intermediateEncodings) {
// Build an XPAT command for each term
int encodingLength = 0;
uint32_t i;
for (i = 0; i < numTerms; i++) {
nsCOMPtr<nsIMsgSearchTerm> pTerm = do_QueryElementAt(m_searchTerms, i);
for (uint32_t i = 0; i < numTerms; i++) {
nsIMsgSearchTerm* pTerm = m_searchTerms[i];
// set boolean OR term if any of the search terms are an OR...this only
// works if we are using homogeneous boolean operators.
bool isBooleanOpAnd;
@ -216,9 +214,7 @@ nsresult nsMsgSearchNews::Encode(nsCString* outEncoding) {
if (encoding) {
PL_strcpy(encoding, "?search");
m_searchTerms->GetLength(&numTerms);
for (i = 0; i < numTerms; i++) {
for (uint32_t i = 0; i < numTerms; i++) {
if (intermediateEncodings[i]) {
PL_strcat(encoding, m_kTermSeparator);
PL_strcat(encoding, intermediateEncodings[i]);
@ -292,7 +288,7 @@ void nsMsgSearchNews::CollateHits() {
// in the results of each XPAT command. So if we fire 3 XPAT commands (one
// per search term), the article number must appear 3 times. If it appears
// fewer than 3 times, it matched some search terms, but not all.
m_searchTerms->GetLength(&termCount);
termCount = m_searchTerms.Length();
}
uint32_t candidateCount = 0;
uint32_t candidate = m_candidateHits[0];

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

@ -20,7 +20,8 @@ typedef enum search_type {
class nsMsgSearchNews : public nsMsgSearchAdapter {
public:
nsMsgSearchNews(nsMsgSearchScopeTerm* scope, nsIArray* termList);
nsMsgSearchNews(nsMsgSearchScopeTerm* scope,
nsTArray<RefPtr<nsIMsgSearchTerm>> const& termList);
virtual ~nsMsgSearchNews();
NS_IMETHOD ValidateTerms() override;

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

@ -31,9 +31,6 @@ nsMsgSearchSession::nsMsgSearchSession() {
m_handlingError = false;
m_expressionTree = nullptr;
m_searchPaused = false;
m_termList = nsArray::Create();
NS_ASSERTION(m_termList,
"Failed to allocate a nsIMutableArray for m_termList");
}
nsMsgSearchSession::~nsMsgSearchSession() {
@ -58,7 +55,7 @@ nsMsgSearchSession::AddSearchTerm(nsMsgSearchAttribValue attrib,
new nsMsgSearchTerm(attrib, op, value, boolOp, customString);
NS_ENSURE_TRUE(pTerm, NS_ERROR_OUT_OF_MEMORY);
m_termList->AppendElement(pTerm);
m_termList.AppendElement(pTerm);
// force the expression tree to rebuild whenever we change the terms
delete m_expressionTree;
m_expressionTree = nullptr;
@ -68,22 +65,22 @@ nsMsgSearchSession::AddSearchTerm(nsMsgSearchAttribValue attrib,
NS_IMETHODIMP
nsMsgSearchSession::AppendTerm(nsIMsgSearchTerm* aTerm) {
NS_ENSURE_ARG_POINTER(aTerm);
NS_ENSURE_TRUE(m_termList, NS_ERROR_NOT_INITIALIZED);
delete m_expressionTree;
m_expressionTree = nullptr;
return m_termList->AppendElement(aTerm);
}
NS_IMETHODIMP
nsMsgSearchSession::GetSearchTerms(nsIMutableArray** aResult) {
NS_ENSURE_ARG_POINTER(aResult);
NS_ADDREF(*aResult = m_termList);
m_termList.AppendElement(aTerm);
return NS_OK;
}
NS_IMETHODIMP
nsMsgSearchSession::SetSearchTerms(nsIMutableArray* aSearchTerms) {
m_termList = aSearchTerms;
nsMsgSearchSession::GetSearchTerms(nsTArray<RefPtr<nsIMsgSearchTerm>>& terms) {
terms = m_termList.Clone();
return NS_OK;
}
NS_IMETHODIMP
nsMsgSearchSession::SetSearchTerms(
nsTArray<RefPtr<nsIMsgSearchTerm>> const& terms) {
m_termList = terms.Clone();
return NS_OK;
}
@ -123,7 +120,8 @@ NS_IMETHODIMP nsMsgSearchSession::UnregisterListener(
NS_IMETHODIMP nsMsgSearchSession::GetNumSearchTerms(uint32_t* aNumSearchTerms) {
NS_ENSURE_ARG(aNumSearchTerms);
return m_termList->Count(aNumSearchTerms);
*aNumSearchTerms = m_termList.Length();
return NS_OK;
}
NS_IMETHODIMP
@ -316,8 +314,7 @@ nsresult nsMsgSearchSession::Initialize() {
nsMsgSearchScopeTerm* scopeTerm = nullptr;
nsresult rv = NS_OK;
uint32_t numTerms;
m_termList->Count(&numTerms);
uint32_t numTerms = m_termList.Length();
// Ensure that the FE has added scopes and terms to this search
NS_ASSERTION(numTerms > 0, "no terms to search!");
if (numTerms == 0) return NS_MSG_ERROR_NO_SEARCH_VALUES;
@ -484,7 +481,7 @@ void nsMsgSearchSession::DestroyScopeList() {
m_scopeList.Clear();
}
void nsMsgSearchSession::DestroyTermList() { m_termList->Clear(); }
void nsMsgSearchSession::DestroyTermList() { m_termList.Clear(); }
nsMsgSearchScopeTerm* nsMsgSearchSession::GetRunningScope() {
return m_scopeList.SafeElementAt(m_idxRunningScope, nullptr);

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

@ -49,7 +49,7 @@ class nsMsgSearchSession : public nsIMsgSearchSession,
void ReleaseFolderDBRef();
nsTArray<RefPtr<nsMsgSearchScopeTerm>> m_scopeList;
nsCOMPtr<nsIMutableArray> m_termList;
nsTArray<RefPtr<nsIMsgSearchTerm>> m_termList;
nsTArray<nsCOMPtr<nsIMsgSearchNotify>> m_listenerList;
nsTArray<int32_t> m_listenerFlagList;

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

@ -1690,7 +1690,8 @@ nsresult nsMsgSearchScopeTerm::TimeSlice(bool* aDone) {
return m_adapter->Search(aDone);
}
nsresult nsMsgSearchScopeTerm::InitializeAdapter(nsIArray* termList) {
nsresult nsMsgSearchScopeTerm::InitializeAdapter(
nsTArray<RefPtr<nsIMsgSearchTerm>> const& termList) {
if (m_adapter) return NS_OK;
nsresult rv = NS_OK;

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

@ -10,7 +10,6 @@ var searchSessionContractID = "@mozilla.org/messenger/searchSession;1";
var gSearchSession;
var nsMsgSearchScope = Ci.nsMsgSearchScope;
var nsIMsgSearchTerm = Ci.nsIMsgSearchTerm;
var nsMsgSearchOp = Ci.nsMsgSearchOp;
var nsMsgSearchAttrib = Ci.nsMsgSearchAttrib;
var nsIAbDirectory = Ci.nsIAbDirectory;
@ -161,12 +160,12 @@ function onSearch()
var currentAbURI = document.getElementById('abPopup').getAttribute('value');
gSearchSession.addDirectoryScopeTerm(GetScopeForDirectoryURI(currentAbURI));
saveSearchTerms(gSearchSession.searchTerms, gSearchSession);
gSearchSession.searchTerms = saveSearchTerms(gSearchSession.searchTerms, gSearchSession);
var searchUri = currentAbURI + "?(";
for (let i = 0; i < gSearchSession.searchTerms.length; i++) {
let searchTerm = gSearchSession.searchTerms.queryElementAt(i, nsIMsgSearchTerm);
let searchTerm = gSearchSession.searchTerms[i];
// get the "and" / "or" value from the first term
if (i == 0) {

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

@ -399,7 +399,7 @@ function onSearch()
AddSubFolders(gMsgFolderSelected);
}
// reflect the search widgets back into the search session
saveSearchTerms(gSearchSession.searchTerms, gSearchSession);
gSearchSession.searchTerms = saveSearchTerms(gSearchSession.searchTerms, gSearchSession);
try
{

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

@ -834,7 +834,7 @@ function getSearchTermString(searchTerms)
var count = searchTerms.length;
for (searchIndex = 0; searchIndex < count; )
{
var term = searchTerms.queryElementAt(searchIndex++, Ci.nsIMsgSearchTerm);
var term = searchTerms[searchIndex++];
if (condition.length > 1)
condition += ' ';
@ -926,8 +926,7 @@ function setupXFVirtualFolderSearch(folderUrisToSearch, searchTerms, searchOnlin
gSearchSession.addScopeTerm(!searchOnline ? nsMsgSearchScope.offlineMail : GetScopeForFolder(realFolder), realFolder);
}
const nsIMsgSearchTerm = Ci.nsIMsgSearchTerm;
for (let term of fixIterator(searchTerms, nsIMsgSearchTerm)) {
for (let term of searchTerms) {
gSearchSession.appendTerm(term);
}
}
@ -952,7 +951,7 @@ function CreateGroupedSearchTerms(searchTermsArray)
var numEntries = searchTermsArray.length;
for (let i = 0; i < numEntries; i++) {
let searchTerm = searchTermsArray.queryElementAt(i, Ci.nsIMsgSearchTerm);
let searchTerm = searchTermsArray[i];
// clone the term, since we might be modifying it
var searchTermForQS = searchSession.createTerm();

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

@ -53,7 +53,7 @@ function onOK()
var newMailView = null;
if (gMailView)
{
saveSearchTerms(gMailView.searchTerms, gMailView);
gMailView.searchTerms = saveSearchTerms(gMailView.searchTerms, gMailView);
// if the name of the view has been changed...
if (gMailView.prettyName != dialog.nameField.value)
gMailView.mailViewName = dialog.nameField.value;
@ -63,7 +63,7 @@ function onOK()
// otherwise, create a new mail view
newMailView = mailViewList.createMailView();
saveSearchTerms(newMailView.searchTerms, newMailView);
newMailView.searchTerms = saveSearchTerms(newMailView.searchTerms, newMailView);
newMailView.mailViewName = dialog.nameField.value;
// now add the mail view to our mail view list
mailViewList.addMailView(newMailView);

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

@ -283,9 +283,8 @@ function AddVirtualFolderTerms(searchTermsArray)
var virtualFolderSearchTerms = (gVirtualFolderTerms || gXFVirtualFolderTerms);
if (virtualFolderSearchTerms)
{
for (let i = 0; i < termsArray.length; i++)
for (let searchTerm of virtualFolderSearchTerms)
{
let searchTerm = virtualFolderSearchTerms.queryElementAt(i, Ci.nsIMsgSearchTerm);
searchTermsArray.appendElement(searchTerm);
}
}

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

@ -321,7 +321,7 @@ function createSearchTermsWithList(aTermsArray)
}
// Add each item in aTermsArray to the search session.
for (let term of fixIterator(aTermsArray, Ci.nsIMsgSearchTerm)) {
for (let term of aTermsArray) {
gSearchSession.appendTerm(term);
}
}
@ -376,7 +376,7 @@ function createSearchTerms()
var defaultSearchTerms = (gDefaultSearchViewTerms || gVirtualFolderTerms || gXFVirtualFolderTerms);
if (defaultSearchTerms)
{
for (let searchTerm of fixIterator(defaultSearchTerms, Ci.nsIMsgSearchTerm))
for (let searchTerm of defaultSearchTerms)
{
searchTermsArray.appendElement(searchTerm);
}