summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/addrbook/modules/AddrBookDirectory.jsm
blob: b35f35b147c0032f4200f7170c35273be1f4f057 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
/* This Source Code Form is subject to the terms of the Mozilla Public
 * 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/. */

const EXPORTED_SYMBOLS = ["AddrBookDirectory"];

const { XPCOMUtils } = ChromeUtils.importESModule(
  "resource://gre/modules/XPCOMUtils.sys.mjs"
);
const lazy = {};
XPCOMUtils.defineLazyModuleGetters(lazy, {
  AddrBookCard: "resource:///modules/AddrBookCard.jsm",
  AddrBookMailingList: "resource:///modules/AddrBookMailingList.jsm",
  BANISHED_PROPERTIES: "resource:///modules/VCardUtils.jsm",
  compareAddressBooks: "resource:///modules/AddrBookUtils.jsm",
  newUID: "resource:///modules/AddrBookUtils.jsm",
  VCardProperties: "resource:///modules/VCardUtils.jsm",
});

/**
 * Abstract base class implementing nsIAbDirectory.
 *
 * @abstract
 * @implements {nsIAbDirectory}
 */
class AddrBookDirectory {
  QueryInterface = ChromeUtils.generateQI(["nsIAbDirectory"]);

  constructor() {
    this._uid = null;
    this._dirName = null;
  }

  _initialized = false;
  init(uri) {
    if (this._initialized) {
      throw new Components.Exception(
        `Directory already initialized: ${uri}`,
        Cr.NS_ERROR_ALREADY_INITIALIZED
      );
    }

    // If this._readOnly is true, the user is prevented from making changes to
    // the contacts. Subclasses may override this (for example to sync with a
    // server) by setting this._overrideReadOnly to true, but must clear it
    // before yielding to another thread (e.g. awaiting a Promise).

    if (this._dirPrefId) {
      XPCOMUtils.defineLazyPreferenceGetter(
        this,
        "_readOnly",
        `${this.dirPrefId}.readOnly`,
        false
      );
    }

    this._initialized = true;
  }
  async cleanUp() {
    if (!this._initialized) {
      throw new Components.Exception(
        "Directory not initialized",
        Cr.NS_ERROR_NOT_INITIALIZED
      );
    }
  }

  get _prefBranch() {
    if (this.__prefBranch) {
      return this.__prefBranch;
    }
    if (!this._dirPrefId) {
      throw Components.Exception("No dirPrefId!", Cr.NS_ERROR_NOT_AVAILABLE);
    }
    return (this.__prefBranch = Services.prefs.getBranch(
      `${this._dirPrefId}.`
    ));
  }
  /** @abstract */
  get lists() {
    throw new Components.Exception(
      `${this.constructor.name} does not implement lists getter.`,
      Cr.NS_ERROR_NOT_IMPLEMENTED
    );
  }
  /** @abstract */
  get cards() {
    throw new Components.Exception(
      `${this.constructor.name} does not implement cards getter.`,
      Cr.NS_ERROR_NOT_IMPLEMENTED
    );
  }

