Browse Source

P4TB-357: For the Mac AB use nsIAbCard.localId as a persistent ID.

1.1.101
Jorg Knobloch 2 years ago
parent
commit
5eb93ca9b3
1 changed files with 14 additions and 12 deletions
  1. +14
    -12
      addon/content/TbContacts.js

+ 14
- 12
addon/content/TbContacts.js View File

@ -4,11 +4,11 @@ var { MailServices } = ChromeUtils.import("resource:///modules/MailServices.jsm"
var { pEp } = ChromeUtils.import("chrome://pEp4Tb/content/modules/pEp.js");
const TbContacts = {
getCardForEmail(emailAddress) {
getCardUserIdForEmail(emailAddress) {
// copied from msgHdrViewOverlay.js
const books = MailServices.ab.directories;
const result = { book: null, card: null };
while (!result.card && books.hasMoreElements()) {
let userId = null;
while (books.hasMoreElements()) {
const ab = books.getNext().QueryInterface(Ci.nsIAbDirectory);
// Thunderbird supports four different types of address book:
// 1) Its own local address book.
@ -23,29 +23,31 @@ const TbContacts = {
// For LDAP and Outlook ABs, the `cardForEmailAddress()` method is not implemented,
// one would have to do a `nsIAbDirectoryQuery.doQuery()` to locate a card.
// The Mac AB doesn't return a stable UID, that is, in the next Thunderbird session
// a new UID is returned.
// a new UID is returned. However, localId can be used.
// Mac and LDAP ABs are readlonly, the Outlook AB is not.
// Right now, we're only looking at local ABs.
let abURI = ab.URI;
if (abURI.startsWith("moz-abldapdirectory:") || abURI.startsWith("moz-abosxdirectory:") ||
abURI.startsWith("moz-aboutlookdirectory:")) continue;
if (abURI.startsWith("moz-abldapdirectory:") || abURI.startsWith("moz-aboutlookdirectory:")) continue;
try {
const card = ab.cardForEmailAddress(emailAddress);
if (card) {
result.book = ab;
result.card = card;
if (abURI.startsWith("moz-abosxdirectory:")) {
// localId is of the form: moz-abosxcard://ACE6A928-78EA-46CC-8186-1B4E5F08E7B8:ABPerson
userId = card.localId.substr(16, 36);
} else {
userId = card.UID;
}
break;
}
} catch (ex) {
console.error(`Error (${ex.message}) fetching card from address book ${ab.dirName} for ${emailAddress}`);
}
}
return result;
return userId;
},
getpEpIdentity({ name, email }) {
let card = this.getCardForEmail(email).card;
return new pEp.Identity(email, card && card.UID, name);
return new pEp.Identity(email, this.getCardUserIdForEmail(email), name);
},
getpEpOwnIdentity({ name, email }) {


Loading…
Cancel
Save