Bug 129393 - Side effect of locating card info with case sensitive email addresses - Collected Address Book contains duplicates because adding is case sensitive. r=standard8
This commit is contained in:
Родитель
7c02ec3716
Коммит
07356a56b8
|
@ -32,6 +32,7 @@ interface nsISimpleEnumerator;
|
|||
#define kMailListTotalAddresses "ListTotalAddresses"
|
||||
// not shown in the UI
|
||||
#define kLowerPriEmailColumn "LowercasePrimaryEmail"
|
||||
#define kLower2ndEmailColumn "LowercaseSecondEmail"
|
||||
|
||||
// Palm Integration
|
||||
#define CARD_ATTRIB_PALMID "PalmRecId"
|
||||
|
|
|
@ -37,13 +37,12 @@ nsAbAddressCollector::~nsAbAddressCollector()
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the first card found with a given property name/value pair. This
|
||||
* Returns the first card found with the specified email address. This
|
||||
* returns an already addrefed pointer to the card if the card is found.
|
||||
*/
|
||||
already_AddRefed<nsIAbCard>
|
||||
nsAbAddressCollector::GetCardFromProperty(const char *aName,
|
||||
const nsACString &aValue,
|
||||
nsIAbDirectory **aDirectory)
|
||||
nsAbAddressCollector::GetCardForAddress(const nsACString &aEmailAddress,
|
||||
nsIAbDirectory **aDirectory)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID, &rv));
|
||||
|
@ -68,9 +67,11 @@ nsAbAddressCollector::GetCardFromProperty(const char *aName,
|
|||
|
||||
// Some implementations may return NS_ERROR_NOT_IMPLEMENTED here,
|
||||
// so just catch the value and continue.
|
||||
if (NS_FAILED(directory->GetCardFromProperty(aName, aValue, true,
|
||||
if (NS_FAILED(directory->CardForEmailAddress(aEmailAddress,
|
||||
getter_AddRefs(result))))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
|
@ -124,25 +125,10 @@ nsAbAddressCollector::CollectSingleAddress(const nsACString &aEmail,
|
|||
return NS_OK;
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIAbCard> card;
|
||||
bool emailAddressIn2ndEmailColumn = false;
|
||||
|
||||
nsCOMPtr<nsIAbDirectory> originDirectory;
|
||||
|
||||
if (!aSkipCheckExisting)
|
||||
{
|
||||
card = GetCardFromProperty(kPriEmailProperty, aEmail,
|
||||
getter_AddRefs(originDirectory));
|
||||
// We've not found a card, but is this address actually in the additional
|
||||
// email column?
|
||||
if (!card)
|
||||
{
|
||||
card = GetCardFromProperty(k2ndEmailProperty, aEmail,
|
||||
getter_AddRefs(originDirectory));
|
||||
if (card)
|
||||
emailAddressIn2ndEmailColumn = true;
|
||||
}
|
||||
}
|
||||
nsCOMPtr<nsIAbCard> card = (!aSkipCheckExisting) ?
|
||||
GetCardForAddress(aEmail, getter_AddRefs(originDirectory)) : nullptr;
|
||||
|
||||
if (!card && (aCreateCard || aSkipCheckExisting))
|
||||
{
|
||||
|
@ -163,7 +149,7 @@ nsAbAddressCollector::CollectSingleAddress(const nsACString &aEmail,
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (card && !emailAddressIn2ndEmailColumn && originDirectory)
|
||||
else if (card && originDirectory)
|
||||
{
|
||||
// It could be that the origin directory is read-only, so don't try and
|
||||
// write to it if it is.
|
||||
|
|
|
@ -29,9 +29,8 @@ public:
|
|||
nsresult Init();
|
||||
|
||||
private:
|
||||
already_AddRefed<nsIAbCard> GetCardFromProperty(const char *aName,
|
||||
const nsACString &aValue,
|
||||
nsIAbDirectory **aDirectory);
|
||||
already_AddRefed<nsIAbCard> GetCardForAddress(const nsACString &aEmailAddress,
|
||||
nsIAbDirectory **aDirectory);
|
||||
void AutoCollectScreenName(nsIAbCard *aCard, const nsACString &aEmail);
|
||||
bool SetNamesForCard(nsIAbCard *aSenderCard, const nsACString &aFullName);
|
||||
void SplitFullName(const nsCString &aFullName, nsCString &aFirstName,
|
||||
|
|
|
@ -1015,7 +1015,7 @@ NS_IMETHODIMP nsAbMDBDirectory::CardForEmailAddress(const nsACString &aEmailAddr
|
|||
{
|
||||
NS_ENSURE_ARG_POINTER(aAbCard);
|
||||
|
||||
*aAbCard = NULL;
|
||||
*aAbCard = nullptr;
|
||||
|
||||
// Ensure that if we've not been given an email address we never match
|
||||
// so that we don't fail out unnecessarily and we don't match a blank email
|
||||
|
@ -1044,14 +1044,15 @@ NS_IMETHODIMP nsAbMDBDirectory::CardForEmailAddress(const nsACString &aEmailAddr
|
|||
if (lowerEmail.IsEmpty())
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
mDatabase->GetCardFromAttribute(this, kLowerPriEmailColumn, NS_ConvertUTF16toUTF8(lowerEmail),
|
||||
mDatabase->GetCardFromAttribute(this, kLowerPriEmailColumn,
|
||||
NS_ConvertUTF16toUTF8(lowerEmail),
|
||||
false, aAbCard);
|
||||
if (!*aAbCard)
|
||||
// We don't have a lower case second email column, so we have to search
|
||||
// case-sensitively here.
|
||||
mDatabase->GetCardFromAttribute(this, k2ndEmailProperty, aEmailAddress,
|
||||
true, aAbCard);
|
||||
|
||||
{
|
||||
mDatabase->GetCardFromAttribute(this, kLower2ndEmailColumn,
|
||||
NS_ConvertUTF16toUTF8(lowerEmail),
|
||||
false, aAbCard);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -725,6 +725,10 @@ nsresult nsAddrDatabase::AddRowToDeletedCardsTable(nsIAbCard *card, nsIMdbRow **
|
|||
if (!unicodeStr.IsEmpty())
|
||||
AddUnicodeToColumn(cardRow, m_PriEmailColumnToken, m_LowerPriEmailColumnToken, unicodeStr.get());
|
||||
|
||||
card->GetPropertyAsAString(k2ndEmailProperty, unicodeStr);
|
||||
if (!unicodeStr.IsEmpty())
|
||||
AddUnicodeToColumn(cardRow, m_2ndEmailColumnToken, m_Lower2ndEmailColumnToken, unicodeStr.get());
|
||||
|
||||
uint32_t nowInSeconds;
|
||||
PRTime now = PR_Now();
|
||||
PRTime2Seconds(now, &nowInSeconds);
|
||||
|
@ -951,7 +955,7 @@ nsresult nsAddrDatabase::UpdateLowercaseEmailListName()
|
|||
NS_ENSURE_TRUE(NS_SUCCEEDED(merror) && rowCursor, NS_ERROR_FAILURE);
|
||||
|
||||
do
|
||||
{ //add lowercase primary email to each card and mailing list row
|
||||
{ // Add lowercase primary+secondary email to each card and mailing list row.
|
||||
merror = rowCursor->NextRow(m_mdbEnv, &findRow, &rowPos);
|
||||
if (NS_SUCCEEDED(merror) && findRow)
|
||||
{
|
||||
|
@ -963,22 +967,30 @@ nsresult nsAddrDatabase::UpdateLowercaseEmailListName()
|
|||
if (IsCardRowScopeToken(rowOid.mOid_Scope))
|
||||
{
|
||||
err = GetStringColumn(findRow, m_LowerPriEmailColumnToken, tempString);
|
||||
if (NS_SUCCEEDED(err))
|
||||
break;
|
||||
if (NS_FAILED(err)) // not set yet
|
||||
{
|
||||
err = ConvertAndAddLowercaseColumn(findRow, m_PriEmailColumnToken,
|
||||
m_LowerPriEmailColumnToken);
|
||||
commitRequired = commitRequired || NS_SUCCEEDED(err);
|
||||
}
|
||||
|
||||
err = ConvertAndAddLowercaseColumn(findRow, m_PriEmailColumnToken,
|
||||
m_LowerPriEmailColumnToken);
|
||||
commitRequired = true;
|
||||
err = GetStringColumn(findRow, m_Lower2ndEmailColumnToken, tempString);
|
||||
if (NS_FAILED(err)) // not set yet
|
||||
{
|
||||
err = ConvertAndAddLowercaseColumn(findRow, m_2ndEmailColumnToken,
|
||||
m_Lower2ndEmailColumnToken);
|
||||
commitRequired = commitRequired || NS_SUCCEEDED(err);
|
||||
}
|
||||
}
|
||||
else if (IsListRowScopeToken(rowOid.mOid_Scope))
|
||||
{
|
||||
err = GetStringColumn(findRow, m_LowerListNameColumnToken, tempString);
|
||||
if (NS_SUCCEEDED(err))
|
||||
break;
|
||||
if (NS_SUCCEEDED(err)) // already set up
|
||||
continue;
|
||||
|
||||
err = ConvertAndAddLowercaseColumn(findRow, m_ListNameColumnToken,
|
||||
m_LowerListNameColumnToken);
|
||||
commitRequired = true;
|
||||
commitRequired = commitRequired || NS_SUCCEEDED(err);
|
||||
}
|
||||
}
|
||||
findRow->Release();
|
||||
|
@ -1047,6 +1059,7 @@ nsresult nsAddrDatabase::InitMDBInfo()
|
|||
m_mdbStore->StringToToken(m_mdbEnv, kPriEmailProperty, &m_PriEmailColumnToken);
|
||||
m_mdbStore->StringToToken(m_mdbEnv, kLowerPriEmailColumn, &m_LowerPriEmailColumnToken);
|
||||
m_mdbStore->StringToToken(m_mdbEnv, k2ndEmailProperty, &m_2ndEmailColumnToken);
|
||||
m_mdbStore->StringToToken(m_mdbEnv, kLower2ndEmailColumn, &m_Lower2ndEmailColumnToken);
|
||||
m_mdbStore->StringToToken(m_mdbEnv, kPreferMailFormatProperty, &m_MailFormatColumnToken);
|
||||
m_mdbStore->StringToToken(m_mdbEnv, kPopularityIndexProperty, &m_PopularityIndexColumnToken);
|
||||
m_mdbStore->StringToToken(m_mdbEnv, kAllowRemoteContentProperty, &m_AllowRemoteContentColumnToken);
|
||||
|
@ -2321,6 +2334,19 @@ NS_IMETHODIMP nsAddrDatabase::AddPrimaryEmail(nsIMdbRow *aRow, const char *aValu
|
|||
return rv;
|
||||
}
|
||||
|
||||
/* value is UTF8 string */
|
||||
NS_IMETHODIMP nsAddrDatabase::Add2ndEmail(nsIMdbRow *aRow, const char *aValue)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aValue);
|
||||
|
||||
nsresult rv = AddCharStringColumn(aRow, m_2ndEmailColumnToken, aValue);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
rv = AddLowercaseColumn(aRow, m_Lower2ndEmailColumnToken, aValue);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* value is UTF8 string */
|
||||
NS_IMETHODIMP nsAddrDatabase::AddListName(nsIMdbRow *aRow, const char *aValue)
|
||||
{
|
||||
|
|
|
@ -90,8 +90,7 @@ public:
|
|||
|
||||
NS_IMETHOD AddPrimaryEmail(nsIMdbRow * row, const char * value) MOZ_OVERRIDE;
|
||||
|
||||
NS_IMETHOD Add2ndEmail(nsIMdbRow * row, const char * value) MOZ_OVERRIDE
|
||||
{ return AddCharStringColumn(row, m_2ndEmailColumnToken, value); }
|
||||
NS_IMETHOD Add2ndEmail(nsIMdbRow * row, const char * value) MOZ_OVERRIDE;
|
||||
|
||||
NS_IMETHOD AddPreferMailFormat(nsIMdbRow * row, uint32_t value) MOZ_OVERRIDE
|
||||
{ return AddIntColumn(row, m_MailFormatColumnToken, value); }
|
||||
|
@ -409,6 +408,7 @@ protected:
|
|||
mdb_token m_LastModDateColumnToken;
|
||||
mdb_token m_RecordKeyColumnToken;
|
||||
mdb_token m_LowerPriEmailColumnToken;
|
||||
mdb_token m_Lower2ndEmailColumnToken;
|
||||
|
||||
mdb_token m_MailFormatColumnToken;
|
||||
mdb_token m_PopularityIndexColumnToken;
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
* Tests against cards in different ABs are done in test_collection_2.js.
|
||||
*/
|
||||
|
||||
// make xpcshell-tests TEST_PATH=mailnews/addrbook/test/unit/test_collection.js
|
||||
|
||||
const nsIAbPMF = Components.interfaces.nsIAbPreferMailFormat;
|
||||
|
||||
// Source fields (emailHeader/mailFormat) and expected results for use for
|
||||
|
@ -350,10 +352,18 @@ function run_test()
|
|||
nsIAbPMF.unknown,
|
||||
true);
|
||||
|
||||
// Try collecting the same address in another case. This shouldn't create any
|
||||
// new card.
|
||||
collectChecker.addressCollect.collectSingleAddress(kSingleAddress.toUpperCase(),
|
||||
kSingleDisplayName,
|
||||
true,
|
||||
nsIAbPMF.unknown,
|
||||
true);
|
||||
|
||||
childCards = collectChecker.AB.childCards;
|
||||
var foundCards = [];
|
||||
|
||||
while(childCards.hasMoreElements()) {
|
||||
while (childCards.hasMoreElements()) {
|
||||
var card = childCards.getNext();
|
||||
if (card instanceof Ci.nsIAbCard &&
|
||||
card.primaryEmail == kSingleAddress)
|
||||
|
|
Загрузка…
Ссылка в новой задаче