  getCard(uid) {
    let card = new lazy.AddrBookCard();
    card.directoryUID = this.UID;
    card._uid = uid;
    card._properties = this.loadCardProperties(uid);
    card._isGoogleCardDAV = this._isGoogleCardDAV;
    return card.QueryInterface(Ci.nsIAbCard);
  }
  /** @abstract */
  loadCardProperties(uid) {
    throw new Components.Exception(
      `${this.constructor.name} does not implement loadCardProperties.`,
      Cr.NS_ERROR_NOT_IMPLEMENTED
    );
  }
  /** @abstract */
  saveCardProperties(uid, properties) {
    throw new Components.Exception(
      `${this.constructor.name} does not implement saveCardProperties.`,
      Cr.NS_ERROR_NOT_IMPLEMENTED
    );
  }
  /** @abstract */
  deleteCard(uid) {
    throw new Components.Exception(
      `${this.constructor.name} does not implement deleteCard.`,
      Cr.NS_ERROR_NOT_IMPLEMENTED
    );
  }
  /** @abstract */
  saveList(list) {
    throw new Components.Exception(
      `${this.constructor.name} does not implement saveList.`,
      Cr.NS_ERROR_NOT_IMPLEMENTED
    );
  }
  /** @abstract */
  deleteList(uid) {
    throw new Components.Exception(
      `${this.constructor.name} does not implement deleteList.`,
      Cr.NS_ERROR_NOT_IMPLEMENTED
    );
  }
  /**
   * Create a Map of the properties to record when saving `card`, including
   * any changes we want to make just before saving.
   *
   * @param {nsIAbCard} card
   * @param {?string} uid
   * @returns {Map<string, string>}
   */
  prepareToSaveCard(card, uid) {
    let propertyMap = new Map(
      Array.from(card.properties, p => [p.name, p.value])
    );
    let newProperties = new Map();

    // Get a VCardProperties object for the card.
    let vCardProperties;
    if (card.supportsVCard) {
      vCardProperties = card.vCardProperties;
    } else {
      vCardProperties = lazy.VCardProperties.fromPropertyMap(propertyMap);
    }

    if (uid) {
      // Force the UID to be as passed.
      vCardProperties.clearValues("uid");
      vCardProperties.addValue("uid", uid);
    } else if (vCardProperties.getFirstValue("uid") != card.UID) {
      vCardProperties.clearValues("uid");
      vCardProperties.addValue("uid", card.UID);
    }

    // Collect only the properties we intend to keep.
    for (let [name, value] of propertyMap) {
      if (lazy.BANISHED_PROPERTIES.includes(name)) {
        continue;
      }
      if (value !== null && value !== undefined && value !== "") {
        newProperties.set(name, value);
      }
    }

    // Add the vCard and the properties from it we want to cache.
    newProperties.set("_vCard", vCardProperties.toVCard());

    let displayName = vCardProperties.getFirstValue("fn");
    newProperties.set("DisplayName", displayName || "");

    let flatten = value => {
      if (Array.isArray(value)) {
        return value.join(" ");
      }
      return value;
    };

    let name = vCardProperties.getFirstValue("n");
    if (Array.isArray(name)) {
      newProperties.set("FirstName", flatten(name[1]));
      newProperties.set("LastName", flatten(name[0]));
    }

    let email = vCardProperties.getAllValuesSorted("email");
    if (email[0]) {
      newProperties.set("PrimaryEmail", email[0]);
    }
    if (email[1]) {
      newProperties.set("SecondEmail", email[1]);
    }

    let nickname = vCardProperties.getFirstValue("nickname");
    if (nickname) {
      newProperties.set("NickName", flatten(nickname));
    }

    // Always set the last modified date.
    newProperties.set("LastModifiedDate", "" + Math.floor(Date.now() / 1000));
    return newProperties;
  }

  /* nsIAbDirectory */

