/* 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/. */

#include "nsISupports.idl"
#include "calIItipItem.idl"
#include "nsIPropertyBag2.idl"
#include "nsIMsgSMIMEHeaderSink.idl"

interface nsIMailProgressListener;
interface nsIWebProgress;
interface nsIRequest;

/**
 * An interface that email-streaming channels can use to provide access to
 * parsed message headers, message attachment info, and other metadata.
 * The intended use is by QIing nsIChannel to nsIMailChannel.
 */
[scriptable, uuid(e4abdb58-54fa-4deb-8c43-714a69519b3a)]
interface nsIMailChannel : nsISupports {
  /**
   * Called by MIME emitters to add a header to this mail channel.
   * Do not call otherwise.
   */
  void addHeaderFromMIME(in AUTF8String name, in AUTF8String value);

  /**
   * Header names for this request, available at onStopRequest.
   * The number of header names is the same as the number of header values,
   * and they are in the same order.
   */
  readonly attribute Array<AUTF8String> headerNames;

  /**
   * Header values for this request, available at onStopRequest.
   */
  readonly attribute Array<AUTF8String> headerValues;

  /**
   * Called by MIME emitters to add attachment info to this mail channel.
   * Do not call otherwise.
   */
  void handleAttachmentFromMIME(in AUTF8String contentType,
                        in AUTF8String url,
                        in AUTF8String displayName,
                        in AUTF8String uri,
                        in boolean aNotDownloaded);

  /**
   * Called by MIME emitters to add attachment info to this mail channel.
   * Do not call otherwise.
   */
  void addAttachmentFieldFromMIME(in AUTF8String field, in AUTF8String value);

  /**
   * Attachments for this request, available at onStopRequest.
   */
  readonly attribute Array<nsIPropertyBag2> attachments;

  /**
   * The character set of the message, according to the MIME parser. Not the
   * character set of the channel, which should always be UTF-8.
   */
  attribute AUTF8String mailCharacterSet;

  /**
   * The method property of iMIP attachments, as determined by the MIME parser.
   * Not to be set after onStopRequest.
   */
  attribute AUTF8String imipMethod;

  /**
   * The actual iMIP invitation, as created by CalMIMEConverter.
   * Not to be set after onStopRequest.
   */
  attribute calIItipItem imipItem;

  /**
   * Set this in onStartRequest to receive security status notifications.
   */
  attribute nsIMsgSMIMEHeaderSink smimeHeaderSink;

  /**
   * A listener for progress events. This object must also implement
   * nsISupportsWeakReference.
   */
  attribute nsIMailProgressListener listener;
};

[scriptable, uuid(1286f969-1c20-422e-8247-233fe0d26ba5)]
interface nsIMailProgressListener : nsISupports {
  /**
   * Receive a notification from the parser that it has finished outputting
   * the headers to the channel.
   */
  void onHeadersComplete(in nsIMailChannel mailChannel);

  /**
   * Receive a notification from the parser that it has finished outputting
   * the message body to the channel.
   */
  void onBodyComplete(in nsIMailChannel mailChannel);

  /**
   * Receive a notification from the parser that it has finished outputting
   * the attachment information to the channel.
   */
  void onAttachmentsComplete(in nsIMailChannel mailChannel);
};
