Bug 842632, part 3c: Use the C++ API in addrbook, r=Standard8.
This commit is contained in:
Родитель
74c1434f73
Коммит
a97dae91ae
|
@ -11,12 +11,14 @@
|
|||
#include "nsAbAddressCollector.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIMsgHeaderParser.h"
|
||||
#include "nsStringGlue.h"
|
||||
#include "prmem.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsIAbManager.h"
|
||||
#include "mozilla/mailnews/MimeHeaderParser.h"
|
||||
|
||||
using namespace mozilla::mailnews;
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsAbAddressCollector, nsIAbAddressCollector, nsIObserver)
|
||||
|
||||
|
@ -91,48 +93,23 @@ nsAbAddressCollector::CollectAddress(const nsACString &aAddresses,
|
|||
|
||||
// note that we're now setting the whole recipient list,
|
||||
// not just the pretty name of the first recipient.
|
||||
uint32_t numAddresses;
|
||||
char *names;
|
||||
char *addresses;
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIMsgHeaderParser> pHeader = do_GetService(NS_MAILNEWS_MIME_HEADER_PARSER_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
rv = pHeader->ParseHeaderAddresses(PromiseFlatCString(aAddresses).get(),
|
||||
&names, &addresses, &numAddresses);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to parse, so can't collect");
|
||||
if (NS_FAILED(rv))
|
||||
return NS_OK;
|
||||
|
||||
char *curNamePtr = names;
|
||||
char *curAddressPtr = addresses;
|
||||
nsTArray<nsCString> names;
|
||||
nsTArray<nsCString> addresses;
|
||||
ExtractAllAddresses(EncodedHeader(aAddresses),
|
||||
UTF16ArrayAdapter<>(names), UTF16ArrayAdapter<>(addresses));
|
||||
uint32_t numAddresses = names.Length();
|
||||
|
||||
for (uint32_t i = 0; i < numAddresses; i++)
|
||||
{
|
||||
nsDependentCString curAddress(curAddressPtr);
|
||||
curAddressPtr += curAddress.Length() + 1;
|
||||
|
||||
nsCString unquotedName;
|
||||
rv = pHeader->UnquotePhraseOrAddr(curNamePtr, false,
|
||||
getter_Copies(unquotedName));
|
||||
curNamePtr += strlen(curNamePtr) + 1;
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to unquote name");
|
||||
if (NS_FAILED(rv))
|
||||
continue;
|
||||
|
||||
// Don't allow collection of addresses with no email address, it makes
|
||||
// no sense. Whilst we should never get here in most normal cases, we
|
||||
// should still be careful.
|
||||
if (curAddress.IsEmpty())
|
||||
if (addresses[i].IsEmpty())
|
||||
continue;
|
||||
|
||||
CollectSingleAddress(curAddress, unquotedName, aCreateCard, aSendFormat,
|
||||
CollectSingleAddress(addresses[i], names[i], aCreateCard, aSendFormat,
|
||||
false);
|
||||
}
|
||||
|
||||
PR_FREEIF(addresses);
|
||||
PR_FREEIF(names);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче