Bug 1390337 - Remove some unused functions in nsIMsgDBView and nsIMsgHeaderParser. r=jcranmer,jorgk
authoraceman <acelists@atlas.sk>
Fri, 23 Nov 2018 13:47:00 +0100
changeset 34064 9fe194930e8d79bba16afa23dce8b18fe0e550b1
parent 34063 b3f44f8462f9d0e89e3967ebe01aca33081ee749
child 34065 78daaa93369e8c57c78390b6a0e3d16c121bba7a
push id389
push userclokep@gmail.com
push dateMon, 18 Mar 2019 19:01:53 +0000
reviewersjcranmer, jorgk
bugs1390337
Bug 1390337 - Remove some unused functions in nsIMsgDBView and nsIMsgHeaderParser. r=jcranmer,jorgk
mail/base/content/mailWindowOverlay.js
mailnews/base/public/nsIMsgDBView.idl
mailnews/base/src/nsMsgDBView.cpp
mailnews/mime/public/nsIMsgHeaderParser.idl
mailnews/mime/src/mimeJSComponents.js
mailnews/mime/test/unit/test_nsIMsgHeaderParser2.js
suite/mailnews/mailWindowOverlay.js
--- a/mail/base/content/mailWindowOverlay.js
+++ b/mail/base/content/mailWindowOverlay.js
@@ -2937,17 +2937,17 @@ var gMessageNotificationBar = {
     // Return receipts can be RFC 3798 or not.
     let mdnHdr = aMimeHdr.extractHeader("Disposition-Notification-To", false) ||
                  aMimeHdr.extractHeader("Return-Receipt-To", false); // not
     let fromHdr = aMimeHdr.extractHeader("From", false);
 
     let mdnAddr = MailServices.headerParser.extractHeaderAddressMailboxes(mdnHdr);
     let fromAddr = MailServices.headerParser.extractHeaderAddressMailboxes(fromHdr);
 
-    let authorName = MailServices.headerParser.extractHeaderAddressName(
+    let authorName = MailServices.headerParser.extractFirstName(
                        aMsgHeader.mime2DecodedAuthor) || aMsgHeader.author;
 
     // If the return receipt doesn't go to the sender address, note that in the
     // notification.
     let mdnBarMsg = (mdnAddr != fromAddr) ?
       this.stringBundle.getFormattedString("mdnBarMessageAddressDiffers",
                                             [authorName, mdnAddr]) :
       this.stringBundle.getFormattedString("mdnBarMessageNormal", [authorName]);
--- a/mailnews/base/public/nsIMsgDBView.idl
+++ b/mailnews/base/public/nsIMsgDBView.idl
@@ -313,18 +313,16 @@ interface nsIMsgDBView : nsISupports
    *
    * @return an array containing the selected message headers.  You are free to
    *     mutate the array; it will not affect the underlying selection.
    */
   void getSelectedMsgHdrs([optional] out unsigned long count,
                           [retval, array, size_is(count)]
                           out nsIMsgDBHdr headers);
 
-  /* @deprecated */ nsIMutableArray getMsgHdrsForSelection();
-
   void getURIsForSelection(out unsigned long count, [retval, array, size_is(count)] out string uris);
   void getIndicesForSelection(out unsigned long count, [retval, array, size_is(count)] out nsMsgViewIndex indices);
 
   readonly attribute ACString URIForFirstSelectedMessage;
   readonly attribute nsIMsgDBHdr hdrForFirstSelectedMessage;
   void loadMessageByMsgKey(in nsMsgKey aMsgKey);
   void loadMessageByViewIndex(in nsMsgViewIndex aIndex);
   void loadMessageByUrl(in string aUrl);
--- a/mailnews/base/src/nsMsgDBView.cpp
+++ b/mailnews/base/src/nsMsgDBView.cpp
@@ -2769,32 +2769,16 @@ nsMsgDBView::GetSelectedMsgHdrs(uint32_t
   }
 
   *aLength = numMsgsSelected;
   *aResult = headers;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsMsgDBView::GetMsgHdrsForSelection(nsIMutableArray **aResult)
-{
-  nsMsgViewIndexArray selection;
-  GetSelectedIndices(selection);
-  uint32_t numIndices = selection.Length();
-
-  nsresult rv;
-  nsCOMPtr<nsIMutableArray> messages(do_CreateInstance(NS_ARRAY_CONTRACTID, &rv));
-  NS_ENSURE_SUCCESS(rv, rv);
-  rv = GetHeadersFromSelection(selection.Elements(), numIndices, messages);
-  NS_ENSURE_SUCCESS(rv, rv);
-  messages.forget(aResult);
-  return rv;
-}
-
-NS_IMETHODIMP
 nsMsgDBView::GetURIsForSelection(uint32_t *length,
                                  char ***uris)
 {
   nsresult rv = NS_OK;
 
   NS_ENSURE_ARG_POINTER(length);
   *length = 0;
 
--- a/mailnews/mime/public/nsIMsgHeaderParser.idl
+++ b/mailnews/mime/public/nsIMsgHeaderParser.idl
@@ -196,38 +196,17 @@ interface nsIMsgHeaderParser : nsISuppor
   /**
    * Given a string which contains a list of Header addresses, returns a
    * comma-separated list of just the `mailbox' portions.
    *
    * @param aLine          The header line to parse.
    * @return               A comma-separated list of just the mailbox parts
    *                       of the email-addresses.
    */
-  /* @deprecated */ ACString extractHeaderAddressMailboxes(in ACString aLine);
-
-  /**
-   * Given a string which contains a list of Header addresses, returns a
-   * comma-separated list of just the `user name' portions.  If any of
-   * the addresses doesn't have a name, then the mailbox is used instead.
-   *
-   * @param aLine          The header line to parse.
-   * @return               A comma-separated list of just the name parts
-   *                       of the addresses.
-   */
-  /* @deprecated */ AUTF8String extractHeaderAddressNames(in AUTF8String aLine);
-
-  /*
-   * Like extractHeaderAddressNames, but only returns the first name in the
-   * header if there is one. This function will return unquoted strings suitable
-   * for display.
-   *
-   * @param aLine          The header line to parse.
-   * @return               The first name found in the list.
-   */
-  /* @deprecated */ AUTF8String extractHeaderAddressName(in AUTF8String aLine);
+  ACString extractHeaderAddressMailboxes(in ACString aLine);
 
   /**
    * Given a name and email address, produce a string that is suitable for
    * emitting in a MIME header (after applying RFC 2047 encoding).
    *
    * @note This is a temporary method.
    */
   /* @deprecated */ AString makeMimeAddress(in AString aName, in AString aEmail);
--- a/mailnews/mime/src/mimeJSComponents.js
+++ b/mailnews/mime/src/mimeJSComponents.js
@@ -287,18 +287,18 @@ MimeAddressParser.prototype = {
     let emitter = new jsmime.headeremitter.makeStreamingEmitter(handler,
       options);
     emitter.addAddresses(addresses);
     emitter.finish(true);
     return handler.value.replace(/\r\n( |$)/g, '');
   },
 
   extractFirstName: function (aHeader) {
-    let address = this.parseDecodedHeader(aHeader, false)[0];
-    return address.name || address.email;
+    let addresses = this.parseDecodedHeader(aHeader, false);
+    return (addresses.length > 0) ? (addresses[0].name || addresses[0].email) : "";
   },
 
   removeDuplicateAddresses: function (aAddrs, aOtherAddrs) {
     // This is actually a rather complicated algorithm, especially if we want to
     // preserve group structure. Basically, we use a set to identify which
     // headers we have seen and therefore want to remove. To work in several
     // various forms of edge cases, we need to normalize the entries in that
     // structure.
@@ -411,27 +411,16 @@ MimeAddressParser.prototype = {
     aFullNames.value = fullNames;
     return allAddresses.length;
   },
 
   extractHeaderAddressMailboxes: function (aLine) {
     return this.parseDecodedHeader(aLine).map(addr => addr.email).join(", ");
   },
 
-  extractHeaderAddressNames: function (aLine) {
-    return this.parseDecodedHeader(aLine).map(addr => addr.name || addr.email)
-                                         .join(", ");
-  },
-
-  extractHeaderAddressName: function (aLine) {
-    let addrs = this.parseDecodedHeader(aLine).map(addr =>
-                 addr.name || addr.email);
-    return addrs.length == 0 ? "" : addrs[0];
-  },
-
   makeMimeAddress: function (aName, aEmail) {
     let object = this.makeMailboxObject(aName, aEmail);
     return this.makeMimeHeader([object]);
   },
 };
 
 function MimeConverter() {
 }
--- a/mailnews/mime/test/unit/test_nsIMsgHeaderParser2.js
+++ b/mailnews/mime/test/unit/test_nsIMsgHeaderParser2.js
@@ -1,24 +1,24 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /*
  * Test suite for nsIMsgHeaderParser functions:
  *   extractHeaderAddressMailboxes
- *   extractHeaderAddressNames
- *   extractHeaderAddressName
+ *   extractFirstName
+ *   parseDecodedHeader
  */
 
 ChromeUtils.import("resource:///modules/MailServices.jsm");
 
 function run_test() {
   // In this array, the sub arrays consist of the following elements:
-  // 0: input string
+  // 0: input string (a comma separated list of recipients)
   // 1: expected output from extractHeaderAddressMailboxes
-  // 2: expected output from extractHeaderAddressNames
-  // 3: expected output from extractHeaderAddressName
+  // 2: list of recipient names in the string
+  // 3: first recipient name in the string
   const checks =
   [
     ["abc@foo.invalid",
      "abc@foo.invalid",
      "abc@foo.invalid",
      "abc@foo.invalid" ],
     ["foo <ghj@foo.invalid>",
      "ghj@foo.invalid",
@@ -40,36 +40,37 @@ function run_test() {
     ["foo\u00D0 bar <foo@bar.invalid>, \u00F6foo <ghj@foo.invalid>",
      "foo@bar.invalid, ghj@foo.invalid",
      "foo\u00D0 bar, \u00F6foo",
      "foo\u00D0 bar" ],
     // More complicated examples drawn from RFC 2822
     ["\"Joe Q. Public\" <john.q.public@example.com>,Test <\"abc!x.yz\"@foo.invalid>, Test <test@[xyz!]>,\"Giant; \\\"Big\\\" Box\" <sysservices@example.net>",
      "john.q.public@example.com, \"abc!x.yz\"@foo.invalid, test@[xyz!], sysservices@example.net",
      "Joe Q. Public, Test, Test, Giant; \"Big\" Box",
-     // extractHeaderAddressName returns unquoted names, hence the difference.
+     // extractFirstName returns unquoted names, hence the difference.
      "Joe Q. Public" ],
     // Bug 549931
     ["Undisclosed recipients:;",
      "", // Mailboxes
      "", // Address Names
      ""] // Address Name
   ];
 
   // this used to cause memory read overruns
   let addresses = {}, names = {}, fullAddresses = {};
   MailServices.headerParser.parseHeadersWithArray("\" \"@a a;b", addresses, names, fullAddresses);
 
-
   // Test - empty strings
 
   Assert.equal(MailServices.headerParser.extractHeaderAddressMailboxes(""), "");
-  Assert.equal(MailServices.headerParser.extractHeaderAddressNames(""), "");
-  Assert.equal(MailServices.headerParser.extractHeaderAddressName(""), "");
+  Assert.equal(MailServices.headerParser.extractFirstName(""), "");
 
   // Test - extractHeaderAddressMailboxes
 
   for (let i = 0; i < checks.length; ++i) {
     Assert.equal(MailServices.headerParser.extractHeaderAddressMailboxes(checks[i][0]), checks[i][1]);
-    Assert.equal(MailServices.headerParser.extractHeaderAddressNames(checks[i][0]), checks[i][2]);
-    Assert.equal(MailServices.headerParser.extractHeaderAddressName(checks[i][0]), checks[i][3]);
+    let names = MailServices.headerParser.parseDecodedHeader(checks[i][0])
+                                         .map(addr => addr.name || addr.email)
+                                         .join(", ");
+    Assert.equal(names, checks[i][2]);
+    Assert.equal(MailServices.headerParser.extractFirstName(checks[i][0]), checks[i][3]);
   }
 }
--- a/suite/mailnews/mailWindowOverlay.js
+++ b/suite/mailnews/mailWindowOverlay.js
@@ -2612,17 +2612,17 @@ var gMessageNotificationBar =
 
     if (this.mMsgNotificationBar.getNotificationWithValue("remoteContent"))
       return;
 
     var headerParser = MailServices.headerParser;
     // update the allow remote content for sender string
     var mailbox = headerParser.extractHeaderAddressMailboxes(aMsgHdr.author);
     var emailAddress = mailbox || aMsgHdr.author;
-    var displayName = headerParser.extractHeaderAddressName(aMsgHdr.author);
+    var displayName = headerParser.extractFirstName(aMsgHdr.mime2DecodedAuthor);
     var brandName = this.mBrandBundle.getString("brandShortName");
     var remoteContentMsg = this.mStringBundle
                                .getFormattedString("remoteContentBarMessage",
                                                    [brandName]);
     var buttons = [{
       label: this.mStringBundle.getString("remoteContentPrefLabel"),
       accessKey: this.mStringBundle.getString("remoteContentPrefAccesskey"),
       popup: "remoteContentOptions"
@@ -2680,18 +2680,18 @@ var gMessageNotificationBar =
     var fromHdr = aMimeHdr.extractHeader("From", false);
 
     var mdnAddr = MailServices.headerParser
                               .extractHeaderAddressMailboxes(mdnHdr);
     var fromAddr = MailServices.headerParser
                                .extractHeaderAddressMailboxes(fromHdr);
 
     var authorName = MailServices.headerParser
-                                 .extractHeaderAddressName(
-                       aMsgHeader.mime2DecodedAuthor) || aMsgHeader.author;
+                                 .extractFirstName(aMsgHeader.mime2DecodedAuthor)
+                                 || aMsgHeader.author;
 
     var barMsg;
     // If the return receipt doesn't go to the sender address, note that in the
     // notification.
     if (mdnAddr != fromAddr)
       barMsg = this.mStringBundle.getFormattedString("mdnBarMessageAddressDiffers",
                                          [authorName, mdnAddr]);
     else