/* structures.h */



/* Section I.  Menu definitions and Button State values. */


typedef unsigned long ButtonState;


/* 
 * This structure was designed for much more general use than is currently
 * implemented. The label and mnemonic remain unused to allow over-ride by
 * Xdefaults. These, or the widget in association with the callback 
 * function and callback data allow "on-the-fly" changes of the entire
 * button configuration.
 */

typedef struct _menu_structure_ {
  char                       *label;              /* label. Unused.        */
  char                       *name;               /* resource name.        */
  char                       mnemonic;            /* Mnemonic key. Unused. */
  void                       (*func)();           /* Callback function or  */
  struct _menu_structure_    *sub_menu;           /* recursive menu with   */
  int                        size;                /* known size.           */
  caddr_t                    data;                /* Callback data. Unused.*/
  Tool                     widget;                /* The button itself.    */
  unsigned long              statemap;            /* sensitivity flags.    */
} Menu;


typedef struct _BUTTON_LIST_ {
  Tool w;
  ButtonState state;
  struct _BUTTON_LIST_ * next;
} ButtonList;


/* 
 * Global menu button states. A '1' bit indicates the button will
 * be dimmed out (insensitive) if the state to be matched against
 * (i.e. the current conditions) also have this bit set.
 * For instance, to have a button dimmed on "No Selection", we
 * create the button with the BTN_NOSELECTION mask. When we check
 * selection state elsewhere in the program, we set this bit if
 * nothing is selected, and then call check_buttons() with that value.
 * The definition of "current conditions" varies by window; so not all
 * states make sense (or are checked) under certain window contexts.
 */

#define BTN_ON          ((unsigned long) 0 )       /* always on         */
#define BTN_INSENSITIVE ((unsigned long) 1 << 0 )  /* always disabled   */
#define BTN_NOSELECTION ((unsigned long) 1 << 1 )  /* no items selected */
#define BTN_SELECTION   ((unsigned long) 1 << 2 )  /* item(s) selected  */
#define BTN_NOPREV      ((unsigned long) 1 << 3 )  /* no prev window    */
#define BTN_NONEXT      ((unsigned long) 1 << 4 )  /* no next window    */
#define BTN_ISNEWS      ((unsigned long) 1 << 5 )  /* a newsgroup       */
#define BTN_ISMAIL      ((unsigned long) 1 << 6 )  /* a mailbox         */
#define BTN_NOKEYWORDS        ((unsigned long) 1 << 7)
#define BTN_NOATTACH          ((unsigned long) 1 << 8)
#define BTN_NOATTACHSELECT    ((unsigned long) 1 << 9)
#define BTN_NOSIGFILE         ((unsigned long) 1 << 10)
#define BTN_NOPGP             ((unsigned long) 1 << 11)
#define BTN_SHORT_HEADER      ((unsigned long) 1 << 12)
#define BTN_LONG_HEADER       ((unsigned long) 1 << 13)
#define BTN_SHOW_ENTIRE       ((unsigned long) 1 << 14)
#define BTN_SHOW_CODED        ((unsigned long) 1 << 15)
#define BTN_SHOW_NORMAL       ((unsigned long) 1 << 16)
#define BTN_ISALL             ((unsigned long) 1 << 17)
#define BTN_NOMAILBOXESOPEN      ((unsigned long) 1 << 18) 
#define BTN_NOMAINOPEN           ((unsigned long) 1 << 19
#define BTN_NOCOMPOSEOPEN        ((unsigned long) 1 << 20)
#define BTN_NOREADOPEN           ((unsigned long) 1 << 21)
#define BTN_NOHIDEDOT            ((unsigned long) 1 << 22)
#define BTN_HIDEDOT              ((unsigned long) 1 << 23)
#define BTN_MAILBOX_NOEDIT       ((unsigned long) 1 << 24)
#define BTN_MAILBOX_DONEWS       ((unsigned long) 1 << 25)
#define BTN_MAILBOX_DOMAIL       ((unsigned long) 1 << 26)
#define BTN_OLD_SERVER           ((unsigned long) 1 << 27)




/* Section II.   Other program structures and data types. */

typedef struct _TAG_PAIR_ {
  char *tag;
  char *value;
} TagPair;


typedef struct _ML_FLAG_ {
  char *name;                /* What we call this flag.            */
  char *localized;           /* Possibly translated into Swahili.  */
  char *resource;            /* The Xresource to find the Swahili. */
  char *protocol;            /* What IMAP calls this flag.         */
  Boolean settable;          /* Can we change the value?           */
} MLFlag;


/* Quick representations. When we don't need to translate */

typedef enum _REPRESENTATION_TYPE_ {
  REP_ASCENDING     = 0,
  REP_DESCENDING    = 1,
  REP_SORT_SENDER   = 2,
  REP_SORT_SUBJECT  = 3,
  REP_SORT_THREAD   = 4,
  REP_SORT_SIZE     = 5

} Representation_Type;

/* When we do... (look in view.c for the global structure and translators) */

