/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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"
interface nsIArray;
interface nsIMsgWindow;
interface nsIUrlListener;
interface nsIMsgDatabase;
interface nsIMsgDBHdr;
interface nsIMsgFolder;
interface nsIMsgCopyServiceListener;

[ptr] native nsLocalFolderScanState(nsLocalFolderScanState);

%{C++
/* flags for markMsgsOnPop3Server */
#define POP3_NONE 0
#define POP3_DELETE 1
#define POP3_FETCH_BODY 2
#define POP3_FORCE_DEL 3

struct nsLocalFolderScanState;
%}

[scriptable, uuid(ebf7576c-e15f-4aba-b021-cc6e9266e90c)]
interface nsIMsgLocalMailFolder : nsISupports {
  /**
   * Set the default flags on the subfolders of this folder, such as
   * Drafts, Templates, etc.
   * @param flags bitwise OR matching the type of mailboxes you want to flag.
   *              This function will be smart and find the right names.
   *              E.g. nsMsgFolderFlags::Inbox | nsMsgFolderFlags::Drafts
   */
  void setFlagsOnDefaultMailboxes(in unsigned long flags);

  /* 
   * This will return null if the db is out of date
   */
  nsIMsgDatabase getDatabaseWOReparse();

  /*
   * This will kick off a url to reparse the db if it's out of date.
   * If aReparseUrlListener is null, folder will use itself as the listener
   */
  nsIMsgDatabase getDatabaseWithReparse(in nsIUrlListener aReparseUrlListener, in nsIMsgWindow aMsgWindow);
  void parseFolder(in nsIMsgWindow aMsgWindow, in nsIUrlListener listener);
  void copyFolderLocal(in nsIMsgFolder srcFolder, in boolean isMove, in nsIMsgWindow msgWindow, in nsIMsgCopyServiceListener listener );
  void copyAllSubFolders(in nsIMsgFolder srcFolder, in nsIMsgWindow msgWindow, in nsIMsgCopyServiceListener listener );
  void onCopyCompleted(in nsISupports aSrcSupport, in boolean aMoveCopySucceeded);
  attribute boolean checkForNewMessagesAfterParsing;
  void markMsgsOnPop3Server(in nsIArray aMessages, in int32_t aMark);

  /**
   * File size on disk has possibly changed - update and notify.
   */
  void refreshSizeOnDisk();

  /**
   * Creates a subfolder to the current folder with the passed in folder name.
   * @param aFolderName name of the folder to create.
   * @return newly created folder.
   */
  nsIMsgFolder createLocalSubfolder(in AString aFolderName);

  /**
   * Adds a message to the end of the folder, parsing it as it goes, and
   * applying filters, if applicable.
   * @param aMessage string containing the entire body of the message to add
   * @return the nsIMsgDBHdr of the added message
   */
  nsIMsgDBHdr addMessage(in string aMessage);

  /**
   * Add one or more messages to the end of the folder in a single batch. Each
   * batch requires an fsync() on the mailbox file so it is a good idea to
   * try and minimize the number of calls you make to this method or addMessage.
   *
   * Filters are applied, if applicable.
   *
   * @param aMessageCount The number of messages.
   * @param aMessages An array of pointers to strings containing entire message
   *                  bodies.
   * @return an array of nsIMsgDBHdr of the added messages
   */
  nsIArray addMessageBatch(in uint32_t aMessageCount,
                           [array, size_is(aMessageCount)] in string aMessages);

  /**
   * Functions for updating the UI while running DownloadMessagesForOffline:
   * delete the old message before adding its newly downloaded body, and
   * select the new message after it has replaced the old one
   */
  void deleteDownloadMsg(in nsIMsgDBHdr aMsgHdr, out boolean aDoSelect);
  void selectDownloadMsg();
  void notifyDelete();

  /**
   * Functions for grubbing through a folder to find the Uidl for a
   * given msgDBHdr.
   */
  [noscript] void getFolderScanState(in nsLocalFolderScanState aState);
  [noscript] void getUidlFromFolder(in nsLocalFolderScanState aState, in nsIMsgDBHdr aMsgHdr);


  /**
   * Shows warning if there is not enough space in the message store
   * for a message of the given size.
   */
  boolean warnIfLocalFileTooBig(in nsIMsgWindow aWindow,
                                [optional] in long long aSpaceRequested);

  /**
   * Update properties on a new header from an old header, for cases where
   * a partial message will be replaced with a full message.
   *
   * @param   aOldHdr  message header used as properties source
   * @param   aNewHdr  message header used as properties destination
   */
  void updateNewMsgHdr(in nsIMsgDBHdr aOldHdr, in nsIMsgDBHdr aNewHdr);
};
