enum {TOUT_NONE,TOUT_OPEN,TOUT_SEND};
typedef struct ITEM {char *body; int nref; int body_len; char mid[BFSZ];} Zitem;

#define THMAX 4
typedef struct THOUT {
	int start;
	int chan;
	int nbusy;
	int state;
	int isbusy;
	Zitem *next[THMAX];
	Zitem *item;
	char to[BFSZ];
	char bind[BFSZ];
	char reason[BFSZ];
	char inbf[BFSZ];
	char *outbf; /* Output buffering */
	int outmax;
	int outlen;
	int thread_running;
	int finish;
	int nok;
	int nbad;
	int ndup;
	int ksent;
	int ntoread; /* Number of takethis responses to read back */
} Thout;


int tout_mutex_wait(void);
int tout_mutex_release(void);
int tout_open(Thout *th);
Zitem *tout_getref(Thout *th, String *item, char *groupnum, char *mid);
int thout_start_setup(int chan);
int tout_start(Thout *th);
int tout_main(void *arg);
int tout_read_open(Thout *th);
int tout_read_line(Thout *th, char *bf);
int tout_send_one(Thout *th);
Thout *tout_new(char *to, char *bind);
int tout_release(Zitem **item);
int tout_finish(Thout *th);
int tout_feed(int ff, char *msgid, char *groupnum, String *item);