typedef struct _ML_REPRESENTATION_ {
  char *name;               /* What we call this sort order.                */
  char *localized;          /* What Hunder Groelstag calls this sort order. */
  char *resource;           /* The Xresource M. Groelstag uses to change it.*/
} MLRepresentation;



/*  Not yet used. */
typedef struct _ML_CONFIRMATION_STRUCT_ {
  Tool ConfirmW;
  XmString dialogTitle;
  XmString cancelLabelString;
  XmString okLabelString;
  XmString helpLabelString;
  XmString messageString;
  unsigned char defaultButtonType;
  Pixmap symbolPixmap;
  void *calldata;
  void (*okCB)();
  void (*cancelCB)();
  void (*helpCB)();

} MLConfirmation;



/* 
 * The local user credentials from the passwd database and
 * also the local hostname. This is loaded at the start of 
 * the program, and remains in memory until program exit.
 */

typedef struct _LOCAL_AUTH_ {
  char *hostname;
  char *username;
  char *fullname;
  char *homedir;
  char *shell;

} Local_Auth;


/* 
 * This is a structure for any remote authorization, returned by
 * the "login()" function. We can link these together to avoid
 * requesting a login more than once for a particular service.
 * The widgets will be invalid once the information has been entered.
 */

typedef struct _REMOTE_AUTH_ {
  
  struct _SERVER_CONFIG_ *config;
  char *hostname;
  char *authtype;
  char *username;
  char *password;
  char *workspace;      /* Password scrambling scratchpad */
  int done;
  Tool shell;
  Tool name;
  Tool pass;
  XtIntervalId timer;   /* We use this timer to keep the window visible. */

  struct _REMOTE_AUTH_ * next;

} Remote_Auth;


/* No longer used. */
typedef struct _KEYWORD_WIN_ {
  Tool shell;
  Tool list;
  int done;
  char *keyword;
} Keyword_Win;




/* General purpose text window for help and showing text attachments. */

typedef struct _GENTEXT_ {
  Tool shell;
  Tool text;
  Tool scroll;
  unsigned char *contents;
  struct _GENTEXT_ *next;
  struct _GENTEXT_ *prev;
} Gentext;


/*
 * Structure for holding loaded files, which are perhaps binary.
 */

typedef struct _BINARY_BUFFER_ {

  unsigned char *data;
  unsigned long length;

} Binary_Buffer;


/*
 * Linked list of mailbox names returned by server.
 */

typedef struct _MAILBOX_LIST_ {

  char *name;
  char delimiter;
  long attribute;
  unsigned long nmsgs;
  unsigned long recent;
  unsigned long unseen;
  unsigned long validity;
  unsigned long uidnext;

  struct _MAILBOX_LIST_ * next;
  struct _MAILBOX_LIST_ * prev;

} Mailbox_List;



/* 
 * Used to keep the mailbox lists for every server they have been
 * requested from. It is not necessary to open a mailbox on the
 * server. This willl soon be merged into the new Server_Config
 * database.
 */

typedef struct _SERVER_LIST_ {

  char *name;
  int type;

  Boolean active;
  Boolean everything;
  char *last_pattern;
  Mailbox_List *mailbox_list;
  Mailbox_List *mailbox_all_list;

  struct _SERVER_LIST_ *next;
  struct _SERVER_LIST_ *prev;

} Server_List;



/* A simple linked list. */

typedef struct _STRING_LIST_ {

  char *string;
  struct _STRING_LIST_ *next;

} String_List;


/* Lots of work left to do on this structure. */

#define SVC_MAIL         "mail"
#define SVC_NEWS         "news"
#define SVC_FILE         "file"
#define SVC_XFER         "xfer"

#define CONNEXION_AUTO        0
#define CONNEXION_AUTO_STR    "auto"
#define CONNEXION_IMAP        143
#define CONNEXION_IMAP_STR    "imap"
#define CONNEXION_NEWS        0
#define CONNEXION_NEWS_STR    "auto"
#define CONNEXION_NNTP        119
#define CONNEXION_NNTP_STR    "nntp"

typedef enum _SERVICE_TYPE_ {

  SERVICE_NONE         = 0,
  SERVICE_LOCAL        = 1,
  SERVICE_NEWS         = 2,
  SERVICE_NNTP         = 3,
  SERVICE_POP          = 4,
  SERVICE_IMAP         = 5,
  SERVICE_IMSP         = 60

} ServiceType;

typedef struct _NET_SERVICES_ {
  char *service;
  ServiceType type;
} NetServices;


typedef struct _SERVER_CONFIG_ {
  char *name;
  ServiceType type;
  char *url;
  char *imap;

  char *hostname;
  unsigned port;

  char *username;
  char *password;
  char *mailbox;

  Boolean in_use;
  Mailbox_List *subscribed;
  Mailbox_List *unsubscribed;

  struct _SERVER_CONFIG_ *next;
  struct _SERVER_CONFIG_ *prev;

} Server_Config;

/* Ditto for the above structure's control window. */