  get readOnly() {
    return this._readOnly;
  }
  get isRemote() {
    return false;
  }
  get isSecure() {
    return false;
  }
  get propertiesChromeURI() {
    return "chrome://messenger/content/addressbook/abAddressBookNameDialog.xhtml";
  }
  get dirPrefId() {
    return this._dirPrefId;
  }
  get dirName() {
    if (this._dirName === null) {
      this._dirName = this.getLocalizedStringValue("description", "");
    }
    return this._dirName;
  }
  set dirName(value) {
    this.setLocalizedStringValue("description", value);
    this._dirName = value;
    Services.obs.notifyObservers(this, "addrbook-directory-updated", "DirName");
  }
  get dirType() {
    return Ci.nsIAbManager.JS_DIRECTORY_TYPE;
  }
  get fileName() {
    return this._fileName;
  }
  get UID() {
    if (!this._uid) {
      if (this._prefBranch.getPrefType("uid") == Services.prefs.PREF_STRING) {
        this._uid = this._prefBranch.getStringPref("uid");
      } else {
        this._uid = lazy.newUID();
        this._prefBranch.setStringPref("uid", this._uid);
      }
    }
    return this._uid;
  }
  get URI() {
    return this._uri;
  }
  get position() {
    return this._prefBranch.getIntPref("position", 1);
  }
  get childNodes() {
    let lists = Array.from(
      this.lists.values(),
      list =>
        new lazy.AddrBookMailingList(
          list.uid,
          this,
          list.name,
          list.nickName,
          list.description
        ).asDirectory
    );
    lists.sort(lazy.compareAddressBooks);
    return lists;
  }
  /** @abstract */
  get childCardCount() {
    throw new Components.Exception(
      `${this.constructor.name} does not implement childCardCount getter.`,
      Cr.NS_ERROR_NOT_IMPLEMENTED
    );
  }
  get childCards() {
    let results = Array.from(
      this.lists.values(),
      list =>
        new lazy.AddrBookMailingList(
          list.uid,
          this,
          list.name,
          list.nickName,
          list.description
        ).asCard
    ).concat(Array.from(this.cards.keys(), this.getCard, this));

    return results;
  }
  get supportsMailingLists() {
    return true;
  }

  search(query, string, listener) {
    if (!listener) {
      return;
    }
    if (!query) {
      listener.onSearchFinished(Cr.NS_ERROR_FAILURE, true, null, "");
      return;
    }
    if (query[0] == "?") {
      query = query.substring(1);
    }

    let results = Array.from(
      this.lists.values(),
      list =>
        new lazy.AddrBookMailingList(
          list.uid,
          this,
          list.name,
          list.nickName,
          list.description
        ).asCard
    ).concat(Array.from(this.cards.keys(), this.getCard, this));

    // Process the query string into a tree of conditions to match.
    let lispRegexp = /^\((and|or|not|([^\)]*)(\)+))/;
    let index = 0;
    let rootQuery = { children: [], op: "or" };
    let currentQuery = rootQuery;

    while (true) {
      let match = lispRegexp.exec(query.substring(index));
      if (!match) {
        break;
      }
      index += match[0].length;

      if (["and", "or", "not"].includes(match[1])) {
        // For the opening bracket, step down a level.
        let child = {
          parent: currentQuery,
          children: [],
          op: match[1],
        };
        currentQuery.children.push(child);
        currentQuery = child;
      } else {
        let [name, condition, value] = match[2].split(",");
        currentQuery.children.push({
          name,
          condition,
          value: decodeURIComponent(value).toLowerCase(),
        });

        // For each closing bracket except the first, step up a level.
        for (let i = match[3].length - 1; i > 0; i--) {
          currentQuery = currentQuery.parent;
        }
      }
    }

    results = results.filter(card => {
      let properties;
      if (card.isMailList) {
        properties = new Map([
          ["DisplayName", card.displayName],
          ["NickName", card.getProperty("NickName", "")],
          ["Notes", card.getProperty("Notes", "")],
        ]);
      } else if (card._properties.has("_vCard")) {
        try {
          properties = card.vCardProperties.toPropertyMap();
        } catch (ex) {
          // Parsing failed. Skip the vCard and just use the other properties.
          console.error(ex);
          properties = new Map();
        }
        for (let [key, value] of card._properties) {
          if (!properties.has(key)) {
            properties.set(key, value);
          }
        }
      } else {
        properties = card._properties;
      }
      let matches = b => {
        if ("condition" in b) {
          let { name, condition, value } = b;
          if (name == "IsMailList" && condition == "=") {
            return card.isMailList == (value == "true");
          }
          let cardValue = properties.get(name);
          if (!cardValue) {
            return condition == "!ex";
          }
          if (condition == "ex") {
            return true;
          }

          cardValue = cardValue.toLowerCase();
          switch (condition) {
            case "=":
              return cardValue == value;
            case "!=":
              return cardValue != value;
            case "lt":
              return cardValue < value;
            case "gt":
              return cardValue > value;
            case "bw":
              return cardValue.startsWith(value);
            case "ew":
              return cardValue.endsWith(value);
            case "c":
              return cardValue.includes(value);
            case "!c":
              return !cardValue.includes(value);
            case "~=":
            case "regex":
            default:
              return false;
          }
        }
        if (b.op == "or") {
          return b.children.some(bb => matches(bb));
        }
        if (b.op == "and") {
          return b.children.every(bb => matches(bb));
        }
        if (b.op == "not") {
          return !matches(b.children[0]);
        }
        return false;
      };

      return matches(rootQuery);
    }, this);

