Bug 1736124 - Addressbook vCard exports and imports with work and home url. r=mkmelin

If you Import Address books (via vCard) from older Thunderbird Versions we do need a workaround. Otherwise the URL will not be used with the new types (type=home or type=work).
Importing a URL without any type isn't really supported by our UI(abCard) so far.
That's why i would go for the solution that when Importing a vCard without any type specification it would behave as prior to this patch.
This means that the first URL without any type will be specified as Work Web Page.
If a URL with type=work is specified in the imported vCard the workaround will be dropped and the URL without any type specification is not imported at all.

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

Depends on D131249
This commit is contained in:
Nicolai Kasper 2021-11-16 15:56:41 +00:00
Родитель a4e099400b
Коммит eb6356d730
3 изменённых файлов: 53 добавлений и 3 удалений

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

@ -75,8 +75,14 @@ var VCardUtils = {
}
}
}
// Preserve URL if no URL with type work is given take for `url.work` the URL without any type.
if (name == "url") {
name = type.includes("home") ? "url.home" : name;
name = type.includes("work") ? "url.work" : name;
}
if (!(name in typeMap)) {
// Special treatment for `url`, which is not in the typeMap.
if (!(name in typeMap) && name != "url") {
continue;
}
@ -90,6 +96,13 @@ var VCardUtils = {
vPropMap.get(name).push({ index, pref, value });
}
// If no URL with type is specified assume its the Work Web Page (WebPage 1).
if (vPropMap.has("url") && !vPropMap.has("url.work")) {
vPropMap.set("url.work", vPropMap.get("url"));
}
// AbCard only supports Work Web Page or Home Web Page. Get rid of the URL without type.
vPropMap.delete("url");
for (let props of vPropMap.values()) {
// Sort the properties by preference, or by the order they appeared.
props.sort((a, b) => {
@ -501,7 +514,8 @@ var typeMap = {
"tel.fax": singleTextProperty("FaxNumber", "tel", { type: "fax" }),
"tel.pager": singleTextProperty("PagerNumber", "tel", { type: "pager" }),
"tel.cell": singleTextProperty("CellularNumber", "tel", { type: "cell" }),
url: singleTextProperty("WebPage1", "url", {}, "url"),
"url.work": singleTextProperty("WebPage1", "url", { type: "work" }, "url"),
"url.home": singleTextProperty("WebPage2", "url", { type: "home" }, "url"),
"x-mozilla-html": {
*fromAbCard(map) {
if (!map.has("PreferMailFormat")) {

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

@ -75,7 +75,8 @@ function run_test() {
lines.includes("TEL;TYPE=cell;VALUE=TEXT:CellularNumber1"),
"TEL;TYPE=cell"
);
Assert.ok(lines.includes("URL;VALUE=URL:http://WebPage21"), "URL");
Assert.ok(lines.includes("URL;TYPE=work;VALUE=URL:http://WebPage21"), "URL");
Assert.ok(lines.includes("URL;TYPE=home;VALUE=URL:http://WebPage11"), "URL");
Assert.ok(lines.includes("UID:fdcb9131-38ec-4daf-a4a7-2ef115f562a7"), "UID");
// Test - XML

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

@ -167,6 +167,41 @@ add_task(function testVCardToAbCard() {
Department: "Manufacturing",
});
// URL
// If no type is given assume its WebPage1 (work).
check("URL:https://www.thunderbird.net/", {
WebPage1: "https://www.thunderbird.net/",
});
check("URL;TYPE=work:https://developer.thunderbird.net/", {
WebPage1: "https://developer.thunderbird.net/",
});
check("URL;TYPE=home:https://addons.thunderbird.net/", {
WebPage2: "https://addons.thunderbird.net/",
});
check(
formatVCard`
URL;TYPE=home:https://addons.thunderbird.net/
URL;TYPE=work:https://developer.thunderbird.net/`,
{
WebPage1: "https://developer.thunderbird.net/",
WebPage2: "https://addons.thunderbird.net/",
}
);
// If a URL without a type is given and a Work Web Page do not import the URL without type.
check(
formatVCard`
URL:https://www.thunderbird.net/
URL;TYPE=home:https://addons.thunderbird.net/
URL;TYPE=work:https://developer.thunderbird.net/`,
{
WebPage1: "https://developer.thunderbird.net/",
WebPage2: "https://addons.thunderbird.net/",
}
);
// Email: just to be difficult, email is stored by priority, not type.
check("EMAIL:first@invalid", { PrimaryEmail: "first@invalid" });
check("EMAIL;PREF=1:first@invalid", { PrimaryEmail: "first@invalid" });