typedef struct _NETWORK_CONFIG_ {
  Tool shell;
  Tool form;
  Tool menubar;
  Tool rowcol;
  Tool nick;
  Tool name;
  Tool user;
  Tool pass;
  Tool mbox;
  Tool button1;
  Tool button2;
  Tool button3;
  Tool button4;
  Tool button5;
  Tool button6;
  Tool port;
  Tool list;


  
  unsigned sel_port;
  ServiceType servicetype;
  Server_Config *current;
  Boolean is_realized;
  ButtonList *buttonlist;
  ButtonState buttonstate;
  unsigned long selection;

} Network_Config;




/* Use by text search window and also the compose spell function */


typedef struct _SEARCH_WIN_ {
  
  Tool shell;
  Tool searchw;
  Tool replacew;
  Tool parent;
  Tool sbutton;
  Tool rbutton;

  Boolean parent_destroyed;
  Boolean is_realized;
  Boolean reverse;
  Boolean replace;
  Boolean editable;
  XmTextPosition position;
  unsigned long button_state;
  String_List *string_list;
  String_List *base;
  char *search_text;
  char *replace_text;

} Search_Win;


/*
 * Linked list for holding address book entries.
 */

typedef struct _ADDRESS_BOOK_INFO_ {

  unsigned char *name;
  unsigned char *address;
  unsigned char *comment;
  unsigned char *groups;

  struct _ADDRESS_BOOK_INFO_ *next;
  struct _ADDRESS_BOOK_INFO_ *prev;

} Address_Book_Info;

/*
 * The control structure for the address book window.
 */


typedef struct _ADDRESS_BOOK_ {
  
  Tool shell;
  Tool rowcol;
  Tool name;
  Tool address;
  Tool groups;
  Tool comment;
  Tool pattern;
  Tool list;
  Tool search_list;

  Tool current_list;
  Boolean is_realized;

  unsigned long button_state;

  struct _ADDRESS_BOOK_INFO_ *current;

} Address_Book;


/*
 * Used to map a file attachment to a MIME type based on the
 * filename extension.
 */

typedef struct _FILENAME_MAP_ {

  char *suffix;
  int type;
  char *subtype;
  struct _FILENAME_MAP_ *next;

} Filename_Map;



/* 
 * Barely used right now. This was once going to map to Xew multi-media
 * handlers, but now, we just recognize the DOCTYPE_HELP to indicate that
 * the first line of the file will be the window title. No more Xew.
 */ 

typedef enum _DOC_TYPE_ {

  DOCTYPE_PLAIN     = 0,
  DOCTYPE_ENRICHED  = 1,
  DOCTYPE_IMAGE     = 2,
  DOCTYPE_AUDIO     = 3,
  DOCTYPE_VIDEO     = 4,
  DOCTYPE_HELP      = 5
    
} Doc_Type;



/*
 * Structure for maintaining external (or internal?) MIME handlers
 * Once again, the structure is overdesigned for current needs.
 */


typedef struct _MIME_HANDLER_ {

  int type;                        /* type this applies to */
  char *subtype;                   /* subtype this applies to */
  Boolean view_builtin;            /* not used */
  void *builtin;                   /* not used */
  char *view;                      /* executable command string to view */
  char *compose;                   /* executable command string to compose */
  struct _MIME_HANDLER_ *next;

} Mime_Handler;


/* 
 * Linked list of recognized MIME types
 */

typedef struct _MIME_TYPE_ {

  int type;
  char *subtype;
  struct _MIME_TYPE_ * next;

} Mime_Type;


/*
 * Control structure for MIME classification window
 */


typedef struct _MIME_ATTACH_ {

  Tool shell;
  Tool desc_text;
  Tool type_text;
  Tool type_list;

  char *compose;

  int done;

} Mime_Attach;



/*
 * Control structure for "linearizing" nested attachments and relating
 * them to a list widget.
 */


typedef struct _PART_LIST_ {

  int partnumber;
  PART *part;
  char *partstr;

  struct _PART_LIST_ *prev;
  struct _PART_LIST_ *next;

} Part_List;


/* 
 * Possible types of message compositions.
 */


typedef enum _COMPOSE_TYPE_ {

  COMPOSE_NEW            = 0,
  COMPOSE_REPLY          = 1,
  COMPOSE_REPLYALL       = 2,
  COMPOSE_FORWARD        = 3,
  COMPOSE_FORWARDATTACH  = 4,
  COMPOSE_REMAIL         = 5

} Compose_Type;



/* 
 *  Dual purpose window for text search/replace and spell correction. 
 * This is in transition from the previously mentioned search window.
 */

typedef struct ML_SEARCH_WINDOW_ {
  
  Tool parent;
  Tool shell;
  Tool search_textw;
  Tool replace_textw;
  Tool search_button;
  Tool replace_button;

  Boolean is_realized;
  Boolean reverse;
  Boolean replace;
  Boolean editable;

  XmTextPosition position;
  ButtonState button_state;
  String_List *string_list;
  String_List *base;

  char *search_text;
  char *replace_text;

} MLSearchWindow;


/* The compose window. This is all new, and in use. */