    for (let card of results) {
      listener.onSearchFoundCard(card);
    }
    listener.onSearchFinished(Cr.NS_OK, true, null, "");
  }
  generateName(generateFormat, bundle) {
    return this.dirName;
  }
  cardForEmailAddress(emailAddress) {
    if (!emailAddress) {
      return null;
    }

    // Check the properties. We copy the first two addresses to properties for
    // this purpose, so it should be fast.
    let card = this.getCardFromProperty("PrimaryEmail", emailAddress, false);
    if (card) {
      return card;
    }
    card = this.getCardFromProperty("SecondEmail", emailAddress, false);
    if (card) {
      return card;
    }

    // Nothing so far? Go through all the cards checking all of the addresses.
    // This could be slow.
    emailAddress = emailAddress.toLowerCase();
    for (let [uid, properties] of this.cards) {
      let vCard = properties.get("_vCard");
      // If the vCard string doesn't include the email address, the parsed
      // vCard won't include it either, so don't waste time parsing it.
      if (!vCard?.toLowerCase().includes(emailAddress)) {
        continue;
      }
      card = this.getCard(uid);
      if (card.emailAddresses.some(e => e.toLowerCase() == emailAddress)) {
        return card;
      }
    }

    return null;
  }
  /** @abstract */
  getCardFromProperty(property, value, caseSensitive) {
    throw new Components.Exception(
      `${this.constructor.name} does not implement getCardFromProperty.`,
      Cr.NS_ERROR_NOT_IMPLEMENTED
    );
  }
  /** @abstract */
  getCardsFromProperty(property, value, caseSensitive) {
    throw new Components.Exception(
      `${this.constructor.name} does not implement getCardsFromProperty.`,
      Cr.NS_ERROR_NOT_IMPLEMENTED
    );
  }
  getMailListFromName(name) {
    for (let list of this.lists.values()) {
      if (list.name.toLowerCase() == name.toLowerCase()) {
        return new lazy.AddrBookMailingList(
          list.uid,
          this,
          list.name,
          list.nickName,
          list.description
        ).asDirectory;
      }
    }
    return null;
  }
  deleteDirectory(directory) {
    if (this._readOnly) {
      throw new Components.Exception(
        "Directory is read-only",
        Cr.NS_ERROR_FAILURE
      );
    }

    let list = this.lists.get(directory.UID);
    list = new lazy.AddrBookMailingList(
      list.uid,
      this,
      list.name,
      list.nickName,
      list.description
    );

    this.deleteList(directory.UID);

    Services.obs.notifyObservers(
      list.asDirectory,
      "addrbook-list-deleted",
      this.UID
    );
  }
  hasCard(card) {
    return this.lists.has(card.UID) || this.cards.has(card.UID);
  }
  hasDirectory(dir) {
    return this.lists.has(dir.UID);
  }
  hasMailListWithName(name) {
    return this.getMailListFromName(name) != null;
  }
  addCard(card) {
    return this.dropCard(card, false);
  }
  modifyCard(card) {
    if (this._readOnly && !this._overrideReadOnly) {
      throw new Components.Exception(
        "Directory is read-only",
        Cr.NS_ERROR_FAILURE
      );
    }

    let oldProperties = this.loadCardProperties(card.UID);
    let newProperties = this.prepareToSaveCard(card);

    let allProperties = new Set(oldProperties.keys());
    for (let key of newProperties.keys()) {
      allProperties.add(key);
    }

    if (this.hasOwnProperty("cards")) {
      this.cards.set(card.UID, newProperties);
    }
    this.saveCardProperties(card.UID, newProperties);

    let changeData = {};
    for (let name of allProperties) {
      if (name == "LastModifiedDate") {
        continue;
      }

      let oldValue = oldProperties.get(name) || null;
      let newValue = newProperties.get(name) || null;
      if (oldValue != newValue) {
        changeData[name] = { oldValue, newValue };
      }
    }

    // Increment this preference if one or both of these properties change.
    // This will cause the UI to throw away cached values.
    if ("DisplayName" in changeData || "PreferDisplayName" in changeData) {
      Services.prefs.setIntPref(
        "mail.displayname.version",
        Services.prefs.getIntPref("mail.displayname.version", 0) + 1
      );
    }

    // Send the card as it is in this directory, not as passed to this function.
    let newCard = this.getCard(card.UID);
    Services.obs.notifyObservers(newCard, "addrbook-contact-updated", this.UID);

    Services.obs.notifyObservers(
      newCard,
      "addrbook-contact-properties-updated",
      JSON.stringify(changeData)
    );

    // Return the card, even though the interface says not to, because
    // subclasses may want it.
    return newCard;
  }
  deleteCards(cards) {
    if (this._readOnly && !this._overrideReadOnly) {
      throw new Components.Exception(
        "Directory is read-only",
        Cr.NS_ERROR_FAILURE
      );
    }

    if (cards === null) {
      throw Components.Exception("", Cr.NS_ERROR_INVALID_POINTER);
    }

    let updateDisplayNameVersion = false;
    for (let card of cards) {
      updateDisplayNameVersion = updateDisplayNameVersion || card.displayName;
      // TODO: delete photo if there is one
      this.deleteCard(card.UID);
      if (this.hasOwnProperty("cards")) {
        this.cards.delete(card.UID);
      }
    }

    // Increment this preference if one or more cards has a display name.
    // This will cause the UI to throw away cached values.
    if (updateDisplayNameVersion) {
      Services.prefs.setIntPref(
        "mail.displayname.version",
        Services.prefs.getIntPref("mail.displayname.version", 0) + 1
      );
    }

    for (let card of cards) {
      Services.obs.notifyObservers(card, "addrbook-contact-deleted", this.UID);
      card.directoryUID = null;
    }

    // We could just delete all non-existent cards from list_cards, but a
    // notification should be fired for each one. Let the list handle that.
    for (let list of this.childNodes) {
      list.deleteCards(cards);
    }
  }
  dropCard(card, needToCopyCard) {
    if (this._readOnly && !this._overrideReadOnly) {
      throw new Components.Exception(
        "Directory is read-only",
        Cr.NS_ERROR_FAILURE
      );
    }

    if (!card.UID) {
      throw new Error("Card must have a UID to be added to this directory.");
    }

    let uid = needToCopyCard ? lazy.newUID() : card.UID;
    let newProperties = this.prepareToSaveCard(card, uid);
    if (card.directoryUID && card.directoryUID != this._uid) {
      // These properties belong to a different directory. Don't keep them.
      newProperties.delete("_etag");
      newProperties.delete("_href");
    }

    if (this.hasOwnProperty("cards")) {
      this.cards.set(uid, newProperties);
    }
    this.saveCardProperties(uid, newProperties);

    // Increment this preference if the card has a display name.
    // This will cause the UI to throw away cached values.
    if (card.displayName) {
      Services.prefs.setIntPref(
        "mail.displayname.version",
        Services.prefs.getIntPref("mail.displayname.version", 0) + 1
      );
    }

    let newCard = this.getCard(uid);
    Services.obs.notifyObservers(newCard, "addrbook-contact-created", this.UID);
    return newCard;
  }
  useForAutocomplete(identityKey) {
    return (
      Services.prefs.getBoolPref("mail.enable_autocomplete") &&
      this.getBoolValue("enable_autocomplete", true)
    );
  }
  addMailList(list) {
    if (this._readOnly) {
      throw new Components.Exception(
        "Directory is read-only",
        Cr.NS_ERROR_FAILURE
      );
    }

    if (!list.isMailList) {
      throw Components.Exception(
        "Can't add; not a mail list",
        Cr.NS_ERROR_UNEXPECTED
      );
    }

    // Check if the new name is empty.
    if (!list.dirName) {
      throw new Components.Exception(
        `Mail list name must be set; list.dirName=${list.dirName}`,
        Cr.NS_ERROR_ILLEGAL_VALUE
      );
    }

    // Check if the new name contains 2 spaces.
    if (list.dirName.match("  ")) {
      throw new Components.Exception(
        `Invalid mail list name: ${list.dirName}`,
        Cr.NS_ERROR_ILLEGAL_VALUE
      );
    }

    // Check if the new name contains the following special characters.
    for (let char of ',;"<>') {
      if (list.dirName.includes(char)) {
        throw new Components.Exception(
          `Invalid mail list name: ${list.dirName}`,
          Cr.NS_ERROR_ILLEGAL_VALUE
        );
      }
    }

    let newList = new lazy.AddrBookMailingList(
      lazy.newUID(),
      this,
      list.dirName || "",
      list.listNickName || "",
      list.description || ""
    );
    this.saveList(newList);

    let newListDirectory = newList.asDirectory;
    Services.obs.notifyObservers(
      newListDirectory,
      "addrbook-list-created",
      this.UID
    );
    return newListDirectory;
  }
  editMailListToDatabase(listCard) {
    // Deliberately not implemented, this isn't a mailing list.
    throw Components.Exception(
      "editMailListToDatabase not relevant here",
      Cr.NS_ERROR_NOT_IMPLEMENTED
    );
  }
  copyMailList(srcList) {
    // Deliberately not implemented, this isn't a mailing list.
    throw Components.Exception(
      "copyMailList not relevant here",
      Cr.NS_ERROR_NOT_IMPLEMENTED
    );
  }
  getIntValue(name, defaultValue) {
    return this._prefBranch
      ? this._prefBranch.getIntPref(name, defaultValue)
      : defaultValue;
  }
  getBoolValue(name, defaultValue) {
    return this._prefBranch
      ? this._prefBranch.getBoolPref(name, defaultValue)
      : defaultValue;
  }
  getStringValue(name, defaultValue) {
    return this._prefBranch
      ? this._prefBranch.getStringPref(name, defaultValue)
      : defaultValue;
  }
  getLocalizedStringValue(name, defaultValue) {
    if (!this._prefBranch) {
      return defaultValue;
    }
    if (this._prefBranch.getPrefType(name) == Ci.nsIPrefBranch.PREF_INVALID) {
      return defaultValue;
    }
    try {
      return this._prefBranch.getComplexValue(name, Ci.nsIPrefLocalizedString)
        .data;
    } catch (e) {
      // getComplexValue doesn't work with autoconfig.
      return this._prefBranch.getStringPref(name);
    }
  }
  setIntValue(name, value) {
    this._prefBranch.setIntPref(name, value);
  }
  setBoolValue(name, value) {
    this._prefBranch.setBoolPref(name, value);
  }
  setStringValue(name, value) {
    this._prefBranch.setStringPref(name, value);
  }
  setLocalizedStringValue(name, value) {
    let valueLocal = Cc["@mozilla.org/pref-localizedstring;1"].createInstance(
      Ci.nsIPrefLocalizedString
    );
    valueLocal.data = value;
    this._prefBranch.setComplexValue(
      name,
      Ci.nsIPrefLocalizedString,
      valueLocal
    );
  }
}