Bug 1586167 - Change AddrBookCard.generateName function to match old behaviour. r=mkmelin
authorGeoff Lankow <geoff@darktrojan.net>
Fri, 04 Oct 2019 16:27:16 +1300
changeset 37070 59307bc1a4ad57b299aa4ef7351aea92946af289
parent 37069 913390299c9ee608970bc60df9afe12c55941bf9
child 37071 78c57b3a917c563211910812b202f1635017ec7a
push id395
push userclokep@gmail.com
push dateMon, 02 Dec 2019 19:38:57 +0000
reviewersmkmelin
bugs1586167
Bug 1586167 - Change AddrBookCard.generateName function to match old behaviour. r=mkmelin
mailnews/addrbook/jsaddrbook/AddrBookCard.jsm
--- a/mailnews/addrbook/jsaddrbook/AddrBookCard.jsm
+++ b/mailnews/addrbook/jsaddrbook/AddrBookCard.jsm
@@ -36,35 +36,46 @@ AddrBookCard.prototype = {
   classID: Components.ID("{1143991d-31cd-4ea6-9c97-c587d990d724}"),
 
   /* nsIAbItem */
 
   get uuid() {
     return MailServices.ab.generateUUID(this._directoryId, this._localId);
   },
   generateName(generateFormat, bundle) {
+    let result = "";
     let format;
     switch (generateFormat) {
       case Ci.nsIAbItem.GENERATE_DISPLAY_NAME:
-        return this.displayName;
+        result = this.displayName;
+        break;
       case Ci.nsIAbItem.GENERATE_LAST_FIRST_ORDER:
         format = bundle
           ? bundle.GetStringFromName("lastFirstFormat")
           : "%S, %S";
-        return format
+        result = format
           .replace("%S", this.lastName)
           .replace("%S", this.firstName);
+        break;
       case Ci.nsIAbItem.GENERATE_FIRST_LAST_ORDER:
         format = bundle ? bundle.GetStringFromName("firstLastFormat") : "%S %S";
-        return format
+        result = format
           .replace("%S", this.firstName)
           .replace("%S", this.lastName);
+        break;
     }
 
-    return "";
+    if (result == "") {
+      result = this.getProperty("Company", "");
+    }
+    if (result == "") {
+      result = this.primaryEmail.split("@", 1)[0];
+    }
+
+    return result;
   },
 
   /* nsIAbCard */
 
   get directoryId() {
     return this._directoryId;
   },
   set directoryId(value) {