typedef struct _ML_COMPOSE_WINDOW_ {

  Tool shell;
  Tool form;
  Tool menubar;
  Tool rowcol;

  Tool to_button;
  Tool to_text;
  Tool newsgroups_button;
  Tool newsgroups_text;
  Boolean toggled_newsgroups;

  Tool subject_button;
  Tool subject_text;

  Tool cc_button;
  Tool cc_text;
  Tool bcc_button;
  Tool bcc_text;
  Boolean toggled_bcc;

  Tool attach_list;
  unsigned attach_list_selection;

  Tool compose_text;

  ButtonList *buttonlist;
  ButtonState buttonstate;

} MLComposeWindow;


typedef struct _ML_COMPOSE_OPTIONS_WINDOW_ {

  Tool shell;
  Tool form;
  Tool menubar;
  Tool mailhost;
  Tool nntphost;
  Tool domain;
  Tool replyto;
  Tool sigfile;
  Tool outlog;
  Tool charset;
  Tool language;
  Tool defcc;
  Tool defbcc;
  Tool prefix;
  Tool rowcol;
  Tool verbose;
  Tool keep_open;
  Tool send_eight;
  Tool word_wrap;
  Tool message_log;
  Tool log_attachments;

  ButtonList *buttonlist;
  Boolean is_realized;
  Boolean destroyed;

} MLComposeOptionsWindow;


typedef struct _ML_COMPOSE_OPTIONS_ {

  MLComposeOptionsWindow *window;

  Boolean verbose;
  Boolean verbose_tmp;
  Boolean keep_open;
  Boolean keep_open_tmp;
  Boolean send_eight;
  Boolean send_eight_tmp;
  Boolean word_wrap;
  Boolean word_wrap_tmp;
  Boolean message_log;
  Boolean message_log_tmp;
  Boolean log_attachments;
  Boolean log_attachments_tmp;

  char *mailhost;
  char *nntphost;
  char *domain;
  char *replyto;
  char *sigfile;
  char *outlog;
  char *defcc;
  char *defbcc;
  char *charset;
  char *language;
  char *prefix;

} MLComposeOptions;


/* The overall session compose structure containing the above "objects". */

typedef struct _ML_COMPOSE_ {

  MLComposeWindow          *window;
  MLComposeOptions         *options;
  Search_Win               *spellwindow;

  Compose_Type compose_type; 

  struct _MESSAGE_ *message;
  char *in_reply_to;
  char *reply_text;
  char *remail_header;

  Boolean in_ispell;
  Boolean has_newsgroups;

  struct mail_body_parameter *parameters;

  PART *attachments;

  struct _PART_LIST_ *part_list;

  struct _ML_COMPOSE_ *next;
  struct _ML_COMPOSE_ *prev;

} MLCompose;




/*
 *  Control structure for the compose "edit tool". This may be history. 
 */


typedef struct _EDIT_ {
  
  Tool shell;
  Tool strip_text;
  Tool insert_text;
  Tool wrap_text;
  Tool undo;
  Tool paste;

  Boolean is_realized;
  char *buffer;
  Position begin;
  Position end;

} Edit;



/*
 * Data structure for the file selection window
 */

typedef struct _DIR_STRUCT_ {

  char *name;
  Boolean directory;
  struct _DIR_STRUCT_ * next;

} Dir_Struct;


/*
 * Control structure for the file selection window.
 */


typedef struct _DIRVIEW_ {

  Tool shell;
  Tool dir_path;
  Tool dir_file;
  Tool dir_pattern;
  Tool dir_dirlist;
  Tool dir_filelist;

  unsigned long button_state;

  char *cwd;
  char *pathname;

  int recurse;
  Boolean ignore_dot;

  Dir_Struct *dir_struct;
  int done;

} Dirview;


/*
 * Types of messages for the read window
 */


typedef enum _MESSAGE_TYPE_ {
  MESSAGE_NORMAL    = 0,     /* self explanatory */
  MESSAGE_PART      = 1,     /* ditto            */
  MESSAGE_RAWPART   = 2,     /* not used.        */
  MESSAGE_IN_MEMORY = 3,     /* Also not used. desgined for external fetch */
  MESSAGE_FROM_FILE = 4      /* ditto. */
  
} Message_Type;




/*
 * Per-message data structure for the read window
 */


typedef struct _READ_INFO_ {


  Message_Type message_type;
  int mailbox_type;
  MAILSTREAM *mailstream;
  struct _MESSAGE_ *message;
  struct _LVIEW_  *lview;
  unsigned long msgno;
  int serialno;   /* which mainwindow */
  Boolean fetched;
  Boolean visible;
  Boolean expunged;
  int amount;
  char *server;
  char *current_part_str;
  char *base_part_str;
  char *header;
  char *short_header;
  char *current_text;
  char *alt_text;

  PART *current_part;
  BODY *body;
  ENVELOPE *envelope;
  Boolean show_long_header;
  Boolean selected;
  Boolean show_entire;
  Boolean show_alt;
  Boolean rfc_msg_leaf;
  PART *attachments;
  unsigned long button_state;

  unsigned long number; 

  unsigned long selection;

  Part_List *part_list;

  struct _READ_INFO_ *next;       /* reverse order !!!!!!!!!!!!!!!*/
  struct _READ_INFO_ *prev;       /* reverse order !!!!!!!!!!!!!!!*/


} Read_Info;


