зеркало из https://github.com/mozilla/gecko-dev.git
Bug #162789 --> Add backend support for filtering and searching based on the sender in an address book.
r=navin sr=bienvenu
This commit is contained in:
Родитель
a8ec009e66
Коммит
5a079be131
|
@ -102,8 +102,8 @@ interface nsMsgSearchAttrib {
|
||||||
const nsMsgSearchAttribValue AdditionalEmail = 31;
|
const nsMsgSearchAttribValue AdditionalEmail = 31;
|
||||||
|
|
||||||
|
|
||||||
// 32 - 48, reserved for ab / LDAP;
|
// 32 - 46, reserved for ab / LDAP;
|
||||||
|
const nsMsgSearchAttribValue SenderInAddressBook = 47;
|
||||||
const nsMsgSearchAttribValue Label = 48; /* mail only...can search by label */
|
const nsMsgSearchAttribValue Label = 48; /* mail only...can search by label */
|
||||||
//49 is for showing customize... in ui headers start from 50 onwards up until 99.
|
//49 is for showing customize... in ui headers start from 50 onwards up until 99.
|
||||||
const nsMsgSearchAttribValue OtherHeader = 49; /* for mail and news. MUST ALWAYS BE LAST attribute since we can have an arbitrary # of these... */
|
const nsMsgSearchAttribValue OtherHeader = 49; /* for mail and news. MUST ALWAYS BE LAST attribute since we can have an arbitrary # of these... */
|
||||||
|
@ -140,7 +140,9 @@ interface nsMsgSearchOp {
|
||||||
const nsMsgSearchOpValue IsLessThan = 14;
|
const nsMsgSearchOpValue IsLessThan = 14;
|
||||||
|
|
||||||
const nsMsgSearchOpValue NameCompletion = 15; /* Name Completion operator...as the name implies =) */
|
const nsMsgSearchOpValue NameCompletion = 15; /* Name Completion operator...as the name implies =) */
|
||||||
const nsMsgSearchOpValue kNumMsgSearchOperators = 16; /* must be last operator */
|
const nsMsgSearchOpValue IsInAB = 16;
|
||||||
|
const nsMsgSearchOpValue IsntInAB = 17;
|
||||||
|
const nsMsgSearchOpValue kNumMsgSearchOperators = 18; /* must be last operator */
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef long nsMsgSearchWidgetValue;
|
typedef long nsMsgSearchWidgetValue;
|
||||||
|
@ -206,7 +208,7 @@ typedef struct nsMsgSearchValue
|
||||||
(!(_a == nsMsgSearchAttrib::Priority || _a == nsMsgSearchAttrib::Date || \
|
(!(_a == nsMsgSearchAttrib::Priority || _a == nsMsgSearchAttrib::Date || \
|
||||||
_a == nsMsgSearchAttrib::MsgStatus || _a == nsMsgSearchAttrib::MessageKey || \
|
_a == nsMsgSearchAttrib::MsgStatus || _a == nsMsgSearchAttrib::MessageKey || \
|
||||||
_a == nsMsgSearchAttrib::Size || _a == nsMsgSearchAttrib::AgeInDays || \
|
_a == nsMsgSearchAttrib::Size || _a == nsMsgSearchAttrib::AgeInDays || \
|
||||||
_a == nsMsgSearchAttrib::FolderInfo || _a == nsMsgSearchAttrib::Location))
|
_a == nsMsgSearchAttrib::FolderInfo || _a == nsMsgSearchAttrib::Location) || _a == nsMsgSearchAttrib::Label)
|
||||||
%}
|
%}
|
||||||
|
|
||||||
[ptr] native nsSearchMenuItem(nsSearchMenuItem);
|
[ptr] native nsSearchMenuItem(nsSearchMenuItem);
|
||||||
|
|
|
@ -45,6 +45,9 @@
|
||||||
#include "nsIMsgSearchScopeTerm.h"
|
#include "nsIMsgSearchScopeTerm.h"
|
||||||
#include "nsIMsgSearchTerm.h"
|
#include "nsIMsgSearchTerm.h"
|
||||||
|
|
||||||
|
// needed to search for addresses in address books
|
||||||
|
#include "nsIAbMDBDirectory.h"
|
||||||
|
|
||||||
#define EMPTY_MESSAGE_LINE(buf) (buf[0] == nsCRT::CR || buf[0] == nsCRT::LF || buf[0] == '\0')
|
#define EMPTY_MESSAGE_LINE(buf) (buf[0] == nsCRT::CR || buf[0] == nsCRT::LF || buf[0] == '\0')
|
||||||
|
|
||||||
class nsMsgSearchTerm : public nsIMsgSearchTerm
|
class nsMsgSearchTerm : public nsIMsgSearchTerm
|
||||||
|
@ -102,6 +105,7 @@ public:
|
||||||
nsMsgSearchBooleanOperator m_booleanOp; // boolean operator to be applied to this search term and the search term which precedes it.
|
nsMsgSearchBooleanOperator m_booleanOp; // boolean operator to be applied to this search term and the search term which precedes it.
|
||||||
nsCString m_arbitraryHeader; // user specified string for the name of the arbitrary header to be used in the search
|
nsCString m_arbitraryHeader; // user specified string for the name of the arbitrary header to be used in the search
|
||||||
// only has a value when m_attribute = attribOtherHeader!!!!
|
// only has a value when m_attribute = attribOtherHeader!!!!
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
nsresult MatchString (const char *stringToMatch, const char *charset,
|
nsresult MatchString (const char *stringToMatch, const char *charset,
|
||||||
PRBool *pResult);
|
PRBool *pResult);
|
||||||
|
@ -110,7 +114,10 @@ protected:
|
||||||
nsMsgSearchOpValue ParseOperator(char *inStream);
|
nsMsgSearchOpValue ParseOperator(char *inStream);
|
||||||
nsresult ParseValue(char *inStream);
|
nsresult ParseValue(char *inStream);
|
||||||
nsresult InitHeaderAddressParser();
|
nsresult InitHeaderAddressParser();
|
||||||
|
nsresult InitializeAddressBook();
|
||||||
|
nsresult MatchInAddressBook(const char * aAddress, PRBool *pResult);
|
||||||
|
// fields used by search in address book
|
||||||
|
nsCOMPtr <nsIAbMDBDirectory> mDirectory;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
44=reserved for AB
|
44=reserved for AB
|
||||||
45=reserved for AB
|
45=reserved for AB
|
||||||
46=reserved for AB
|
46=reserved for AB
|
||||||
47=reserved for AB
|
47=Sender
|
||||||
48=reserved for AB
|
48=Label
|
||||||
# don't use above 49
|
# don't use above 49
|
||||||
49=Customize...
|
49=Customize...
|
||||||
|
|
|
@ -20,4 +20,6 @@
|
||||||
14=is less than
|
14=is less than
|
||||||
|
|
||||||
15=NameCompletion
|
15=NameCompletion
|
||||||
|
16=is in my address book
|
||||||
|
17=isn't in my address book
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@ REQUIRES = xpcom \
|
||||||
msgnews \
|
msgnews \
|
||||||
txmgr \
|
txmgr \
|
||||||
import \
|
import \
|
||||||
|
addrbook \
|
||||||
docshell \
|
docshell \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
|
|
|
@ -192,6 +192,12 @@ nsresult nsMsgSearchValidityManager::InitOfflineMailTable ()
|
||||||
m_offlineMailTable->SetAvailable (nsMsgSearchAttrib::Sender, nsMsgSearchOp::EndsWith, 1);
|
m_offlineMailTable->SetAvailable (nsMsgSearchAttrib::Sender, nsMsgSearchOp::EndsWith, 1);
|
||||||
m_offlineMailTable->SetEnabled (nsMsgSearchAttrib::Sender, nsMsgSearchOp::EndsWith, 1);
|
m_offlineMailTable->SetEnabled (nsMsgSearchAttrib::Sender, nsMsgSearchOp::EndsWith, 1);
|
||||||
|
|
||||||
|
// don't enable this until we are ready to fork rules.dat
|
||||||
|
//m_offlineMailTable->SetAvailable (nsMsgSearchAttrib::SenderInAddressBook, nsMsgSearchOp::IsInAB, 1);
|
||||||
|
//m_offlineMailTable->SetEnabled (nsMsgSearchAttrib::SenderInAddressBook, nsMsgSearchOp::IsInAB, 1);
|
||||||
|
//m_offlineMailTable->SetAvailable (nsMsgSearchAttrib::SenderInAddressBook, nsMsgSearchOp::IsntInAB, 1);
|
||||||
|
//m_offlineMailTable->SetEnabled (nsMsgSearchAttrib::SenderInAddressBook, nsMsgSearchOp::IsntInAB, 1);
|
||||||
|
|
||||||
m_offlineMailTable->SetAvailable (nsMsgSearchAttrib::To, nsMsgSearchOp::Contains, 1);
|
m_offlineMailTable->SetAvailable (nsMsgSearchAttrib::To, nsMsgSearchOp::Contains, 1);
|
||||||
m_offlineMailTable->SetEnabled (nsMsgSearchAttrib::To, nsMsgSearchOp::Contains, 1);
|
m_offlineMailTable->SetEnabled (nsMsgSearchAttrib::To, nsMsgSearchOp::Contains, 1);
|
||||||
m_offlineMailTable->SetAvailable (nsMsgSearchAttrib::To, nsMsgSearchOp::DoesntContain, 1);
|
m_offlineMailTable->SetAvailable (nsMsgSearchAttrib::To, nsMsgSearchOp::DoesntContain, 1);
|
||||||
|
@ -394,6 +400,12 @@ nsresult nsMsgSearchValidityManager::InitOnlineMailFilterTable ()
|
||||||
m_onlineMailFilterTable->SetAvailable (nsMsgSearchAttrib::Sender, nsMsgSearchOp::EndsWith, 1);
|
m_onlineMailFilterTable->SetAvailable (nsMsgSearchAttrib::Sender, nsMsgSearchOp::EndsWith, 1);
|
||||||
m_onlineMailFilterTable->SetEnabled (nsMsgSearchAttrib::Sender, nsMsgSearchOp::EndsWith, 1);
|
m_onlineMailFilterTable->SetEnabled (nsMsgSearchAttrib::Sender, nsMsgSearchOp::EndsWith, 1);
|
||||||
|
|
||||||
|
// don't enable this until we are ready to fork rules.dat
|
||||||
|
//m_onlineMailFilterTable->SetAvailable (nsMsgSearchAttrib::SenderInAddressBook, nsMsgSearchOp::IsInAB, 1);
|
||||||
|
//m_onlineMailFilterTable->SetEnabled (nsMsgSearchAttrib::SenderInAddressBook, nsMsgSearchOp::IsInAB, 1);
|
||||||
|
//m_onlineMailFilterTable->SetAvailable (nsMsgSearchAttrib::SenderInAddressBook, nsMsgSearchOp::IsntInAB, 1);
|
||||||
|
//m_onlineMailFilterTable->SetEnabled (nsMsgSearchAttrib::SenderInAddressBook, nsMsgSearchOp::IsntInAB, 1);
|
||||||
|
|
||||||
m_onlineMailFilterTable->SetAvailable (nsMsgSearchAttrib::To, nsMsgSearchOp::Contains, 1);
|
m_onlineMailFilterTable->SetAvailable (nsMsgSearchAttrib::To, nsMsgSearchOp::Contains, 1);
|
||||||
m_onlineMailFilterTable->SetEnabled (nsMsgSearchAttrib::To, nsMsgSearchOp::Contains, 1);
|
m_onlineMailFilterTable->SetEnabled (nsMsgSearchAttrib::To, nsMsgSearchOp::Contains, 1);
|
||||||
m_onlineMailFilterTable->SetAvailable (nsMsgSearchAttrib::To, nsMsgSearchOp::DoesntContain, 1);
|
m_onlineMailFilterTable->SetAvailable (nsMsgSearchAttrib::To, nsMsgSearchOp::DoesntContain, 1);
|
||||||
|
|
|
@ -567,6 +567,7 @@ nsresult nsMsgSearchOfflineMail::MatchTerms(nsIMsgDBHdr *msgToMatch,
|
||||||
charset = (const char*)defaultCharset;
|
charset = (const char*)defaultCharset;
|
||||||
switch (attrib)
|
switch (attrib)
|
||||||
{
|
{
|
||||||
|
case nsMsgSearchAttrib::SenderInAddressBook:
|
||||||
case nsMsgSearchAttrib::Sender:
|
case nsMsgSearchAttrib::Sender:
|
||||||
msgToMatch->GetAuthor(getter_Copies(matchString));
|
msgToMatch->GetAuthor(getter_Copies(matchString));
|
||||||
err = pTerm->MatchRfc822String (matchString, charset, charsetOverride, &result);
|
err = pTerm->MatchRfc822String (matchString, charset, charsetOverride, &result);
|
||||||
|
|
|
@ -58,6 +58,8 @@
|
||||||
#include "nsTime.h"
|
#include "nsTime.h"
|
||||||
#include "nsIPrefBranch.h"
|
#include "nsIPrefBranch.h"
|
||||||
#include "nsIPrefService.h"
|
#include "nsIPrefService.h"
|
||||||
|
|
||||||
|
#include "nsIRDFService.h"
|
||||||
#include "nsISupportsObsolete.h"
|
#include "nsISupportsObsolete.h"
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
@ -86,7 +88,8 @@ nsMsgSearchAttribEntry SearchAttribEntryTable[] =
|
||||||
{nsMsgSearchAttrib::MsgStatus, "status"},
|
{nsMsgSearchAttrib::MsgStatus, "status"},
|
||||||
{nsMsgSearchAttrib::To, "to"},
|
{nsMsgSearchAttrib::To, "to"},
|
||||||
{nsMsgSearchAttrib::CC, "cc"},
|
{nsMsgSearchAttrib::CC, "cc"},
|
||||||
{nsMsgSearchAttrib::ToOrCC, "to or cc"}
|
{nsMsgSearchAttrib::ToOrCC, "to or cc"},
|
||||||
|
{nsMsgSearchAttrib::SenderInAddressBook, "from in ab"}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Take a string which starts off with an attribute
|
// Take a string which starts off with an attribute
|
||||||
|
@ -207,7 +210,9 @@ nsMsgSearchOperatorEntry SearchOperatorEntryTable[] =
|
||||||
{nsMsgSearchOp::IsHigherThan, "is higher than"},
|
{nsMsgSearchOp::IsHigherThan, "is higher than"},
|
||||||
{nsMsgSearchOp::IsLowerThan, "is lower than"},
|
{nsMsgSearchOp::IsLowerThan, "is lower than"},
|
||||||
{nsMsgSearchOp::BeginsWith, "begins with"},
|
{nsMsgSearchOp::BeginsWith, "begins with"},
|
||||||
{nsMsgSearchOp::EndsWith, "ends with"}
|
{nsMsgSearchOp::EndsWith, "ends with"},
|
||||||
|
{nsMsgSearchOp::IsInAB, "is in ab"},
|
||||||
|
{nsMsgSearchOp::IsntInAB, "isn't in ab"},
|
||||||
};
|
};
|
||||||
|
|
||||||
nsresult NS_MsgGetOperatorFromString(const char *string, PRInt16 *op)
|
nsresult NS_MsgGetOperatorFromString(const char *string, PRInt16 *op)
|
||||||
|
@ -816,7 +821,50 @@ nsresult nsMsgSearchTerm::MatchBody (nsIMsgSearchScopeTerm *scope, PRUint32 offs
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsresult nsMsgSearchTerm::InitializeAddressBook()
|
||||||
|
{
|
||||||
|
// the search attribute value has the URI for the address book we need to load.
|
||||||
|
// we need both the database and the directory.
|
||||||
|
nsresult rv = NS_OK;
|
||||||
|
|
||||||
|
if (mDirectory)
|
||||||
|
{
|
||||||
|
nsXPIDLCString dirURI;
|
||||||
|
mDirectory->GetDirUri(getter_Copies(dirURI));
|
||||||
|
if (strcmp(dirURI.get(), m_value.string))
|
||||||
|
mDirectory = NULL; // clear out the directory....we are no longer pointing to the right one
|
||||||
|
}
|
||||||
|
if (!mDirectory)
|
||||||
|
{
|
||||||
|
nsCOMPtr <nsIRDFService> rdfService = do_GetService("@mozilla.org/rdf/rdf-service;1",&rv);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
nsCOMPtr <nsIRDFResource> resource;
|
||||||
|
rv = rdfService->GetResource(m_value.string, getter_AddRefs(resource));
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
mDirectory = do_QueryInterface(resource, &rv);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult nsMsgSearchTerm::MatchInAddressBook(const char * aAddress, PRBool *pResult)
|
||||||
|
{
|
||||||
|
nsresult rv = InitializeAddressBook();
|
||||||
|
*pResult = PR_FALSE;
|
||||||
|
|
||||||
|
if (mDirectory)
|
||||||
|
{
|
||||||
|
PRBool cardExists = PR_FALSE;
|
||||||
|
rv = mDirectory->HasCardForEmailAddress(aAddress, &cardExists);
|
||||||
|
if ( (m_operator == nsMsgSearchOp::IsInAB && cardExists) || (m_operator == nsMsgSearchOp::IsntInAB && !cardExists))
|
||||||
|
*pResult = PR_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
// *pResult is PR_FALSE when strings don't match, PR_TRUE if they do.
|
// *pResult is PR_FALSE when strings don't match, PR_TRUE if they do.
|
||||||
nsresult nsMsgSearchTerm::MatchRfc2047String (const char *rfc2047string,
|
nsresult nsMsgSearchTerm::MatchRfc2047String (const char *rfc2047string,
|
||||||
|
@ -836,6 +884,11 @@ nsresult nsMsgSearchTerm::MatchRfc2047String (const char *rfc2047string,
|
||||||
charset, charsetOverride,
|
charset, charsetOverride,
|
||||||
PR_FALSE);
|
PR_FALSE);
|
||||||
|
|
||||||
|
if (nsMsgSearchAttrib::SenderInAddressBook == m_attribute)
|
||||||
|
{
|
||||||
|
res = MatchInAddressBook(stringToMatch ? stringToMatch : rfc2047string, pResult);
|
||||||
|
}
|
||||||
|
else
|
||||||
res = MatchString(stringToMatch ? stringToMatch : rfc2047string,
|
res = MatchString(stringToMatch ? stringToMatch : rfc2047string,
|
||||||
nsnull, pResult);
|
nsnull, pResult);
|
||||||
|
|
||||||
|
@ -957,7 +1010,6 @@ nsresult nsMsgSearchTerm::GetMatchAllBeforeDeciding (PRBool *aResult)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nsresult nsMsgSearchTerm::MatchRfc822String (const char *string, const char *charset, PRBool charsetOverride, PRBool *pResult)
|
nsresult nsMsgSearchTerm::MatchRfc822String (const char *string, const char *charset, PRBool charsetOverride, PRBool *pResult)
|
||||||
{
|
{
|
||||||
if (!pResult)
|
if (!pResult)
|
||||||
|
@ -997,9 +1049,16 @@ nsresult nsMsgSearchTerm::MatchRfc822String (const char *string, const char *cha
|
||||||
{
|
{
|
||||||
walkNames = names + namePos;
|
walkNames = names + namePos;
|
||||||
walkAddresses = addresses + addressPos;
|
walkAddresses = addresses + addressPos;
|
||||||
|
if (nsMsgSearchAttrib::SenderInAddressBook == m_attribute)
|
||||||
|
{
|
||||||
|
err = MatchRfc2047String (walkAddresses.get(), charset, charsetOverride, &result);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
err = MatchRfc2047String (walkNames.get(), charset, charsetOverride, &result);
|
err = MatchRfc2047String (walkNames.get(), charset, charsetOverride, &result);
|
||||||
if (boolContinueLoop == result)
|
if (boolContinueLoop == result)
|
||||||
err = MatchRfc2047String (walkAddresses.get(), charset, charsetOverride, &result);
|
err = MatchRfc2047String (walkAddresses.get(), charset, charsetOverride, &result);
|
||||||
|
}
|
||||||
|
|
||||||
namePos += walkNames.Length() + 1;
|
namePos += walkNames.Length() + 1;
|
||||||
addressPos += walkAddresses.Length() + 1;
|
addressPos += walkAddresses.Length() + 1;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче