#ifndef _GLOBALS_H_
#define _GLOBALS_H_
/*
 * asmail is the AfterStep mailbox monitor
 * Copyright (c) 2002 Albert Dorofeev <albert@tigr.net>
 * For the updates see http://www.tigr.net/
 *
 * This software is distributed under GPL. For details see LICENSE file.
 */

#include <pthread.h>

#define VERSION "1.0pre3"
#define RCFILE ".asmailrc"
/* Watch out! The MAX_INPUT_LENGTH must be a multiple of 64! */
#define MAX_INPUT_LENGTH 255

#define pthread_attr_default NULL

struct x11_set_struct {
	pthread_t thread;
	pthread_t main_x_thread;
	int argc;
	char **argv;
	int beep;
	int shape;
	char geometry[MAX_INPUT_LENGTH+1];
	char title[MAX_INPUT_LENGTH+1];
	char on_left[MAX_INPUT_LENGTH+1];
	char on_middle[MAX_INPUT_LENGTH+1];
	char on_right[MAX_INPUT_LENGTH+1];
	char on_new_mail[MAX_INPUT_LENGTH+1];
};

/* Mailbox flags */
#define FLAG_DEFAULT		0
#define FLAG_UNREAD_AS_NEW	1
#define FLAG_ARRIVED		2
/* Mailbox types */
#define MBOX_FILE	1
#define MBOX_DIR	2
#define MBOX_POP3	3
#define MBOX_IMAP	4
/* Mailbox status */
#define STAT_IDLE	0
#define STAT_RUN	1
#define STAT_FAIL	2
#define STAT_CONN	3
#define STAT_LOGIN	4
#define STAT_TIMEOUT	5
/* Mailbox new mail status */
#define MAIL_NONE	0
#define MAIL_OLD	1
#define MAIL_NEW	2
/* Allowed ways to authorize user */
#define AUTH_PLAIN	1
#define AUTH_MD5	2

struct mbox_struct {
	pthread_t thread;
	pthread_mutex_t mutex; /* used to protect data written by 2 threads */
	int type;
	int flags;
	char file[MAX_INPUT_LENGTH+1];
	char server[MAX_INPUT_LENGTH+1];
	char user[MAX_INPUT_LENGTH+1];
	char pass[MAX_INPUT_LENGTH+1];
	char mbox[MAX_INPUT_LENGTH+1];
	int auth;
	int port;
	int update;
	int status;
	int mail;
	int ctotal;
	int cnew;
	struct mbox_struct * next;
};

extern char config_file_name[MAX_INPUT_LENGTH+1];
extern int flag_allow_insecure;
extern struct x11_set_struct x11_set;
extern struct mbox_struct * mbox;

/*
 * This is used to signal to the X11 handling routines
 * that we need an update of the screen.
 */
void signal_xkick();
int sleep_xkick(); /* returns the number of times we were kicked to redraw */

/*
 * This is used to signal that the update of mailbox status occured
 */
extern pthread_mutex_t update_lock;
extern pthread_cond_t update_cv;
extern int update_count;

void signal_update();

/* Used to lock the MD5 calculation library */
extern pthread_mutex_t md5_lock;

/*
 * This is used to signal to all threads that
 * they need to verify the mailboxes right away.
 */
extern pthread_mutex_t check_lock;
extern pthread_cond_t check_cv;
extern int check_count;

void signal_check();
void sleep_check(const int secs);

#endif