/*
 * Control structure for read window
 */

typedef struct _READ_ {

  Tool shell;
  Tool form;
  Tool menubar;
  Tool rowcol;
  Tool slider;
  Tool pane;
  Tool read_header;
  Tool read_attach;
  Tool read_text;

  ButtonList *buttonlist;

  Boolean is_realized;

  struct _READ_INFO_ *current;
  struct _READ_INFO_ *read_info;

  struct _READ_ *next;
  struct _READ_ *prev;

} Read;


/*
 * Control structure for PGP "address book"
 */


typedef struct _PGPKV_ {

  Tool shell;
  Tool text;
  Tool list;

  int done;

  char *result;

} Pgpkv;


/*
 * Control structure for the main Preferences window. Gad what a mess...
 */


typedef struct _PREFST_ {
  Tool shell;
 
  /* Basic Configuration */

  Tool confname;
  Tool prntcmd;
  Tool charset;

  Tool fldrpath;
  Tool helpdir;
  Tool mimedir;
  Tool savebox;
  Tool sendlog;
  Tool defcc;
  Tool defbcc;
  Tool headset;
  Tool viewline;
  Tool attribution;
  Tool dflact;
  Tool urlcomm;
  Tool newmail;
  Tool prefix;

  Boolean is_realized;
} Prefst;


typedef struct _PREF2ST_ {
  Tool shell;

  Tool check;
  Tool notesave;
  Tool imapport;
  Tool viewrows;
  Tool readrows;
  Tool comprows;

  Tool mailfetch;
  Tool mailcnt;
  Tool mailtime;
  Tool newsfetch;
  Tool newscnt;
  Tool newstime;

  Tool mailsort;
  Tool newssort;

  Tool aopen;
  Tool ispell;
  Tool tearoff;
  Tool mdebug;
  Tool mimeask;
  Tool logall;
  Tool decodeall;
  Tool send8;
  Tool hideview;
  Tool alert_new;
  Tool newMailBeep;
  Tool keepOnServer;
  Tool autoPlace;
  Tool showLog;

  Boolean is_realized;
} Pref2st;


/* 
 * Data structure maintained for each open mailbox. Will be extended soon.
 */


typedef struct _MAILBOX_ {
  
  Server_Config *server;
  MAILSTREAM *mailstream;
  Boolean locked;
  char *mailboxname;
  Boolean online;
  Boolean ispop;

  /* These will go away with the Server_Config in place. */

  char *host;
  unsigned long port;
  unsigned long auth_type;
  int imap_protocol;

  char *imapname;
  int type;               /* mailbox or newsgroup */
  unsigned nmsgs;         /* number of messages in the mailbox */

  Boolean fetched;        /* 
			   * We've created all the necessary message
			   * structures. Doesn't necessarily mean all
			   * the message structures are filled in.
			   */

  Boolean has_new_mail;   /*
			   * Something new arrived. Triggers various
			   * later actions such as re-evaluating 
			   * logical views
			   */

  Boolean auto_scan;      /*
			   * This mailbox will be closed when 
			   * another is opened.
			   */

  Boolean no_update;      /* Don't update .newsrc for this mailbox */

  struct _MESSAGE_LIST_ *found;     /* results of mailbox search */

  /*
   * The following three items are used to indicate that something
   * has changed in the mailbox, all as a result of flag changes,
   * but all are used to control different actions. "flags_changed" 
   * indicates that the mailbox should be checkpointed (changes flushed
   * by the server) on the next new mail check. "update_needed" informs
   * us that any active filters need to be re-evaluated, and refresh_needed
   * indicates that flags changed in the current (visible) logical view,
   * so it need to be redisplayed, whether or not its actual message list
   * changes during filter updates.
   */


  unsigned long flags_changed; 

  int update_needed;
  int refresh_needed;

  unsigned long first_fetch;   /* lowest message number fetched */

  XtIntervalId bg_timer;       /* For doing background fetches */
  XtIntervalId timer;          /* new mail check timer for this mailbox */

  struct _MAILBOX_ * next;
  struct _MAILBOX_ * prev;

} Mailbox;



/* Filter parse and search tree definitions */


typedef enum {
  AND_OP  = 0,
  OR_OP   = 1,
  NOT_OP  = 2,
  NO_OP   = 3
} BOOLEAN_OPERATOR;

typedef struct _BOOLEAN_LIST_ {
  char *localized;
  char *resource;
  char *operator;
  BOOLEAN_OPERATOR boole;
} BOOLEAN_LIST;

/* This defines the type of predicate in the leaf */
typedef enum {
  pred_simple = 1,
  pred_field = 2,
  pred_dynamic_field = 3
} PREDTYPE;

typedef enum {
  undefined = 1,
  local = 2,
  server = 3
} SEARCHTYPE;


typedef struct _DYNAMIC_FILTER_ {
  char *localized;
  char *resource;
  char *value;				/* dynamic predicate name */
  char *(*set_dynamic)();		/* creates real predicate */
} DYNAMIC;

