Bug 1562158 - Remove xpidl [array] use from msgIStructuredHeaders. r=mkmelin DONTBUILD
authorBen Campbell <benc@thunderbird.net>
Fri, 04 Oct 2019 11:59:29 +1300
changeset 37080 f47342bf3567fd2f36c92b63127a3f6032a30b8e
parent 37079 5fcde2aba579886c6c1598314ec65211023e7d85
child 37081 81233eef62edcad1e1f548e2165c33960070e3e2
push id395
push userclokep@gmail.com
push dateMon, 02 Dec 2019 19:38:57 +0000
reviewersmkmelin
bugs1562158
Bug 1562158 - Remove xpidl [array] use from msgIStructuredHeaders. r=mkmelin DONTBUILD
mailnews/compose/src/nsMsgCompFields.h
mailnews/compose/src/nsMsgCompUtils.cpp
mailnews/mime/public/msgIStructuredHeaders.idl
mailnews/mime/src/mimeJSComponents.js
mailnews/mime/test/unit/test_structured_headers.js
--- a/mailnews/compose/src/nsMsgCompFields.h
+++ b/mailnews/compose/src/nsMsgCompFields.h
@@ -32,21 +32,16 @@ class nsMsgCompFields : public nsIMsgCom
   nsMsgCompFields();
 
   /* this macro defines QueryInterface, AddRef and Release for this class */
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_FORWARD_MSGISTRUCTUREDHEADERS(mStructuredHeaders->)
   NS_FORWARD_MSGIWRITABLESTRUCTUREDHEADERS(mStructuredHeaders->)
   NS_DECL_NSIMSGCOMPFIELDS
 
