diff options
author | Matt A. Tobin <email@mattatobin.com> | 2019-11-03 00:17:46 -0400 |
---|---|---|
committer | Matt A. Tobin <email@mattatobin.com> | 2019-11-03 00:17:46 -0400 |
commit | 302bf1b523012e11b60425d6eee1221ebc2724eb (patch) | |
tree | b191a895f8716efcbe42f454f37597a545a6f421 /mailnews/extensions/mailviews | |
parent | 21b3f6247403c06f85e1f45d219f87549862198f (diff) | |
download | UXP-302bf1b523012e11b60425d6eee1221ebc2724eb.tar UXP-302bf1b523012e11b60425d6eee1221ebc2724eb.tar.gz UXP-302bf1b523012e11b60425d6eee1221ebc2724eb.tar.lz UXP-302bf1b523012e11b60425d6eee1221ebc2724eb.tar.xz UXP-302bf1b523012e11b60425d6eee1221ebc2724eb.zip |
Issue #1258 - Part 1: Import mailnews, ldap, and mork from comm-esr52.9.1
Diffstat (limited to 'mailnews/extensions/mailviews')
-rw-r--r-- | mailnews/extensions/mailviews/content/mailViews.dat | 22 | ||||
-rw-r--r-- | mailnews/extensions/mailviews/content/moz.build | 8 | ||||
-rw-r--r-- | mailnews/extensions/mailviews/public/moz.build | 12 | ||||
-rw-r--r-- | mailnews/extensions/mailviews/public/nsIMsgMailView.idl | 35 | ||||
-rw-r--r-- | mailnews/extensions/mailviews/public/nsIMsgMailViewList.idl | 28 | ||||
-rw-r--r-- | mailnews/extensions/mailviews/src/moz.build | 11 | ||||
-rw-r--r-- | mailnews/extensions/mailviews/src/nsMsgMailViewList.cpp | 312 | ||||
-rw-r--r-- | mailnews/extensions/mailviews/src/nsMsgMailViewList.h | 61 | ||||
-rw-r--r-- | mailnews/extensions/mailviews/src/nsMsgMailViewsCID.h | 17 |
9 files changed, 506 insertions, 0 deletions
diff --git a/mailnews/extensions/mailviews/content/mailViews.dat b/mailnews/extensions/mailviews/content/mailViews.dat new file mode 100644 index 000000000..8565d0061 --- /dev/null +++ b/mailnews/extensions/mailviews/content/mailViews.dat @@ -0,0 +1,22 @@ +version="8" +logging="no" +name="People I Know" +enabled="yes" +type="1" +condition="AND (from,is in ab,moz-abmdbdirectory://abook.mab)" +name="Recent Mail" +enabled="yes" +type="1" +condition="AND (age in days,is less than,1)" +name="Last 5 Days" +enabled="yes" +type="1" +condition="AND (age in days,is less than,5)" +name="Not Junk" +enabled="yes" +type="1" +condition="AND (junk status,isn't,2)" +name="Has Attachments" +enabled="yes" +type="1" +condition="AND (has attachment status,is,true)" diff --git a/mailnews/extensions/mailviews/content/moz.build b/mailnews/extensions/mailviews/content/moz.build new file mode 100644 index 000000000..f5564e55b --- /dev/null +++ b/mailnews/extensions/mailviews/content/moz.build @@ -0,0 +1,8 @@ +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +FINAL_TARGET_FILES.defaults.messenger += [ + 'mailViews.dat', +] diff --git a/mailnews/extensions/mailviews/public/moz.build b/mailnews/extensions/mailviews/public/moz.build new file mode 100644 index 000000000..4d8dd8287 --- /dev/null +++ b/mailnews/extensions/mailviews/public/moz.build @@ -0,0 +1,12 @@ +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +XPIDL_SOURCES += [ + 'nsIMsgMailView.idl', + 'nsIMsgMailViewList.idl', +] + +XPIDL_MODULE = 'mailview' + diff --git a/mailnews/extensions/mailviews/public/nsIMsgMailView.idl b/mailnews/extensions/mailviews/public/nsIMsgMailView.idl new file mode 100644 index 000000000..54f22e76f --- /dev/null +++ b/mailnews/extensions/mailviews/public/nsIMsgMailView.idl @@ -0,0 +1,35 @@ +/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +#include "nsISupports.idl" +// Disable deprecation warnings generated by nsISupportsArray and associated +// classes. +%{C++ +#if defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#elif defined(_MSC_VER) +#pragma warning (disable : 4996) +#endif +%} +interface nsISupportsArray; + +interface nsIMsgSearchTerm; + +[scriptable, uuid(28AC84DF-CBE5-430d-A5C0-4FA63B5424DF)] +interface nsIMsgMailView : nsISupports { + attribute wstring mailViewName; + readonly attribute wstring prettyName; // localized pretty name + + // the array of search terms + attribute nsISupportsArray 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 + // and nsIMsgSearchSession have the same two methods....we should probably make an interface around them. + void appendTerm(in nsIMsgSearchTerm term); + nsIMsgSearchTerm createTerm(); + +}; diff --git a/mailnews/extensions/mailviews/public/nsIMsgMailViewList.idl b/mailnews/extensions/mailviews/public/nsIMsgMailViewList.idl new file mode 100644 index 000000000..e0c846dae --- /dev/null +++ b/mailnews/extensions/mailviews/public/nsIMsgMailViewList.idl @@ -0,0 +1,28 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsISupports.idl" +#include "nsIMsgMailView.idl" + +/////////////////////////////////////////////////////////////////////////////// +// A mail view list is a list of mail views a particular implementor provides +/////////////////////////////////////////////////////////////////////////////// + +typedef long nsMsgMailViewListFileAttribValue; + +[scriptable, uuid(6DD798D7-9528-49e6-9447-3AAF14D2D36F)] +interface nsIMsgMailViewList : nsISupports { + + readonly attribute unsigned long mailViewCount; + + nsIMsgMailView getMailViewAt(in unsigned long mailViewIndex); + + void addMailView(in nsIMsgMailView mailView); + void removeMailView(in nsIMsgMailView mailView); + + nsIMsgMailView createMailView(); + + void save(); +}; diff --git a/mailnews/extensions/mailviews/src/moz.build b/mailnews/extensions/mailviews/src/moz.build new file mode 100644 index 000000000..ee128fb8a --- /dev/null +++ b/mailnews/extensions/mailviews/src/moz.build @@ -0,0 +1,11 @@ +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +SOURCES += [ + 'nsMsgMailViewList.cpp', +] + +FINAL_LIBRARY = 'mail' + diff --git a/mailnews/extensions/mailviews/src/nsMsgMailViewList.cpp b/mailnews/extensions/mailviews/src/nsMsgMailViewList.cpp new file mode 100644 index 000000000..8e5e04a3f --- /dev/null +++ b/mailnews/extensions/mailviews/src/nsMsgMailViewList.cpp @@ -0,0 +1,312 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsMsgMailViewList.h" +// Disable deprecation warnings generated by nsISupportsArray and associated +// classes. +#if defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#elif defined(_MSC_VER) +#pragma warning (disable : 4996) +#endif +#include "nsISupportsArray.h" +#include "nsIFileChannel.h" +#include "nsIMsgFilterService.h" +#include "nsIMsgMailSession.h" +#include "nsIMsgSearchTerm.h" +#include "nsMsgBaseCID.h" +#include "nsAppDirectoryServiceDefs.h" +#include "nsDirectoryServiceUtils.h" +#include "nsIFile.h" +#include "nsComponentManagerUtils.h" +#include "mozilla/Services.h" +#include "nsIMsgFilter.h" + +#define kDefaultViewPeopleIKnow "People I Know" +#define kDefaultViewRecent "Recent Mail" +#define kDefaultViewFiveDays "Last 5 Days" +#define kDefaultViewNotJunk "Not Junk" +#define kDefaultViewHasAttachments "Has Attachments" + +nsMsgMailView::nsMsgMailView() +{ + mViewSearchTerms = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID); +} + +NS_IMPL_ADDREF(nsMsgMailView) +NS_IMPL_RELEASE(nsMsgMailView) +NS_IMPL_QUERY_INTERFACE(nsMsgMailView, nsIMsgMailView) + +nsMsgMailView::~nsMsgMailView() +{ + if (mViewSearchTerms) + mViewSearchTerms->Clear(); +} + +NS_IMETHODIMP nsMsgMailView::GetMailViewName(char16_t ** aMailViewName) +{ + NS_ENSURE_ARG_POINTER(aMailViewName); + + *aMailViewName = ToNewUnicode(mName); + return NS_OK; +} + +NS_IMETHODIMP nsMsgMailView::SetMailViewName(const char16_t * aMailViewName) +{ + mName = aMailViewName; + return NS_OK; +} + +NS_IMETHODIMP nsMsgMailView::GetPrettyName(char16_t ** aMailViewName) +{ + NS_ENSURE_ARG_POINTER(aMailViewName); + + nsresult rv = NS_OK; + if (!mBundle) + { + nsCOMPtr<nsIStringBundleService> bundleService = + mozilla::services::GetStringBundleService(); + NS_ENSURE_TRUE(bundleService, NS_ERROR_UNEXPECTED); + bundleService->CreateBundle("chrome://messenger/locale/mailviews.properties", + getter_AddRefs(mBundle)); + } + + NS_ENSURE_TRUE(mBundle, NS_ERROR_FAILURE); + + // see if mName has an associated pretty name inside our string bundle and if so, use that as the pretty name + // otherwise just return mName + if (mName.EqualsLiteral(kDefaultViewPeopleIKnow)) + rv = mBundle->GetStringFromName(u"mailViewPeopleIKnow", aMailViewName); + else if (mName.EqualsLiteral(kDefaultViewRecent)) + rv = mBundle->GetStringFromName(u"mailViewRecentMail", aMailViewName); + else if (mName.EqualsLiteral(kDefaultViewFiveDays)) + rv = mBundle->GetStringFromName(u"mailViewLastFiveDays", aMailViewName); + else if (mName.EqualsLiteral(kDefaultViewNotJunk)) + rv = mBundle->GetStringFromName(u"mailViewNotJunk", aMailViewName); + else if (mName.EqualsLiteral(kDefaultViewHasAttachments)) + rv = mBundle->GetStringFromName(u"mailViewHasAttachments", aMailViewName); + else + *aMailViewName = ToNewUnicode(mName); + + return rv; +} + +NS_IMETHODIMP nsMsgMailView::GetSearchTerms(nsISupportsArray ** aSearchTerms) +{ + NS_ENSURE_ARG_POINTER(aSearchTerms); + NS_IF_ADDREF(*aSearchTerms = mViewSearchTerms); + return NS_OK; +} + +NS_IMETHODIMP nsMsgMailView::SetSearchTerms(nsISupportsArray * aSearchTerms) +{ + mViewSearchTerms = aSearchTerms; + return NS_OK; +} + +NS_IMETHODIMP nsMsgMailView::AppendTerm(nsIMsgSearchTerm * aTerm) +{ + NS_ENSURE_TRUE(aTerm, NS_ERROR_NULL_POINTER); + + return mViewSearchTerms->AppendElement(static_cast<nsISupports*>(aTerm)); +} + +NS_IMETHODIMP nsMsgMailView::CreateTerm(nsIMsgSearchTerm **aResult) +{ + NS_ENSURE_ARG_POINTER(aResult); + nsCOMPtr<nsIMsgSearchTerm> searchTerm = do_CreateInstance("@mozilla.org/messenger/searchTerm;1"); + NS_IF_ADDREF(*aResult = searchTerm); + return NS_OK; +} + +///////////////////////////////////////////////////////////////////////////// +// nsMsgMailViewList implementation +///////////////////////////////////////////////////////////////////////////// +nsMsgMailViewList::nsMsgMailViewList() +{ + LoadMailViews(); +} + +NS_IMPL_ADDREF(nsMsgMailViewList) +NS_IMPL_RELEASE(nsMsgMailViewList) +NS_IMPL_QUERY_INTERFACE(nsMsgMailViewList, nsIMsgMailViewList) + +nsMsgMailViewList::~nsMsgMailViewList() +{ + +} + +NS_IMETHODIMP nsMsgMailViewList::GetMailViewCount(uint32_t * aCount) +{ + NS_ENSURE_ARG_POINTER(aCount); + + *aCount = m_mailViews.Length(); + return NS_OK; +} + +NS_IMETHODIMP nsMsgMailViewList::GetMailViewAt(uint32_t aMailViewIndex, nsIMsgMailView ** aMailView) +{ + NS_ENSURE_ARG_POINTER(aMailView); + + uint32_t mailViewCount = m_mailViews.Length(); + + NS_ENSURE_ARG(mailViewCount > aMailViewIndex); + + NS_IF_ADDREF(*aMailView = m_mailViews[aMailViewIndex]); + return NS_OK; +} + +NS_IMETHODIMP nsMsgMailViewList::AddMailView(nsIMsgMailView * aMailView) +{ + NS_ENSURE_ARG_POINTER(aMailView); + + m_mailViews.AppendElement(aMailView); + return NS_OK; +} + +NS_IMETHODIMP nsMsgMailViewList::RemoveMailView(nsIMsgMailView * aMailView) +{ + NS_ENSURE_ARG_POINTER(aMailView); + + m_mailViews.RemoveElement(aMailView); + return NS_OK; +} + +NS_IMETHODIMP nsMsgMailViewList::CreateMailView(nsIMsgMailView ** aMailView) +{ + NS_ENSURE_ARG_POINTER(aMailView); + + nsMsgMailView * mailView = new nsMsgMailView; + NS_ENSURE_TRUE(mailView, NS_ERROR_OUT_OF_MEMORY); + + NS_IF_ADDREF(*aMailView = mailView); + return NS_OK; +} + +NS_IMETHODIMP nsMsgMailViewList::Save() +{ + // brute force...remove all the old filters in our filter list, then we'll re-add our current + // list + nsCOMPtr<nsIMsgFilter> msgFilter; + uint32_t numFilters = 0; + if (mFilterList) + mFilterList->GetFilterCount(&numFilters); + while (numFilters) + { + mFilterList->RemoveFilterAt(numFilters - 1); + numFilters--; + } + + // now convert our mail view list into a filter list and save it + ConvertMailViewListToFilterList(); + + // now save the filters to our file + return mFilterList ? mFilterList->SaveToDefaultFile() : NS_ERROR_FAILURE; +} + +nsresult nsMsgMailViewList::ConvertMailViewListToFilterList() +{ + uint32_t mailViewCount = m_mailViews.Length(); + nsCOMPtr<nsIMsgMailView> mailView; + nsCOMPtr<nsIMsgFilter> newMailFilter; + nsString mailViewName; + for (uint32_t index = 0; index < mailViewCount; index++) + { + GetMailViewAt(index, getter_AddRefs(mailView)); + if (!mailView) + continue; + mailView->GetMailViewName(getter_Copies(mailViewName)); + mFilterList->CreateFilter(mailViewName, getter_AddRefs(newMailFilter)); + if (!newMailFilter) + continue; + + nsCOMPtr<nsISupportsArray> searchTerms; + mailView->GetSearchTerms(getter_AddRefs(searchTerms)); + newMailFilter->SetSearchTerms(searchTerms); + mFilterList->InsertFilterAt(index, newMailFilter); + } + + return NS_OK; +} + +nsresult nsMsgMailViewList::LoadMailViews() +{ + nsCOMPtr<nsIFile> file; + nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(file)); + NS_ENSURE_SUCCESS(rv, rv); + + rv = file->AppendNative(nsDependentCString("mailViews.dat")); + + // if the file doesn't exist, we should try to get it from the defaults directory and copy it over + bool exists = false; + file->Exists(&exists); + if (!exists) + { + nsCOMPtr<nsIMsgMailSession> mailSession = do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr<nsIFile> defaultMessagesFile; + nsCOMPtr<nsIFile> profileDir; + rv = mailSession->GetDataFilesDir("messenger", getter_AddRefs(defaultMessagesFile)); + rv = defaultMessagesFile->AppendNative(nsDependentCString("mailViews.dat")); + + // get the profile directory + rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(profileDir)); + + // now copy the file over to the profile directory + defaultMessagesFile->CopyToNative(profileDir, EmptyCString()); + } + // this is kind of a hack but I think it will be an effective hack. The filter service already knows how to + // take a nsIFile and parse the contents into filters which are very similar to mail views. Intead of + // re-writing all of that dirty parsing code, let's just re-use it then convert the results into a data strcuture + // we wish to give to our consumers. + + nsCOMPtr<nsIMsgFilterService> filterService = do_GetService(NS_MSGFILTERSERVICE_CONTRACTID, &rv); + nsCOMPtr<nsIMsgFilterList> mfilterList; + + rv = filterService->OpenFilterList(file, nullptr, nullptr, getter_AddRefs(mFilterList)); + NS_ENSURE_SUCCESS(rv, rv); + + return ConvertFilterListToMailViews(); +} +/** + * Converts the filter list into our mail view objects, + * stripping out just the info we need. + */ +nsresult nsMsgMailViewList::ConvertFilterListToMailViews() +{ + nsresult rv = NS_OK; + m_mailViews.Clear(); + + // iterate over each filter in the list + uint32_t numFilters = 0; + mFilterList->GetFilterCount(&numFilters); + for (uint32_t index = 0; index < numFilters; index++) + { + nsCOMPtr<nsIMsgFilter> msgFilter; + rv = mFilterList->GetFilterAt(index, getter_AddRefs(msgFilter)); + if (NS_FAILED(rv) || !msgFilter) + continue; + + // create a new nsIMsgMailView for this item + nsCOMPtr<nsIMsgMailView> newMailView; + rv = CreateMailView(getter_AddRefs(newMailView)); + NS_ENSURE_SUCCESS(rv, rv); + + nsString filterName; + msgFilter->GetFilterName(filterName); + newMailView->SetMailViewName(filterName.get()); + + nsCOMPtr<nsISupportsArray> filterSearchTerms; + rv = msgFilter->GetSearchTerms(getter_AddRefs(filterSearchTerms)); + NS_ENSURE_SUCCESS(rv, rv); + rv = newMailView->SetSearchTerms(filterSearchTerms); + NS_ENSURE_SUCCESS(rv, rv); + + // now append this new mail view to our global list view + m_mailViews.AppendElement(newMailView); + } + + return rv; +} diff --git a/mailnews/extensions/mailviews/src/nsMsgMailViewList.h b/mailnews/extensions/mailviews/src/nsMsgMailViewList.h new file mode 100644 index 000000000..321803392 --- /dev/null +++ b/mailnews/extensions/mailviews/src/nsMsgMailViewList.h @@ -0,0 +1,61 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +#ifndef _nsMsgMailViewList_H_ +#define _nsMsgMailViewList_H_ + +#include "nscore.h" +#include "nsIMsgMailViewList.h" +#include "nsCOMPtr.h" +#include "nsCOMArray.h" +// Disable deprecation warnings generated by nsISupportsArray and associated +// classes. +#if defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#elif defined(_MSC_VER) +#pragma warning (disable : 4996) +#endif +#include "nsISupportsArray.h" +#include "nsIStringBundle.h" +#include "nsStringGlue.h" +#include "nsIMsgFilterList.h" + +// a mail View is just a name and an array of search terms +class nsMsgMailView : public nsIMsgMailView +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIMSGMAILVIEW + + nsMsgMailView(); + +protected: + virtual ~nsMsgMailView(); + nsString mName; + nsCOMPtr<nsIStringBundle> mBundle; + nsCOMPtr<nsISupportsArray> mViewSearchTerms; +}; + + +class nsMsgMailViewList : public nsIMsgMailViewList +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIMSGMAILVIEWLIST + + nsMsgMailViewList(); + +protected: + virtual ~nsMsgMailViewList(); + nsresult LoadMailViews(); // reads in user defined mail views from our default file + nsresult ConvertFilterListToMailViews(); + nsresult ConvertMailViewListToFilterList(); + + nsCOMArray<nsIMsgMailView> m_mailViews; + nsCOMPtr<nsIMsgFilterList> mFilterList; // our internal filter list representation +}; + +#endif diff --git a/mailnews/extensions/mailviews/src/nsMsgMailViewsCID.h b/mailnews/extensions/mailviews/src/nsMsgMailViewsCID.h new file mode 100644 index 000000000..9487e5f4c --- /dev/null +++ b/mailnews/extensions/mailviews/src/nsMsgMailViewsCID.h @@ -0,0 +1,17 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef nsMsgMailViewsCID_h__ +#define nsMsgMailViewsCID_h__ + +#define NS_MSGMAILVIEWLIST_CONTRACTID \ + "@mozilla.org/messenger/mailviewlist;1" + +#define NS_MSGMAILVIEWLIST_CID \ +{ /* A0258267-44FD-4886-A858-8192615178EC */ \ + 0xa0258267, 0x44fd, 0x4886, \ + { 0xa8, 0x58, 0x81, 0x92, 0x61, 0x51, 0x78, 0xec }} + +#endif /* nsMsgMailViewsCID_h__*/ |