typedef struct _SEARCH_DISPATCH_TABLE_ {
  char *token;
  Boolean (*chercheur)();
} SEARCHERS;

/* leaves of simple parse tree */
  
typedef struct _SEARCH_LEAF_ {
  char *predicate;			/* search predicate */
  BOOLEAN_OPERATOR operator;		/* predeceding operator */
  Boolean atomic_not;		        /* Do we negate? */
  PREDTYPE predicate_type;		/* simple_pred or field_pred */
  struct _SEARCH_LEAF_ *next;		/* link */
} LEAF;

typedef struct _leaf_macro_ {
  char *macro_name;			/* text name of this macro */
  LEAF *leaves;				/* for macro construction */
  int  n_leaves;
} LEAFMACRO;

/* search token object */

typedef struct _SEARCH_TOKEN_ {
  char *localized;
  char *resource;
  char *token;				/* string itself */
  Boolean field_required;		/* followed by a field if true */
  unsigned long field_attributes;	/* attributes for field */
} STOKEN;

typedef enum {
  no_error = 0,
  parse_success = 1,
  empty_filter = 2,
  illegal_token = 3,
  missing_field = 4,
  missing_dquote = 5,
  invalid_name = 6,
  expected_boolean = 7,
  missing_predicate = 8,
  parenthesis_bad = 9,
  illegal_left_paren_field = 10,
  illegal_right_paren_token = 11,
  trop_de_texte = 12,
  illegal_right_paren_termination = 13,
  illegal_numeric_field = 14,
  brackets_bad = 15,
  unprintable_chars = 16,
  misplaced_sauvage = 17

} parse_errors;

/* field  attributes */
#define NONE    (1<<0)			/* no attributes */
#define ATOMIC  (1<<1)			/* no "" used around field */
#define TIMESEARCH (1<<2)			/* THE TIME is used */
#define NUMERIC (1<<3)			/* Must be a number */
#define STRSEARCH (1<<4)                /* Apply substring searches */

/* searchees */
#define TOKEN 1
#define GEORGES_BOOLE 2

/* token types - a bit mask value is defined for each token type
 * which reflects a flag or state that the user can change
 * for a give message in the user interface. Each rule we parse will
 * pass on a composite token mask to the search filter. That way
 * not all filters will necessarily need to be searched if a state change
 * signaled by the server does not include one of the token types. */

#define TYPE_NULL      0
#define TYPE_KEYWORD   (1<<0)
#define TYPE_DELETED   (1<<1)
#define TYPE_UNDELETED (1<<2)
#define TYPE_SEEN      (1<<3)
#define TYPE_UNSEEN    (1<<4)
#define TYPE_RECENT    (1<<5)
#define TYPE_ANSWERED  (1<<6)
#define TYPE_UNANSWERED (1<<7)
#define TYPE_FLAGGED   (1<<8)
#define TYPE_UNFLAGGED (1<<9)
#define TYPE_NEW       (1<<10)
#define TYPE_OLD       (1<<11)
#define TYPE_TOUS      -1

/* other definitions */

#define PARSEBUFLEN 1024
#define SAUVAGE '\03'


/* Macro definitions */
#define RECIPIENT_MACRO "RECIPIENT"
#define CORRESPONDENT_MACRO "CORRESPONDENT"
#define CONVERSANT_MACRO "CONVERSANT"


/* 
 * Data structure for an individual message used by the logical views.
 *.One of these exists for each message in the mailbox. Many Message_List 
 * structures may reference each of these individual messages.
 */

typedef struct _MESSAGE_ {

  Mailbox *mailbox;
  MAILSTREAM *mailstream;
  ENVELOPE *envelope;
  BODY *body;
  LONGCACHE *longcache;
  unsigned long msgno;

  XmString viewline;         /* The line shown in the view window */

  char *sender;              /* possible decoded */
  char *subject;             /* possibly decoded */

  char *message_id;         /* For conversation threading (soon. ) */
  char *references;       
  struct _MESSAGE_ *thread_parent;
  Boolean thread_child;

  Boolean in_view;           /* true if contained in ANY user defined view */
  Boolean fetched;           /* TRUE if we've loaded the message envelope */

} Message;


/*
 * Linked list of messages. This is the heart of the logical view system.
 */


typedef struct _MESSAGE_LIST_ {

  struct _MESSAGE_ *message;
  Boolean selected;          /* I.e. selected IN THIS VIEW! */
  unsigned long number;      /* Sequence number IN THIS VIEW! */
  int level;                 /* Threading. Unused. */
  struct _MESSAGE_LIST_ *next;
  struct _MESSAGE_LIST_ *prev;

} Message_List;


/*
 * Types of filters
 */


typedef enum _FILTER_TYPE_ {
  
  FILTER_TYPE_UNKNOWN = 0,
  FILTER_TYPE_ALL     = 1,
  FILTER_TYPE_BUCKET  = 2,
  FILTER_TYPE_SYSTEM  = 3,
  FILTER_TYPE_USER    = 4,
  FILTER_TYPE_ONESHOT = 5

} Filter_Type;

/*
 * Possible ways to show a message header
 */

typedef enum _HEADERMODE_ {

  HEADER_UNKNOWN = 0,
  HEADER_FULL    = 1,
  HEADER_PART    = 2,
  HEADER_NONE    = 3

} Header_Mode;

/* action table. Synchronized to act_list structure in logical.c */

typedef enum {
  NO_ACT       = 0,
  DELETE_ACT   = 1,
  EXPUNGE_ACT  = 2,
  COPY_ACT     = 3,
  MOVE_ACT     = 4,
  SAVE_ACT     = 5,
  SHELL_ACT    = 6,
  FLAG_ACT     = 7,
  SET_ACT      = 8,
  UNSET_ACT    = 9,
  REPLY_ACT    = 10,
  PRINT_ACT    = 11,
  SELECT_ACT   = 12,
  NEW_ACT      = 13,
  UNSEEN_ACT   = 14,
  UNSELECT_ACT = 15,
  READ_ACT     = 16
  
 } ACTIONS;


typedef struct _actionrec {
  char *name;
  char *localized;
  char *resource;
  ACTIONS action;
  Boolean option;
  Boolean arg;
  Boolean implemented;
} ACTIONREC;


typedef struct _headerrec {
  char *name;
  char *localized;
  char *resource;
  Header_Mode hdrtype;
} HEADERREC;



/*
 * Possible ways to attach a filter to a mailbox
 */




/*
 * Data structure for filter definitions
 */


typedef struct _FILTER_ {

  char *mailboxname;               /* mailbox we're associated with */
  char *name;                      /* filter name */
  char *text;                      /* the filter definition or rules */
  char *action;                    /* default handling "script" */ 

  LEAF *search_tree;               /* result of parsing the filter rules */
  unsigned long search_types;      /* sortof unused */
  Boolean archived;                /* unused */

  Filter_Type filter_type;

  Representation_Type representation;

  unsigned long number;           /* edfilter list widget sequence number */

  struct _FILTER_ * next;         /* used in editor, not in logical views */
  struct _FILTER_ * prev;

} Filter;


/*
 * Data structure for the view window. Contains a filter and
 * a message_list which define the current view. Other items
 * included to maintain the window state. This IS a logical view.
 */

typedef struct _LVIEW_ {

  MAILSTREAM *mailstream;               /* our mailstream */
  Mailbox *mailbox;                     /* and our mailbox */
  char *title;                          /* window title */
  struct _MESSAGE_LIST_ *message_list;  /* this view's messages */
  unsigned long count;                  /* message count */
  unsigned long pruned;                 /* ignored (news) messages */
  Boolean prune_happened;               /* Don't reset the view > once */
  unsigned long num_selected;           /* number selected messages */
  Boolean selected;                     /* is lview itself selected? */
  unsigned long number;                 /* lview selector list sequence */
  Boolean has_new;                      /* any new messages in the view ? */
  unsigned long buttonstate;            /* state of this view */
  int level;                            /* nested logical view level */
  Representation_Type representation;   /* Sort order for this view. */

  /*
   * The following three items filled in by action scripts before
   * they call each script function. The script function checks to
   * see if (scripting == TRUE), and if so, uses the pre-supplied
   * arguments rather than popping up a window for that purpose.
   * However, we're sneaky and do that anyway if an argument is required
   * and we didn't get one from the script.
   */

  Boolean scripting;
  char *script_arg;
  Header_Mode script_header;

  struct _FILTER_ *filter;              /* our filter definition */

  struct _LVIEW_ *parent;               /* We support hierarchical views. */

  struct _LVIEW_ *prev;                 
  struct _LVIEW_ *next;

} Lview;


/* The cute little notebook window. */

typedef struct _NOTE_ {
  
  Tool shell;
  Tool text;
  XtIntervalId autosave;
  Boolean is_realized;

} Note;


/*
 * Used to map a mailbox name to a file containing default filters 
 * for that mailbox. This will soon change to point to a 
 * per-mailbox area in the data (cache) dir.
 */


typedef struct _FILTER_MAP_ {

  char *mailboxname;
  char *filename;
  int sequence;
  struct _FILTER_MAP_ *next;

} Filter_Map;



/*
 * These used for configurable buttons, and aren't exactly perfect, since
 * it requires us to duplicate a lot of stuff that's already in the main
 * menu structures.
 */

typedef struct _BUTTON_MENU_ {
  char *label;
  void (*func)();
  Tool widget;
  ButtonState statemap;
  struct _BUTTON_MENU_ *next;
  struct _BUTTON_MENU_ *prev;
} Button_Menu;

typedef struct _BUTTON_TABLE_ {
  char *label;
  char *desc;
  void (*func)();
  unsigned long statemap;
} Button_Table;


typedef enum _BTN_MENU_TYPE_ {
  MAIN_BTN_MENU         = 0,
  READ_BTN_MENU         = 1,
  COMPOSE_BTN_MENU      = 2,
  MAILBOX_BTN_MENU      = 3
} Btn_Menu_Type;