-  // Allow the C++ utility methods for people who use a concrete class instead
-  // of the interfaces.
-  using msgIStructuredHeaders::GetAddressingHeader;
-  using msgIWritableStructuredHeaders::SetAddressingHeader;
-
   typedef enum MsgHeaderID {
     MSG_FROM_HEADER_ID = 0,
     MSG_REPLY_TO_HEADER_ID,
     MSG_TO_HEADER_ID,
     MSG_CC_HEADER_ID,
     MSG_BCC_HEADER_ID,
     MSG_FCC_HEADER_ID,
     MSG_FCC2_HEADER_ID,
--- a/mailnews/compose/src/nsMsgCompUtils.cpp
+++ b/mailnews/compose/src/nsMsgCompUtils.cpp
@@ -191,18 +191,18 @@ nsresult mime_generate_headers(nsIMsgCom
                  deliver_mode == nsIMsgSend::nsMsgQueueForLater ||
                  deliver_mode == nsIMsgSend::nsMsgDeliverBackground;
 
   bool hasDisclosedRecipient = false;
 
   MOZ_ASSERT(fields, "null fields");
   NS_ENSURE_ARG_POINTER(fields);
 
-  nsCOMArray<msgIAddressObject> from;
-  fields->GetAddressingHeader("From", from, true);
+  nsTArray<RefPtr<msgIAddressObject>> from;
+  fields->GetAddressingHeader("From", true, from);
 
   // Copy all headers from the original compose field.
   rv = finalHeaders->AddAllHeaders(fields);
   NS_ENSURE_SUCCESS(rv, rv);
 
   bool hasMessageId = false;
   if (NS_SUCCEEDED(fields->HasHeader("Message-ID", &hasMessageId)) &&
       hasMessageId) {
@@ -329,20 +329,20 @@ nsresult mime_generate_headers(nsIMsgCom
       finalHeaders->SetRawHeader(HEADER_X_MOZILLA_NEWSHOST, newshostHeaderVal,
                                  nullptr);
     }
 
     // Newsgroups are a recipient...
     hasDisclosedRecipient = true;
   }
 
-  nsCOMArray<msgIAddressObject> recipients;
-  finalHeaders->GetAddressingHeader("To", recipients);
+  nsTArray<RefPtr<msgIAddressObject>> recipients;
+  finalHeaders->GetAddressingHeader("To", false, recipients);
   hasDisclosedRecipient |= !recipients.IsEmpty();
-  finalHeaders->GetAddressingHeader("Cc", recipients);
+  finalHeaders->GetAddressingHeader("Cc", false, recipients);
   hasDisclosedRecipient |= !recipients.IsEmpty();
 
   // If we don't have disclosed recipient (only Bcc), address the message to
   // undisclosed-recipients to prevent problem with some servers
 
   // If we are saving the message as a draft, don't bother inserting the
   // undisclosed recipients field. We'll take care of that when we really send
   // the message.
--- a/mailnews/mime/public/msgIStructuredHeaders.idl
+++ b/mailnews/mime/public/msgIStructuredHeaders.idl
@@ -71,19 +71,18 @@ interface msgIStructuredHeaders : nsISup
    * @param aHeaderName     The name of the header to retrieve.
    * @param aPreserveGroups If false (the default), then the result is a flat
    *                        list of addresses, with all group annotations
    *                        removed.
    *                        If true, then some address objects may represent
    *                        groups in the header, preserving the original header
    *                        structure.
    */
-  void getAddressingHeader(in string aHeaderName,
-    [optional] in boolean aPreserveGroups, [optional] out unsigned long count,
-    [array, size_is(count), retval] out msgIAddressObject addresses);
+  Array<msgIAddressObject> getAddressingHeader(in string aHeaderName,
+    [optional] in boolean aPreserveGroups);
 
   /**
    * Retrieve a raw version of the header value as would be represented in MIME.
    * This form does not include the header name and colon, trailing whitespace,
    * nor embedded CRLF pairs in the case of very long header names.
    *
    * @param aHeaderName     The name of the header to retrieve.
    */
@@ -105,38 +104,16 @@ interface msgIStructuredHeaders : nsISup
    * is not included in this representation.
    *
    * This accessor is provided mainly for the benefit of C++ consumers of this
    * interface, since the JSMime headeremitter functionality allows more
    * fine-grained customization of the results.
    */
    AUTF8String buildMimeText();
 
-%{C++
-  /**
-   * A special variant of getAddressingHeader that is specialized better for C++
-   * users of this API.
-   */
-  nsresult GetAddressingHeader(const char *aPropertyName,
-                               nsCOMArray<msgIAddressObject> &addrs,
-                               bool aPreserveGroups = false)
-  {
-    msgIAddressObject **addrPtr;
-    uint32_t length;
-    nsresult rv = GetAddressingHeader(aPropertyName, aPreserveGroups, &length,
-      &addrPtr);
-    NS_ENSURE_SUCCESS(rv, rv);
-    // addrs.Adopt(addrPtr, length);
-    addrs.Clear();
-    addrs.AppendElements(addrPtr, length);
-    free(addrPtr);
-    return NS_OK;
-  }
-%}
-
 };
 
 /**
  * An interface that enhances msgIStructuredHeaders by allowing the values of
  * headers to be modified.
  */
 [scriptable, uuid(5dcbbef6-2356-45d8-86d7-b3e73f9c9a0c)]
 interface msgIWritableStructuredHeaders : msgIStructuredHeaders {
@@ -173,40 +150,27 @@ interface msgIWritableStructuredHeaders 
    * @param aValue          The value to store.
    */
   void setUnstructuredHeader(in string aHeaderName, in AString aValue);
 
   /**
    * Set the value of the header as if it were an addressing header, such as the
    * From or To headers.
    *
-   * @param aHeaderName     The name of the header to store.
+   * @param aHeaderName     The name of the header to set.
+   * @param aAddresses      The addresses to store.
    */
   void setAddressingHeader(in string aHeaderName,
-    [array, size_is(aCount)] in msgIAddressObject aAddresses,
-    in unsigned long aCount);
+    in Array<msgIAddressObject> aAddresses);
 
   /**
    * Store the value of the header using a raw version as would be represented
    * in MIME. So as to handle 8-bit headers properly, the charset needs to be
    * specified, although it may be null.
    *
    * @param aHeaderName     The name of the header to store.
    * @param aValue          The raw MIME header value to store.
    * @param aCharset        The expected charset of aValue.
    */
   void setRawHeader(in string aHeaderName, in ACString aValue,
                     in string aCharset);
 
-%{C++
-  /**
-   * A special variant of setAddressingHeader that is specialized better for C++
-   * users of this API.
-   */
-  nsresult SetAddressingHeader(const char *aPropertyName,
-                               const nsCOMArray<msgIAddressObject> &addrs)
-  {
-    return SetAddressingHeader(aPropertyName,
-      const_cast<nsCOMArray<msgIAddressObject>&>(addrs).Elements(),
-      addrs.Length());
-  }
-%}
 };
