#ifndef POPLIB_HEADER
#define POPLIB_HEADER

#include "tcplib.h"
#include "defines.h"

struct pop_connection;
typedef struct pop_connection PopCon;

struct pop_connection {
	Chan *c;
	void (*cb)(void*,PopCon*);
	void *data;
	char result[BFSZ];
};

PopCon *pc_new();
void pc_free(PopCon **p);

void pc_set_cb(PopCon *p, void (*cb)(void*,PopCon*), void *data);

int pc_connect(PopCon *p, char *host, int port);
void pc_disconnect(PopCon *p);

int pc_command(PopCon *p, int read_response, char *format, ...);

int pc_user(PopCon *p, char *user);
int pc_pass(PopCon *p, char *pass);
int pc_quit(PopCon *p);
int pc_list(PopCon *p);
int pc_uidl(PopCon *p);
int pc_retr(PopCon *p, char *msg);

int pc_send_command(PopCon *p, char *bf, int x);
int pc_read_response(PopCon *p);
int pc_end(PopCon *p);
int pc_ok(PopCon *p);
int pc_err(PopCon *p);

int pc_read_data_direct(PopCon *p, char *mem, int bytes);
int pc_read_data(PopCon *p, int bytes, int(*xwrite)(void*,int,int,void*), void *xp);

#endif
