/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Netscape 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/NPL/
 *
 * 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 
 * Netscape Communications Corporation.
 * Portions created by the Initial Developer are Copyright (C) 2000
 * 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 NPL, 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 NPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

#include "nsISupports.idl"

interface nsIImapMailFolderSink;
interface nsIImapMessageSink;
interface nsIImapExtensionSink;
interface nsIImapMiscellaneousSink;
interface nsIImapServerSink;
interface nsIImapMockChannel;
interface nsIFileSpec;
interface nsIMsgFolder;

typedef long nsImapAction;
typedef long nsImapState;

typedef unsigned short imapMessageFlagsType;

typedef long nsImapContentModifiedType;

[scriptable, uuid(2e91901e-ff6c-11d3-b9fa-00108335942a)]
interface nsImapContentModifiedTypes
{
	const long IMAP_CONTENT_NOT_MODIFIED = 0;
	const long IMAP_CONTENT_MODIFIED_VIEW_INLINE = 1;
	const long IMAP_CONTENT_MODIFIED_VIEW_AS_LINKS = 2;
	const long IMAP_CONTENT_FORCE_CONTENT_NOT_MODIFIED = 3;
} ;

[scriptable, uuid(AEAA246D-F9E2-11d3-98BA-001083010E9B)]
interface nsIImapUrl : nsISupports
{
	// Initialization method used to initialize the url...
  void Initialize();
  void initializeURIforMockChannel();

	/////////////////////////////////////////////////////////////////////////////// 
	// Getters and Setters for the imap specific event sinks to bind to to your url
	///////////////////////////////////////////////////////////////////////////////
  attribute nsIImapMailFolderSink imapMailFolderSink;
  attribute nsIImapMessageSink imapMessageSink;
  [noscript] attribute nsIImapExtensionSink imapExtensionSink;
  [noscript] attribute nsIImapMiscellaneousSink imapMiscellaneousSink;
  attribute nsIImapServerSink imapServerSink;
	/////////////////////////////////////////////////////////////////////////////// 
	// Getters and Setters for the imap url state
	///////////////////////////////////////////////////////////////////////////////
  attribute nsImapAction imapAction; 
  readonly attribute nsImapState requiredImapState;
  readonly attribute string imapPartToFetch;
  readonly attribute string customAttributeToFetch;
  attribute string customAttributeResult;
  readonly attribute string command;
  attribute string customCommandResult;
  readonly attribute string customAddFlags;
  readonly attribute string customSubtractFlags;
  void allocateCanonicalPath(in string aServerPath, in char aOnlineDelimiter, out string aAllocatedPath);
  void allocateServerPath(in string aCanonicalPath, in char aOnlineDelimiter, out string aAllocatedPath);
  string createServerSourceFolderPathString();
  string createCanonicalSourceFolderPathString();
  string createServerDestinationFolderPathString();
  
  string addOnlineDirectoryIfNecessary(in string onlineMailboxName);
  void createSearchCriteriaString (out string aResult);
  void createListOfMessageIdsString (out string aResult);
  
  boolean messageIdsAreUids();
  readonly attribute imapMessageFlagsType msgFlags; // kAddMsgFlags or kSubtractMsgFlags only
  readonly attribute long childDiscoveryDepth;

  attribute char onlineSubDirSeparator;
  attribute boolean allowContentChange;
  attribute boolean mimePartSelectorDetected;
  attribute nsImapContentModifiedType contentModified;
  attribute boolean fetchPartsOnDemand;	// set to true if we're fetching a msg for display and want to not download parts
  attribute boolean msgLoadingFromCache; // true if this msg load is coming from a cache, so we can know to mark it read
  attribute boolean externalLinkUrl; // true if we ran this url because the user clicked on a link.
  attribute nsISupports copyState;
  attribute nsIFileSpec msgFileSpec;
  attribute nsIImapMockChannel mockChannel;

  void addChannelToLoadGroup();
  void removeChannel(in nsresult aStatus);
  
  ///////////////////////////////////////////////////////////////////////////////
  // Enumerated types specific to imap urls...
  ///////////////////////////////////////////////////////////////////////////////