--- a/mailnews/mime/src/mimeJSComponents.js
+++ b/mailnews/mime/src/mimeJSComponents.js
@@ -86,24 +86,24 @@ MimeStructuredHeaders.prototype = {
   getUnstructuredHeader(aHeaderName) {
     let result = this.getHeader(aHeaderName);
     if (result === undefined || typeof result == "string") {
       return result;
     }
     throw Cr.NS_ERROR_ILLEGAL_VALUE;
   },
 
-  getAddressingHeader(aHeaderName, aPreserveGroups, count) {
+  getAddressingHeader(aHeaderName, aPreserveGroups) {
     let addrs = this.getHeader(aHeaderName);
     if (addrs === undefined) {
       addrs = [];
     } else if (!Array.isArray(addrs)) {
       throw Cr.NS_ERROR_ILLEGAL_VALUE;
     }
-    return fixArray(addrs, aPreserveGroups, count);
+    return fixArray(addrs, aPreserveGroups);
   },
 
   getRawHeader(aHeaderName) {
     let result = this.getHeader(aHeaderName);
     if (result === undefined) {
       return result;
     }
 
@@ -199,17 +199,17 @@ MimeWritableStructuredHeaders.prototype 
       this.setHeader(header, aHeaders.getHeader(header));
     }
   },
 
   setUnstructuredHeader(aHeaderName, aValue) {
     this.setHeader(aHeaderName, aValue);
   },
 
-  setAddressingHeader(aHeaderName, aAddresses, aCount) {
+  setAddressingHeader(aHeaderName, aAddresses) {
     this.setHeader(aHeaderName, fixXpconnectAddresses(aAddresses));
   },
 
   setRawHeader(aHeaderName, aValue, aCharset) {
     aValue = jsmime.headerparser.convert8BitHeader(aValue, aCharset);
     try {
       this.setHeader(
         aHeaderName,
--- a/mailnews/mime/test/unit/test_structured_headers.js
+++ b/mailnews/mime/test/unit/test_structured_headers.js
@@ -37,21 +37,19 @@ add_task(async function check_addressing
   Assert.ok(Array.isArray(full[0].group));
   Assert.equal(headers.getRawHeader("To"), "undisclosed-recipients: ;");
 
   headers.setHeader("To", [{ name: "\u00D3", email: "test@foo.invalid" }]);
   Assert.equal(
     headers.getRawHeader("To"),
     "=?UTF-8?B?w5M=?= <test@foo.invalid>"
   );
-  headers.setAddressingHeader(
-    "To",
-    [{ name: "Comma, Name", email: "test@foo.invalid" }],
-    1
-  );
+  headers.setAddressingHeader("To", [
+    { name: "Comma, Name", email: "test@foo.invalid" },
+  ]);
   Assert.equal(headers.getRawHeader("To"), '"Comma, Name" <test@foo.invalid>');
 });
 
 add_task(async function check_custom_header() {
   // Load an extension for our custom header.
   let url = Services.io.newFileURI(do_get_file("custom_header.js")).spec;
   let promise = new Promise((resolve, reject) => {
     function observer(subject, topic, data) {