Re: RFC mailbox interface



Hi,
Here is my second attempt at the API.  It incorporates some of the 
suggestions made here as well as a mistake I made since I'm used to 
writing C++.  So, how's this one.

typedef struct _Message Message;
typedef struct _Folder Folder;
typedef struct _Server Server;

typedef struct _Flags {
	int READ    :1;
	int NEW     :1;
	int TRASH   :1;
	int DRAFT   :1;
	int FLAGGED :1;
} Flags;

//all feilds are read-only to clients
struct _Message {
	Folder *owner;
	GList *views;
	Flags flags;

	//these header fields are unfolded
	char to[],from[],subject[],date[];
	char msg_id[],references[],in_reply_to[];
	char cc[],bcc[],reply_to[];
	 
	gpointer data;
};

typedef struct _Stats {
	int New;
	int Draft;
	int Flagged;
	int Read;
	int Total;
} Stats;
	 
typedef struct _Folder_Funcs {
	void (*lock)(Folder*);
	void (*unlock)(Folder*);
	gboolean (*sync)(Folder*);
	//deletes all messages in folder
	gboolean (*empty)(Folder*);
	//only updates list if folder is open?
	Stats (*check)(Folder*);
	 
	//possibly creates Message list
	//required for most functions
	Stats (*open)(Folder*);
	//possibly free Message list
	void (*close)(Folder*);

	Message* (*getMessage)(Folder*, int msg);
	// -1 fail, 0 success w/ folder closed, >0 msg index w/ folder 
open
	int (*addMessage)(Folder*, char data[], Flags flags);
	int (*deleteMessage)(Folder*, Message *msg);
	int (*alterMessage)(Folder*, Message *msg, const char data[]);
	int (*setFlags)(Folder*, Message *msg, Flags flags);
	// return unfolded headers?
	GList (*getAllHeaders)(Folder*, Message *msg);
	char* (*getBody)(Folder*, Message *msg);
	char* (*getAll)(Folder*, Message *msg);
	//using copy-in allows for vfolders (ref copy)
	int (*copyMessage)(Folder*, Message *src);
	 
	//IMAP format
	GList (*findMessages)(Folder*, const char srch[]);
	GList (*getHeaders)(Folder*, Message *msg,const char hdrs[]);
	char* (*getBodyStructure)(Folder*, Message *msg);
	char* (*getBodyParts)(Folder*, Message *msg, const char 
parts[]);
} Folder_Funcs;

struct _Folder {
	Server *server;
	Folder_Funcs *funcs;
	gpointer data;
};

struct _Server {
	Folder* (*getFolder)(Server*, const char path[]);
	//should this return a Folder* for the new folder?
	int (*newFolder)(Server*, const char path[]);
	//return list of available Folder paths for getFolder
	GList (*scanFolders)(Server*, const char path[]);

	//remote server functions

	gboolean (*logon)(Server*, const char user[],	const char 
passwd[]);
	gboolean (*logoff)(Server*);
	//sets path and size for cache use size=0 for unlimited
	gboolean (*setcache)(Server*, const char path[], gsize size);

	gpointer data;
};

typedef struct _Type {
	const char name[];
	int type;
} Type;

//these allow for pluging in new mb type without recompile lib
//each plugin will need  const char* getName()

//please rename these
gboolean libattach();
void libdetach();

GSList* getTypes();
Server* getServer(int type, const char server[]);



-- 
K. Haley <halykd@yahoo.com>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]