  // the following are nsImapState enums.
  // we have a basic set of imap url actions. These actions are nsImapActions.
  // Certain actions require us to be in the authenticated state and others require us to
  // be in the selected state. nsImapState is used to store the state the url needs to
  // be in. You'll later see us refer to the imap url state in the imap protocol when we
  // are processing the current url. Don't confuse nsImapState with the generic url state
  // used to keep track of whether the url is running or not...
  const long nsImapAuthenticatedState = 0;
  const long nsImapSelectedState = 1;

  const long nsImapActionSendText = 0;      // a state used for testing purposes to send raw url text straight to the server....
	// nsImapAuthenticatedStateUrl urls
	// since the following url actions require us to be in the authenticated
	// state, the high bit is left blank....
  const long nsImapTest	= 0x00000001;
  const long nsImapCreateFolder	= 0x00000005;
  const long nsImapDeleteFolder	= 0x00000006;
  const long nsImapRenameFolder	= 0x00000007;
  const long nsImapMoveFolderHierarchy = 0x00000008;
  const long nsImapLsubFolders	= 0x00000009;
  const long nsImapGetMailAccountUrl = 0x0000000A;
  const long nsImapDiscoverChildrenUrl = 0x0000000B;
  const long nsImapDiscoverLevelChildrenUrl	= 0x0000000C;
  const long nsImapDiscoverAllBoxesUrl = 0x0000000D;
  const long nsImapDiscoverAllAndSubscribedBoxesUrl	= 0x0000000E;
  const long nsImapAppendMsgFromFile = 0x0000000F;
  const long nsImapSubscribe = 0x00000010;
  const long nsImapUnsubscribe = 0x00000011;
  const long nsImapRefreshACL	= 0x00000012;
  const long nsImapRefreshAllACLs	= 0x00000013;
  const long nsImapListFolder	= 0x00000014;
  const long nsImapUpgradeToSubscription = 0x00000015;
  const long nsImapFolderStatus	= 0x00000016;
  const long nsImapRefreshFolderUrls = 0x00000017;
  const long nsImapEnsureExistsFolder = 0x00000018;
  const long nsImapOfflineToOnlineCopy = 0x00000019;
  const long nsImapOfflineToOnlineMove = 0x0000001A;
  // it's okay to add more imap actions that require us to 
  // be in the authenticated state here without renumbering
  // the imap selected state url actions. just make sure you don't
  // set the high bit...
    
  // nsImapSelectedState urls. Note, the high bit is always set for
  // imap actions which require us to be in the selected state
  const long nsImapSelectFolder	= 0x10000002;
  const long nsImapLiteSelectFolder = 0x10000003;
  const long nsImapExpungeFolder = 0x10000004;
  const long nsImapMsgFetch	= 0x10000018;
  const long nsImapMsgHeader = 0x10000019;
  const long nsImapSearch	= 0x1000001A;
  const long nsImapDeleteMsg = 0x1000001B;
  const long nsImapDeleteAllMsgs = 0x1000001C;
  const long nsImapAddMsgFlags = 0x1000001D;
  const long nsImapSubtractMsgFlags	= 0x1000001E;
  const long nsImapSetMsgFlags = 0x1000001F;
  const long nsImapOnlineCopy	= 0x10000020;
  const long nsImapOnlineMove	= 0x10000021;
  const long nsImapOnlineToOfflineCopy = 0x10000022;
  const long nsImapOnlineToOfflineMove = 0x10000023;
  const long nsImapBiff	= 0x10000026;
  const long nsImapSelectNoopFolder	= 0x10000027;
  const long nsImapAppendDraftFromFile = 0x10000028;
  const long nsImapUidExpunge = 0x10000029;
  const long nsImapSaveMessageToDisk = 0x10000030;
  const long nsImapOpenMimePart = 0x10000031;
  const long nsImapMsgDownloadForOffline	= 0x10000032;
  const long nsImapDeleteFolderAndMsgs = 0x10000033;
  const long nsImapUserDefinedMsgCommand = 0x10000034;
  const long nsImapUserDefinedFetchAttribute = 0x10000035;
  const long nsImapMsgFetchPeek = 0x10000036;
  const long nsImapMsgStoreCustomKeywords = 0x10000037;
};

%{C++
#define IMAP_PORT 143
#define SECURE_IMAP_PORT 993
%}
