Bug 1614265 - Move escapedVCardToAbCard from nsIAbManager to nsIMsgVCardService. r=mkmelin

Differential Revision: https://phabricator.services.mozilla.com/D62393

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Geoff Lankow 2020-02-12 23:16:44 +00:00
Родитель f193f0ce07
Коммит 781a1e03d5
13 изменённых файлов: 167 добавлений и 35 удалений

Просмотреть файл

@ -417,7 +417,9 @@ MailDefaultHandler.prototype = {
inputStream,
inputStream.available()
);
let card = MailServices.ab.escapedVCardToAbCard(data);
let card = Cc["@mozilla.org/addressbook/msgvcardservice;1"]
.getService(Ci.nsIMsgVCardService)
.escapedVCardToAbCard(data);
Services.ww.openWindow(
null,
"chrome://messenger/content/addressbook/abNewCardDialog.xhtml",

Просмотреть файл

@ -157,9 +157,9 @@ function OnLoadNewCard() {
if ("escapedVCardStr" in window.arguments[0]) {
// hide non vcard values
HideNonVcardFields();
gEditCard.card = MailServices.ab.escapedVCardToAbCard(
window.arguments[0].escapedVCardStr
);
gEditCard.card = Cc["@mozilla.org/addressbook/msgvcardservice;1"]
.getService(Ci.nsIMsgVCardService)
.escapedVCardToAbCard(window.arguments[0].escapedVCardStr);
}
if ("titleProperty" in window.arguments[0]) {

Просмотреть файл

@ -18,5 +18,4 @@ skip-if = os == "linux" || os = "mac"
[browser_emlSubject.js]
[browser_messageSidebar.js]
[browser_vcardActions.js]
fail-if = true
[browser_viewPlaintext.js]

Просмотреть файл

@ -299,9 +299,6 @@ AddrBookManager.prototype = {
}
return false;
},
escapedVCardToAbCard(escapedVCardStr) {
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
},
generateUUID(directoryId, localId) {
return `${directoryId}#${localId}`;
},

Просмотреть файл

@ -149,15 +149,6 @@ interface nsIAbManager : nsISupports
*/
boolean mailListNameExists(in wstring name);
/**
* Translates an escaped vcard string into a nsIAbCard.
*
* @param escapedVCardStr The string containing the vcard.
*
* @return A card containing the translated vcard data.
*/
nsIAbCard escapedVCardToAbCard(in string escapedVCardStr);
/**
* Generates a UUID from a (directory ID, local ID) tuple.
*

Просмотреть файл

@ -5,6 +5,8 @@
#include "nsISupports.idl"
interface nsIAbCard;
%{C++
#include "nsVCardObj.h"
%}
@ -13,7 +15,7 @@
[ptr] native VObjectIterator_ptr(VObjectIterator);
[ptr] native const_char_ptr(const char);
[uuid(8b6ae917-676d-4f1f-bbad-2ecc9be0d9b1)]
[scriptable, builtinclass, uuid(8b6ae917-676d-4f1f-bbad-2ecc9be0d9b1)]
interface nsIMsgVCardService : nsISupports {
[noscript, notxpcom] void cleanVObject(in VObject_ptr o);
[noscript, notxpcom] VObject_ptr nextVObjectInList(in VObject_ptr o);
@ -26,4 +28,13 @@ interface nsIMsgVCardService : nsISupports {
[noscript, notxpcom] long moreIteration(in VObjectIterator_ptr i);
[noscript, notxpcom] const_char_ptr vObjectName(in VObject_ptr o);
[noscript, notxpcom] charPtr vObjectAnyValue(in VObject_ptr o);
/**
* Translates an escaped vcard string into a nsIAbCard.
*
* @param escapedVCardStr The string containing the vcard.
*
* @return A card containing the translated vcard data.
*/
nsIAbCard escapedVCardToAbCard(in string escapedVCardStr);
};

Просмотреть файл

@ -19,9 +19,9 @@
#include "nsMsgUtils.h"
#include "nsIMsgVCardService.h"
#include "nsIAbCard.h"
#include "nsIAbManager.h"
#include "nsVCard.h"
#include "nsIChannel.h"
#include "nsIMsgVCardService.h"
//
// nsAbContentHandler
//
@ -70,12 +70,13 @@ nsAbContentHandler::HandleContent(const char *aContentType,
nsCOMPtr<nsPIDOMWindowOuter> parentWindow =
nsPIDOMWindowOuter::From(domWindow);
nsCOMPtr<nsIAbManager> ab = do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
nsCOMPtr<nsIMsgVCardService> vCardService =
do_GetService(NS_MSGVCARDSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIAbCard> cardFromVCard;
rv = ab->EscapedVCardToAbCard(unescapedData.get(),
getter_AddRefs(cardFromVCard));
rv = vCardService->EscapedVCardToAbCard(unescapedData.get(),
getter_AddRefs(cardFromVCard));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsISupportsInterfacePointer> ifptr =
@ -156,11 +157,13 @@ nsAbContentHandler::OnStreamComplete(nsIStreamLoader *aLoader,
vCard.Adopt(
vCardService->WriteMemoryVObjects(0, &len, vObj.get(), false));
nsCOMPtr<nsIAbManager> ab = do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
nsCOMPtr<nsIMsgVCardService> vCardService =
do_GetService(NS_MSGVCARDSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIAbCard> cardFromVCard;
rv = ab->EscapedVCardToAbCard(vCard.get(), getter_AddRefs(cardFromVCard));
rv = vCardService->EscapedVCardToAbCard(vCard.get(),
getter_AddRefs(cardFromVCard));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<mozIDOMWindowProxy> domWindow = do_GetInterface(aContext);

Просмотреть файл

@ -3,6 +3,10 @@
* 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 "nsIAbCard.h"
#include "nsAbBaseCID.h"
#include "nsString.h"
#include "nsMsgUtils.h"
#include "nsMsgVCardService.h"
#include "nsVCard.h"
#include "prmem.h"
@ -64,3 +68,126 @@ NS_IMETHODIMP_(char *) nsMsgVCardService::VObjectAnyValue(VObject *o) {
if (retval) PL_strcpy(retval, (char *)vObjectAnyValue(o));
return retval;
}
char *getCString(VObject *vObj) {
if (VALUE_TYPE(vObj) == VCVT_USTRINGZ)
return fakeCString(vObjectUStringZValue(vObj));
if (VALUE_TYPE(vObj) == VCVT_STRINGZ)
return PL_strdup(vObjectStringZValue(vObj));
return NULL;
}
static void convertNameValue(VObject *vObj, nsIAbCard *aCard) {
const char *cardPropName = NULL;
// if the vCard property is not a root property then we need to determine its
// exact property. a good example of this is VCTelephoneProp, this prop has
// four objects underneath it: fax, work and home and cellular.
if (PL_strcasecmp(VCCityProp, vObjectName(vObj)) == 0)
cardPropName = kWorkCityProperty;
else if (PL_strcasecmp(VCTelephoneProp, vObjectName(vObj)) == 0) {
if (isAPropertyOf(vObj, VCFaxProp))
cardPropName = kFaxProperty;
else if (isAPropertyOf(vObj, VCWorkProp))
cardPropName = kWorkPhoneProperty;
else if (isAPropertyOf(vObj, VCHomeProp))
cardPropName = kHomePhoneProperty;
else if (isAPropertyOf(vObj, VCCellularProp))
cardPropName = kCellularProperty;
else if (isAPropertyOf(vObj, VCPagerProp))
cardPropName = kPagerProperty;
else
return;
} else if (PL_strcasecmp(VCEmailAddressProp, vObjectName(vObj)) == 0)
cardPropName = kPriEmailProperty;
else if (PL_strcasecmp(VCFamilyNameProp, vObjectName(vObj)) == 0)
cardPropName = kLastNameProperty;
else if (PL_strcasecmp(VCFullNameProp, vObjectName(vObj)) == 0)
cardPropName = kDisplayNameProperty;
else if (PL_strcasecmp(VCGivenNameProp, vObjectName(vObj)) == 0)
cardPropName = kFirstNameProperty;
else if (PL_strcasecmp(VCOrgNameProp, vObjectName(vObj)) == 0)
cardPropName = kCompanyProperty;
else if (PL_strcasecmp(VCOrgUnitProp, vObjectName(vObj)) == 0)
cardPropName = kDepartmentProperty;
else if (PL_strcasecmp(VCPostalCodeProp, vObjectName(vObj)) == 0)
cardPropName = kWorkZipCodeProperty;
else if (PL_strcasecmp(VCRegionProp, vObjectName(vObj)) == 0)
cardPropName = kWorkStateProperty;
else if (PL_strcasecmp(VCStreetAddressProp, vObjectName(vObj)) == 0)
cardPropName = kWorkAddressProperty;
else if (PL_strcasecmp(VCPostalBoxProp, vObjectName(vObj)) == 0)
cardPropName = kWorkAddress2Property;
else if (PL_strcasecmp(VCCountryNameProp, vObjectName(vObj)) == 0)
cardPropName = kWorkCountryProperty;
else if (PL_strcasecmp(VCTitleProp, vObjectName(vObj)) == 0)
cardPropName = kJobTitleProperty;
else if (PL_strcasecmp(VCUseHTML, vObjectName(vObj)) == 0)
cardPropName = kPreferMailFormatProperty;
else if (PL_strcasecmp(VCNoteProp, vObjectName(vObj)) == 0)
cardPropName = kNotesProperty;
else if (PL_strcasecmp(VCURLProp, vObjectName(vObj)) == 0)
cardPropName = kWorkWebPageProperty;
else
return;
if (!VALUE_TYPE(vObj)) return;
char *cardPropValue = getCString(vObj);
if (PL_strcmp(cardPropName, kPreferMailFormatProperty)) {
aCard->SetPropertyAsAUTF8String(cardPropName,
nsDependentCString(cardPropValue));
} else {
if (!PL_strcmp(cardPropValue, "TRUE"))
aCard->SetPropertyAsUint32(cardPropName, nsIAbPreferMailFormat::html);
else if (!PL_strcmp(cardPropValue, "FALSE"))
aCard->SetPropertyAsUint32(cardPropName,
nsIAbPreferMailFormat::plaintext);
else
aCard->SetPropertyAsUint32(cardPropName, nsIAbPreferMailFormat::unknown);
}
PR_FREEIF(cardPropValue);
return;
}
static void convertFromVObject(VObject *vObj, nsIAbCard *aCard) {
if (vObj) {
VObjectIterator t;
convertNameValue(vObj, aCard);
initPropIterator(&t, vObj);
while (moreIteration(&t)) {
VObject *nextObject = nextVObject(&t);
convertFromVObject(nextObject, aCard);
}
}
return;
}
NS_IMETHODIMP nsMsgVCardService::EscapedVCardToAbCard(
const char *aEscapedVCardStr, nsIAbCard **aCard) {
NS_ENSURE_ARG_POINTER(aEscapedVCardStr);
NS_ENSURE_ARG_POINTER(aCard);
nsCOMPtr<nsIAbCard> cardFromVCard =
do_CreateInstance(NS_ABCARDPROPERTY_CONTRACTID);
if (!cardFromVCard) return NS_ERROR_FAILURE;
// aEscapedVCardStr will be "" the first time, before you have a vCard
if (*aEscapedVCardStr != '\0') {
nsCString unescapedData;
MsgUnescapeString(nsDependentCString(aEscapedVCardStr), 0, unescapedData);
VObject *vObj = parse_MIME(unescapedData.get(), unescapedData.Length());
if (vObj) {
convertFromVObject(vObj, cardFromVCard);
cleanVObject(vObj);
} else
NS_WARNING("Parse of vCard failed");
}
cardFromVCard.forget(aCard);
return NS_OK;
}

Просмотреть файл

@ -6,7 +6,9 @@
function run_test() {
// Before bug 387403 this would hang, eating up all the memory until it
// crashed.
MailServices.ab.escapedVCardToAbCard(
"begin:vcard\nfn;quoted-printable:Xxxx=C5=82xx Xxx\nn;quoted-printable:Xxx;Xxxx=C5=82xx \nadr;quoted-printable;quoted-printable;dom:;;xx. Xxxxxxxxxxxx X;Xxxxxx=C3=3"
);
Cc["@mozilla.org/addressbook/msgvcardservice;1"]
.getService(Ci.nsIMsgVCardService)
.escapedVCardToAbCard(
"begin:vcard\nfn;quoted-printable:Xxxx=C5=82xx Xxx\nn;quoted-printable:Xxx;Xxxx=C5=82xx \nadr;quoted-printable;quoted-printable;dom:;;xx. Xxxxxxxxxxxx X;Xxxxxx=C3=3"
);
}

Просмотреть файл

@ -5,7 +5,6 @@ support-files = data/*
[test_basic_nsIAbCard.js]
[test_basic_nsIAbDirectory.js]
[test_bug387403.js]
fail-if = true
[test_bug448165.js]
[test_bug534822.js]
fail-if = true

Просмотреть файл

@ -7,7 +7,6 @@ support-files = resources/*
[test_bug_437556.js]
[test_csv_GetSample.js]
[test_becky_addressbook.js]
fail-if = true
run-if = os == 'win'
[test_becky_filters.js]
run-if = os == 'win'
@ -19,6 +18,5 @@ run-if = os == 'win'
[test_shiftjis_csv.js]
[test_utf16_csv.js]
[test_vcard_import.js]
fail-if = true
[test_winmail.js]
run-if = os == 'win'

Просмотреть файл

@ -8,11 +8,11 @@
#include "nsVCardAddress.h"
#include "nsIAbCard.h"
#include "nsIAbManager.h"
#include "nsIAbDirectory.h"
#include "nsIFile.h"
#include "nsIInputStream.h"
#include "nsILineInputStream.h"
#include "nsIMsgVCardService.h"
#include "plstr.h"
#include "msgCore.h"
@ -51,7 +51,8 @@ nsresult nsVCardAddress::ImportAddresses(bool *pAbort, const char16_t *pName,
nsCOMPtr<nsILineInputStream> lineStream(do_QueryInterface(inputStream, &rv));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIAbManager> ab = do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
nsCOMPtr<nsIMsgVCardService> vCardService =
do_GetService(NS_MSGVCARDSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
bool more = true;
@ -61,8 +62,8 @@ nsresult nsVCardAddress::ImportAddresses(bool *pAbort, const char16_t *pName,
if (NS_SUCCEEDED(rv) && !record.IsEmpty()) {
// Parse the vCard and build an nsIAbCard from it
nsCOMPtr<nsIAbCard> cardFromVCard;
rv =
ab->EscapedVCardToAbCard(record.get(), getter_AddRefs(cardFromVCard));
rv = vCardService->EscapedVCardToAbCard(record.get(),
getter_AddRefs(cardFromVCard));
NS_ENSURE_SUCCESS(rv, rv);
nsIAbCard *outCard;

Просмотреть файл

@ -116,7 +116,9 @@ function OnLoadNewCard()
if ("escapedVCardStr" in window.arguments[0]) {
// hide non vcard values
HideNonVcardFields();
gEditCard.card = MailServices.ab.escapedVCardToAbCard(window.arguments[0].escapedVCardStr);
gEditCard.card = Cc["@mozilla.org/addressbook/msgvcardservice;1"]
.getService(Ci.nsIMsgVCardService)
.escapedVCardToAbCard(window.arguments[0].escapedVCardStr);
}
if ("titleProperty" in window.arguments[0])