#define LAST_BTN_MENU          MAILBOX_BTN_MENU

/* Definable buttons window structure */

typedef struct _BTN_ {
  Tool shell;
  Tool namew;
  Tool funcw;
  Tool list;
  Tool curr_list;
  Btn_Menu_Type type;
  Button_Menu *button_menu;
  Button_Table *button_table;
  int btn_count;
  int selected1;
  Button_Menu *selected2;
  Boolean is_realized;
  unsigned long button_state;

} Btn;


typedef struct _LIST_WINDOW_ {

  Tool shell;
  Tool list;
  Boolean is_realized;
  Boolean hide_empty;

} ListWindow;


/* Control structure for main windows */


typedef struct _MAIN_WINDOW_ {

  Boolean is_main;
  Boolean destroyed;
  int     serialno;
  Tool shell;
  Tool menubar;
  Tool rowcol;
  Tool form;

  Tool slider;

  Tool action_button;
  Tool action;

  Tool pane;
  Tool log;
  Tool list;

  ButtonList *buttonlist;

  ListWindow *listwin;

  struct _LVIEW_ *current;
  struct _LVIEW_ *lview;

  struct _MAIN_WINDOW_ *next;
  struct _MAIN_WINDOW_ *prev;

} MainWindow;


typedef struct _LOG_WINDOW_ {
  
  Tool shell;
  Tool text;
  Boolean is_realized;
  Boolean destroyed;
} LogWindow;


/*
 * Control structure for mailbox selection windows.
 */

typedef struct _MAILBOX_WIN_ {

  Tool shell;
  Tool form;
  Tool menubar;
  Tool rowcol;
  Tool server;
  Tool pattern;
  Tool mailbox;
  Tool list;
  Tool conf_button;
  Tool patt_button;
  Tool name_button;

  ButtonList *buttonlist;
  ButtonState button_state;
  MainWindow *mwin;
  Server_Config *current;
  MAILSTREAM *mailstream;
  int type;
  Boolean local_only;
  Boolean everything;
  Boolean move;
  int done;
  Boolean is_realized;
  Boolean top_level;
  unsigned long item_no;
} Mailbox_Win;


/*
 * Control structure for the filter edit window
 */


typedef struct _ATTACH_OPERATION_ {
  Boolean mailbox;
  Boolean active;

} Attach_Operation;




typedef struct _EDFILTER_ {
  
  Tool shell;
  Tool rowcol;
  Tool name;
  Tool action;
  Tool text;
  Tool list;
  Tool radio1;
  Tool radio2;
  Tool radio3;
  Tool radio4;
  Tool radio5;
  Tool radio6;
  Tool radio7;
  Tool radio8;
  Attach_Operation *op;
  Filter *current;
  MainWindow *mwin;
  unsigned long selection;
  unsigned long button_state;
  Representation_Type representation;
  Boolean is_realized;

} Edfilter;



/* 
 * Top level structure which can access most everything in the program.
 */

typedef struct _SESSION_ {

  /* Main Window */

  Tool shell;                   /* application shell */
  MainWindow *mwin;             /* main window structures (linked list) */
  ButtonState buttonstate;      /* Used only for BTN_NOMAILBOXESOPEN */
  Boolean connected;            /* are we online ? */
  LogWindow *lwin;              /* system messages window */

  /* Session Information */

  Server_Config *active;        /* set to configuration executing a callback */
  Boolean busy;                 /* I/O pending (watch/pirate cursor set) */
  unsigned connections;         /* Unused currently. For disconnected. */
  Mailbox *mailboxes;           /* Currently open mailboxes            */
  Mime_Handler *mime_handlers;  /* Helper apps */
  Filter *filters;              /* defined filters, not neccessarily active */
  Filter *session_filters;      /* filters attached at the session level */
  Server_Config *servers;       /* Server configuration tables */
  Remote_Auth *authorizations;  /* Saved authenticators */
  int update_needed;            /* flags changed during a callback */
  Network_Config *netconf;      /* Config window */
  Mailbox_Win *mailboxwin;      /* Mailbox "open" window chain */
  Mailbox_Win *mailcopywin;     /* Mailbox "copy" window chain */
  MLCompose *compose;           /* compose window chain */
  Read *read;                   /* read window + data chain */
  Address_Book *address_book;   /* Address book window */
  Address_Book_Info *addresses; /* list of addresses */
  Note *note;                   /* The notebook */
  Prefst *prefst;               /* top level preferences window */
  Pref2st *pref2st;             /* option preferences window */
  Gentext *gentext;             /* help/general text window chain */
  Edfilter *edfilter;           /* filter editor + data chain */
  Filter_Map *filter_map;       /* mailboxname to saved filter file mapping */
  Btn *btn;                     /* button editor window, unused currently ? */

  char **header_set;            /* base of user-defined header set string */
  char *header_str;             /* Same, but string array */
  char *last_command;           /* saved command for exec functions */
  char *last_dir;               /* saved directory for file selections */
  char *cachedir;               /* The main cache directory location */

} Session;






syntax highlighted by Code2HTML, v. 0.9.1