From 5b64bf539efe22e0ab1f19801b0fe48dfe71c472 Mon Sep 17 00:00:00 2001 From: "naving%netscape.com" Date: Wed, 10 Oct 2001 19:27:06 +0000 Subject: [PATCH] 16902 r=sspitzer sr=bienvenu, Implement custom headers for mail filter and search. --- .../base/resources/content/mailWidgets.xml | 66 ++++++-- .../base/search/public/nsIMsgFilterList.idl | 3 +- .../base/search/public/nsMsgBodyHandler.h | 7 +- .../base/search/public/nsMsgSearchAdapter.h | 1 + .../base/search/public/nsMsgSearchCore.idl | 6 +- .../search/resources/content/CustomHeaders.js | 155 ++++++++++++++++++ .../resources/content/CustomHeaders.xul | 75 +++++++++ .../search/resources/content/FilterEditor.js | 5 + .../search/resources/content/SearchDialog.js | 5 +- .../resources/content/searchTermOverlay.js | 11 ++ .../resources/locale/en-US/CustomHeaders.dtd | 4 + .../resources/locale/en-US/FilterEditor.dtd | 1 + .../locale/en-US/search-attributes.properties | 2 +- mailnews/base/search/src/nsMsgBodyHandler.cpp | 12 +- mailnews/base/search/src/nsMsgFilter.cpp | 41 +++-- mailnews/base/search/src/nsMsgFilterList.cpp | 62 ++++++- mailnews/base/search/src/nsMsgFilterList.h | 2 +- .../base/search/src/nsMsgFilterService.cpp | 4 + mailnews/base/search/src/nsMsgImapSearch.cpp | 36 ++-- mailnews/base/search/src/nsMsgLocalSearch.cpp | 153 ++++++++--------- mailnews/base/search/src/nsMsgLocalSearch.h | 1 - .../base/search/src/nsMsgSearchAdapter.cpp | 97 ++++++++--- mailnews/base/search/src/nsMsgSearchTerm.cpp | 49 ++++-- .../imap/public/nsIImapMiscellaneousSink.h | 4 - mailnews/imap/public/nsIImapServerSink.idl | 2 + mailnews/imap/src/nsImapIncomingServer.cpp | 24 +++ mailnews/imap/src/nsImapMailFolder.cpp | 15 +- mailnews/imap/src/nsImapMailFolder.h | 4 - mailnews/imap/src/nsImapProtocol.cpp | 58 ++----- mailnews/imap/src/nsImapProtocol.h | 4 +- mailnews/imap/src/nsImapProxyEvent.cpp | 104 ------------ mailnews/imap/src/nsImapProxyEvent.h | 23 --- mailnews/jar.mn | 4 + 33 files changed, 662 insertions(+), 378 deletions(-) create mode 100644 mailnews/base/search/resources/content/CustomHeaders.js create mode 100644 mailnews/base/search/resources/content/CustomHeaders.xul create mode 100644 mailnews/base/search/resources/locale/en-US/CustomHeaders.dtd diff --git a/mailnews/base/resources/content/mailWidgets.xml b/mailnews/base/resources/content/mailWidgets.xml index 6c2455a99d03..63e4b04fd7fa 100644 --- a/mailnews/base/resources/content/mailWidgets.xml +++ b/mailnews/base/resources/content/mailWidgets.xml @@ -102,9 +102,28 @@ Components.interfaces.nsMsgSearchAttrib.OtherHeader && hdrs) + strings[i] = hdrsArray[j++]; + else strings[i] = this.stringBundle.GetStringFromID(ids[i]); + } return strings; ]]> @@ -150,6 +169,9 @@ ]]> + + + @@ -190,7 +226,6 @@ @@ -540,6 +580,8 @@ nsMsgSearchAttrib.OtherHeader && this.searchAttribute < nsMsgSearchAttrib.kNumMsgSearchAttributes) + searchTerm.arbitraryHeader = this.searchattribute.label; searchTerm.op = this.searchoperator.value; if (this.searchvalue.value) this.searchvalue.save(); diff --git a/mailnews/base/search/public/nsIMsgFilterList.idl b/mailnews/base/search/public/nsIMsgFilterList.idl index 1ba13577eee6..210680e392c0 100644 --- a/mailnews/base/search/public/nsIMsgFilterList.idl +++ b/mailnews/base/search/public/nsIMsgFilterList.idl @@ -68,7 +68,8 @@ interface nsIMsgFilterList : nsISupports { attribute nsIMsgFolder folder; readonly attribute short version; - + readonly attribute string arbitraryHeaders; + readonly attribute boolean shouldDownloadArbitraryHeaders; readonly attribute unsigned long filterCount; nsIMsgFilter getFilterAt(in unsigned long filterIndex); nsIMsgFilter getFilterNamed(in wstring filterName); diff --git a/mailnews/base/search/public/nsMsgBodyHandler.h b/mailnews/base/search/public/nsMsgBodyHandler.h index 3ffe36c8b9e4..371fa1ee8e8a 100644 --- a/mailnews/base/search/public/nsMsgBodyHandler.h +++ b/mailnews/base/search/public/nsMsgBodyHandler.h @@ -52,8 +52,8 @@ protected: void OpenLocalFolder(); // goes through the mail folder - PRInt32 GetNextLocalLine(char * buf, int bufSize); - + PRInt32 GetNextLocalLine(char * buf, int bufSize); + nsIMsgSearchScopeTerm *m_scope; nsCOMPtr m_fileSpec; // local file state @@ -70,9 +70,6 @@ protected: nsIMsgDBHdr * m_msgHdr; nsIMsgDatabase * m_db; - // News related methods & state - PRInt32 m_NewsArticleOffset; - // Transformations PRBool m_stripHeaders; // PR_TRUE if we're supposed to strip of message headers PRBool m_stripHtml; // PR_TRUE if we're supposed to strip off HTML tags diff --git a/mailnews/base/search/public/nsMsgSearchAdapter.h b/mailnews/base/search/public/nsMsgSearchAdapter.h index f19381ca2757..629008b85e6c 100644 --- a/mailnews/base/search/public/nsMsgSearchAdapter.h +++ b/mailnews/base/search/public/nsMsgSearchAdapter.h @@ -213,6 +213,7 @@ protected: nsresult InitNewsTable (); nsresult InitLocalNewsTable(); nsresult InitNewsExTable (nsINntpIncomingServer *host = nsnull); + nsresult InitOtherHeadersInTable(nsIMsgSearchValidityTable *table, const char *customHeaders); void EnableLdapAttribute (nsMsgSearchAttribValue, PRBool enabled = PR_TRUE); }; diff --git a/mailnews/base/search/public/nsMsgSearchCore.idl b/mailnews/base/search/public/nsMsgSearchCore.idl index 2824e6b1ddaf..04aa2528607f 100644 --- a/mailnews/base/search/public/nsMsgSearchCore.idl +++ b/mailnews/base/search/public/nsMsgSearchCore.idl @@ -123,9 +123,10 @@ interface nsMsgSearchAttrib { const long HomePhone = 46; const long Pager = 47; const long Cellular = 48; + //49 is for showing customize... in ui headers start from 50 onwards up until 99. + const long OtherHeader = 49; /* for mail and news. MUST ALWAYS BE LAST attribute since we can have an arbitrary # of these... */ - const long OtherHeader = 49; /* for mail and news. MUST ALWAYS BE LAST attribute since we can have an arbitrary # of these...*/ - const long kNumMsgSearchAttributes = 50; /* must be last attribute */ + const long kNumMsgSearchAttributes = 100; /* must be last attribute */ }; /* NB: If you add elements to this enum, add only to the end, since @@ -158,7 +159,6 @@ interface nsMsgSearchOp { const long IsLessThan = 14; const long NameCompletion = 15; /* Name Completion operator...as the name implies =) */ - const long kNumMsgSearchOperators = 16; /* must be last operator */ }; diff --git a/mailnews/base/search/resources/content/CustomHeaders.js b/mailnews/base/search/resources/content/CustomHeaders.js new file mode 100644 index 000000000000..34388b257731 --- /dev/null +++ b/mailnews/base/search/resources/content/CustomHeaders.js @@ -0,0 +1,155 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 Communicator client code, released + * March 31, 1998. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998-1999 Netscape Communications Corporation. All + * Rights Reserved. + * Original Contributor(s): Navin Gupta + */ + +var gPrefs; +var addButton; +var removeButton; +var gHeaderInputElement; +var gArrayHdrs; +var gHdrsList; +var gTree; +var gContainer; + +function onLoad() +{ + gPrefs = Components.classes["@mozilla.org/preferences;1"].getService(Components.interfaces.nsIPref); + var hdrs; + try + { + hdrs = gPrefs.GetCharPref("mailnews.customHeaders"); + } + catch(ex) + { + hdrs =null; + } + gHeaderInputElement = document.getElementById("headerInput"); + gHdrsList = document.getElementById("headerList"); + gTree = document.getElementById("headerTree"); + gArrayHdrs = new Array(); + addButton = document.getElementById("addButton"); + removeButton = document.getElementById("removeButton"); + + initializeDialog(hdrs); + + doSetOKCancel(onOk, null); + + updateButtons(); + moveToAlertPosition(); +} + +function initializeDialog(hdrs) +{ + if (hdrs) + { + gArrayHdrs = hdrs.split(": "); + initializeRows(); + } +} + +function initializeRows() +{ + for (var i = 0; i< gArrayHdrs.length; i++) + addRow(TrimString(gArrayHdrs[i])); +} + +function onOk() +{ + if (gArrayHdrs.length) + { + var hdrs = gArrayHdrs.join(": "); + gPrefs.SetCharPref("mailnews.customHeaders", hdrs); + } + window.close(); +} + +function onAddHeader() +{ + var newHdr = TrimString(gHeaderInputElement.value); + gHeaderInputElement.value = ""; + if (!newHdr) return; + if (!duplicateHdrExists(newHdr)) + { + gArrayHdrs[gArrayHdrs.length] = newHdr; + addRow(newHdr); + } +} + +function duplicateHdrExists(hdr) +{ + for (var i=0;i 0); + removeButton.disabled = !headerSelected; +} + +//Remove whitespace from both ends of a string +function TrimString(string) +{ + if (!string) return ""; + return string.replace(/(^\s+)|(\s+$)/g, '') +} diff --git a/mailnews/base/search/resources/content/CustomHeaders.xul b/mailnews/base/search/resources/content/CustomHeaders.xul new file mode 100644 index 000000000000..431dabdbac37 --- /dev/null +++ b/mailnews/base/search/resources/content/CustomHeaders.xul @@ -0,0 +1,75 @@ + + + + + + + + +