/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is mozilla.org code
 *
 * The Initial Developer of the Original Code is
 * Kent James <kent@caspia.com>.
 * Portions created by the Initial Developer are Copyright (C) 2008
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

#include "nsMsgFilterCore.idl"

/**
 * describes a custom action added to a message filter
 */
[scriptable,uuid(EDD6E135-6790-475e-9547-3C1408CF2F07)]
interface nsIMsgFilterCustomAction : nsISupports
{
  /* globally unique string to identify this filter action.
   * recommended form: ExtensionName@example.com#ActionName
   */
  readonly attribute ACString id;

  /* action name to display in action list. This should be localized. */
  readonly attribute AString name;

  /**
   * Is this custom action valid for a particular filter type? 
   *
   * @param type    the filter type
   * @param scope   the search scope
   *
   * @return        true if valid
   */
  boolean isValidForType(in nsMsgFilterTypeType type, in nsMsgSearchScopeValue scope);

  /**
   * After the user inputs a particular action value for the action, determine
   * if that value is valid.
   *
   * @param actionValue          The value entered.
   * @param actionFolder         Folder in the filter list
   * @param filterType           Filter Type (Manual, OfflineMail, etc.)
   *
   * @return errorMessage        A localized message to display if invalid
   *                             Set to null if the actionValue is valid
   */
  AUTF8String validateActionValue(in AUTF8String actionValue,
                                  in nsIMsgFolder actionFolder,
                                  in nsMsgFilterTypeType filterType);

  /* allow duplicate actions in the same filter list? Default No. */
  attribute boolean allowDuplicates;

  /*
   * The custom action itself
   *
   * Generally for the apply method, folder-based methods give correct
   * results and are preferred if available. Otherwise, be careful
   * that the action does correct notifications to maintain counts, and correct
   * manipulations of both IMAP and local non-database storage of message
   * metadata.
   */

  /**
   * Apply the custom action to an array of messages
   *
   * @param msgHdrs      array of nsIMsgDBHdr objects of messages
   * @param actionValue  user-set value to use in the action
   * @param copyListener calling method (filterType Manual only)
   * @param filterType   type of filter being applied
   * @param msgWindow    message window
   */

  void apply(in nsIArray msgHdrs /* nsIMsgDBHdr array */,
             in AUTF8String actionValue,
             in nsIMsgCopyServiceListener copyListener,
             in nsMsgFilterTypeType filterType,
             in nsIMsgWindow msgWindow);

  /* does this action start an async action? If so, a copy listener must
   * be used to continue filter processing after the action. This only
   * applies to after-the-fact (manual) filters. Call OnStopCopy when done
   * using the copyListener to continue.
   */
  readonly attribute boolean isAsync;
};


