/*
  Copyright (C) 2000-2004 SKYRIX Software AG

  This file is part of OpenGroupware.org.

  OGo is free software; you can redistribute it and/or modify it under
  the terms of the GNU Lesser General Public License as published by the
  Free Software Foundation; either version 2, or (at your option) any
  later version.

  OGo is distributed in the hope that it will be useful, but WITHOUT ANY
  WARRANTY; without even the implied warranty of MERCHANTABILITY or
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
  License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with OGo; see the file COPYING.  If not, write to the
  Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  02111-1307, USA.
*/
// $Id$

#ifndef __OGo_NGImap4_NGImap4Client_H__
#define __OGo_NGImap4_NGImap4Client_H__

#import <Foundation/NSObject.h>
#include <NGStreams/NGStreams.h>
#include <NGStreams/NGSocketProtocols.h>
#include <NGImap4/NGImap4Support.h>

/*
  NGImap4Client
  
  An IMAP4 client object.
*/

@class NSMutableArray, NSString, NSNumber, NSDictionary, NSArray, NSURL;
@class EOGlobalID, EOQualifier;
@class NGHashMap;
@class NGImap4ResponseParser, NGImap4Client, NGImap4ResponseNormalizer;

typedef enum {
  UnConnected_NGImap4State = 1,
  NonAuthenticated_NGImap4State,
  Authenticated_NGImap4State,
  Selected_NGImap4State,
} NGImap4State;

@interface NGImap4Client : NSObject
{
  id<NGActiveSocket>        socket;
  id<NGExtendedTextStream>  text;
  id<NGSocketAddress>       address;
  NGImap4ResponseParser     *parser;
  NGImap4ResponseNormalizer *normer;
  NSMutableArray            *responseReceiver;  

  BOOL     isLogin;
  unsigned tagId;

  NSString *delimiter;
  NSString *selectedFolder;
  NSString *login;
  NSString *password;

  BOOL debug;
  BOOL useSSL;

  NGImap4Context *context; /* not retained, used to store exceptions */
  EOGlobalID *serverGID;
}

+ (id)clientWithURL:(NSURL *)_url;
+ (id)clientWithAddress:(id<NGSocketAddress>)_address;
+ (id)clientWithHost:(id)_host;

- (id)initWithURL:(NSURL *)_url;
- (id)initWithHost:(id)_host;
- (id)initWithAddress:(id<NGSocketAddress>)_address;

/* equality */

- (BOOL)isEqualToClient:(NGImap4Client *)_obj;

/* accessors */

- (id<NGActiveSocket>)socket;
- (id<NGSocketAddress>)address;
- (NSString *)delimiter;
- (EOGlobalID *)serverGlobalID;

/* notifications */

- (void)registerForResponseNotification:(id<NGImap4ResponseReceiver>)_obj;
- (void)removeFromResponseNotification:(id<NGImap4ResponseReceiver>)_obj;

/* connection */

- (NSDictionary *)openConnection;
- (void)closeConnection;
- (NSNumber *)isConnected;
- (void)reconnect;

/* commands */

- (NSDictionary *)login:(NSString *)_login password:(NSString *)_passwd;
- (NSDictionary *)logout;
- (NSDictionary *)noop;
  
- (NSDictionary *)capability;
- (NSDictionary *)list:(NSString *)_folder pattern:(NSString *)_pattern;
- (NSDictionary *)lsub:(NSString *)_folder pattern:(NSString *)_pattern;
- (NSDictionary *)select:(NSString *)_folder;
- (NSDictionary *)status:(NSString *)_folder flags:(NSArray *)_flags;
- (NSDictionary *)rename:(NSString *)_folder to:(NSString *)_newName;
- (NSDictionary *)delete:(NSString *)_folder;
- (NSDictionary *)create:(NSString *)_name;
- (NSDictionary *)subscribe:(NSString *)_name;
- (NSDictionary *)unsubscribe:(NSString *)_name;
- (NSDictionary *)expunge;
  
- (NSDictionary *)sort:(NSArray *)_sortOrderings
  qualifier:(EOQualifier *)_qual;
- (NSDictionary *)fetchUids:(NSArray *)_uids parts:(NSArray *)_parts;
- (NSDictionary *)fetchUid:(unsigned)_uid parts:(NSArray *)_parts;
- (NSDictionary *)fetchFrom:(unsigned)_from to:(unsigned)_to
  parts:(NSArray *)_parts;
- (NSDictionary *)storeUid:(unsigned)_uid add:(NSNumber *)_add
  flags:(NSArray *)_flags;
- (NSDictionary *)storeFrom:(unsigned)_from to:(unsigned)_to
  add:(NSNumber *)_add flags:(NSArray *)_flags;
- (NSDictionary *)copyUid:(unsigned)_uid toFolder:(NSString *)_folder;
- (NSDictionary *)copyFrom:(unsigned)_from to:(unsigned)_to
  toFolder:(NSString *)_folder;
- (NSDictionary *)append:(NSData *)_message toFolder:(NSString *)_folder
  withFlags:(NSArray *)_flags;
- (NSDictionary *)threadBySubject:(BOOL)_bySubject
  charset:(NSString *)_charSet;
- (NSDictionary *)getQuotaRoot:(NSString *)_folder;

- (NSDictionary *)searchWithQualifier:(EOQualifier *)_qualifier;

- (void)setContext:(NGImap4Context *)_ctx;
- (NGImap4Context *)context;

@end

#endif /* __OGo_NGImap4_NGImap4Client_H__ */
