1 /*
2  *  MSGED.H
3  *
4  *  Written on 30-Jul-90 by jim nutt.  Changes on 10-Jul-94 by John Dennis.
5  *  Released to the public domain.
6  *
7  *  Main header file for all Msged source files.
8  */
9 
10 #ifndef __MSGED_H__
11 #define __MSGED_H__
12 
13 #ifndef max
14 #define max(a,b) (((a) > (b)) ? (a) : (b))
15 #endif
16 
17 #ifndef min
18 #define min(a,b) (((a) < (b)) ? (a) : (b))
19 #endif
20 
21 #ifndef FALSE
22 #define FALSE 0
23 #endif
24 
25 #ifndef TRUE
26 #define TRUE 1
27 #endif
28 
29 #ifdef PATHLEN
30 #undef PATHLEN
31 #endif
32 
33 #define NO        0
34 #define YES       1
35 #define FAIL      0
36 #define OK        1
37 #define HIDE      2
38 #define RIGHT     0
39 #define LEFT      1
40 #define SAVE      1
41 #define ABORT     -1
42 
43 #define GDOMAINS  0x01          /* gate domains */
44 #define GZONES    0x02          /* gate zones */
45 #define BOTH      0x04          /* gate both */
46 #define GASK      0x08          /* ask if gate should be used */
47 
48 #define DSCTAGASIS   0x01          /* what to import from the areafile  */
49 #define DSCTAGUPPER  0x02          /* and how to do it                  */
50 #define DSCTAGLOWER  0x04
51 #define DSCDESCASIS  0x08
52 #define DSCDESCUPPER 0x10
53 #define DSCDESCLOWER 0x20
54 
55 #define FIDO      0x00          /* message base types */
56 #define QUICK     0x01
57 #define SQUISH    0x02
58 #define JAM       0x03
59 
60 /* #define AREASBBS   0x00 */   /* area file types */
61 #define FASTECHO   0x01
62 /* #define SQUISH     0x02 */
63 #define GECHO      0x03
64 #define FIDOCONFIG 0x04
65 
66 #define USENET    0x01
67 #define FIDONET   0x02
68 
69 #define PATHLEN   64
70 #define BLOCKLEN  255
71 
72                                 /* A buffer of this size must be able to
73                                    store a) the complete amount of kludges in
74                                    the message, or alternatively b) a complete
75                                    paragraph (i.E. a text block without CR's
76                                    in it.  Especially in times of internet
77                                    gateways, the amount of kludge lines can
78                                    easily grow past 4K (think of myriads of
79                                    @RFC-CC: kludges etc.). Msged will not
80                                    crash if the buffer has an overflow, but
81                                    the overflowing parts of the message will
82                                    simply not be displayed. */
83 #ifdef DOS
84 #define BUFLEN    4096
85 #else
86 #define BUFLEN  16384
87 #endif
88 
89 #define MAXUSERS  20
90 
91 #define MT_QUO    0x0001        /* msg has a quote */
92 #define MT_REP    0x0002        /* msg is a reply (no quote) */
93 #define MT_ARC    0x0004        /* check for dest. area */
94 #define MT_FOL    0x0008        /* insert followup template */
95 #define MT_NEW    0x0010        /* msg is new (no to:) */
96 #define MT_FOR    0x0020        /* forwarded message */
97 #define MT_RED    0x0040        /* redirected message */
98 
99 #define WR_HEADER        0x0001 /* write header only */
100 #define WR_ALL           0x0002 /* write all msg */
101 #define RD_HEADER        0x0004 /* read header only */
102 #define RD_ALL           0x0008 /* read all msg */
103 #define RD_HEADER_BRIEF  0x0010 /* read header without replies */
104 
105 #define ERR_OPEN_MSG     -1     /* error opening msg */
106 #define ERR_CLOSE_MSG    -2     /* error closing message */
107 #define ERR_OPEN_AREA    -3     /* error opening area */
108 #define ERR_CLOSE_AREA   -4     /* error closing area */
109 #define ERR_NO_AREA      -5     /* no area currently open! */
110 
111 /* file permissions */
112 #if defined(UNIX)                               /* file permissions for creation */
113 #define S_IMODE_NETMAIL  S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP
114 #define S_IMODE_ECHOMAIL S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH
115 #define S_IMODE_LASTREAD S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH
116 #define S_IMODE ((CurArea.netmail||CurArea.local)?S_IMODE_NETMAIL:S_IMODE_ECHOMAIL)
117 #else /* not UNIX */
118 #define S_IMODE S_IREAD|S_IWRITE
119 #define S_IMODE_LASTREAD S_IREAD|S_IWRITE
120 #endif
121 
122 
123 /* useful time-saving macros */
124 
125 #define ST        string_vars
126 #define SW        switch_vars
127 #define thisnode  alias[0]
128 #define CurArea   arealist[SW->area]
129 
130 /* structures and typedefs */
131 
132 /* Attributes used & recognized by Msged */
133 
134 struct _attributes
135 {
136     unsigned int priv      : 1;  /* private message flag */
137     unsigned int crash     : 1;  /* crash mail */
138     unsigned int rcvd      : 1;  /* received by addressee */
139     unsigned int sent      : 1;  /* message sent */
140     unsigned int attach    : 1;  /* file attached */
141     unsigned int forward   : 1;  /* message in transit */
142     unsigned int orphan    : 1;  /* unknown destination */
143     unsigned int killsent  : 1;  /* kill after sending */
144     unsigned int local     : 1;  /* local message */
145     unsigned int hold      : 1;  /* hold for pickup */
146     unsigned int direct    : 1;  /* do no gating on this msg */
147     unsigned int freq      : 1;  /* file request */
148     unsigned int rreq      : 1;  /* return receipt requested */
149     unsigned int rcpt      : 1;  /* return receipt */
150     unsigned int areq      : 1;  /* audit trail request */
151     unsigned int ureq      : 1;  /* update file request */
152 
153     /* extended attributes only found in @FLAGS kludge line */
154     unsigned int kfs       : 1;  /* kill file when sent */
155     unsigned int as        : 1;  /* archive when sent */
156     unsigned int immediate : 1;  /* immediate delivery */
157     unsigned int tfs       : 1;  /* truncate file when sent */
158     unsigned int lock      : 1;  /* do not process this mail */
159     unsigned int cfm       : 1;  /* confirm receipt request */
160     unsigned int zon       : 1;  /* send mail via zone gate */
161     unsigned int hub       : 1;  /* hub routing */
162 };
163 
164 /* Structure defining an alias for header and cc: entry */
165 
166 typedef struct _alias
167 {
168     int attr;                   /* was an attribute specified? */
169     char *alias;                /* the alias */
170     char *name;                 /* the real name */
171     char *subj;                 /* the subject */
172     struct _attributes attrib;  /* the attributes (if used) */
173     FIDO_ADDRESS addr;          /* the address (if used) */
174 }
175 ALIAS;
176 
177 /* Structure defining a Version7 nodelist */
178 
179 typedef struct _domain_list
180 {
181     char *name;                 /* full domain name eg. fidonet.org */
182     char *base_name;            /* base name of nodelist ie. nodex */
183     char *sysop;                /* sysop lookup filename eg. sysop.ndx */
184 }
185 D_LIST;
186 
187 /*
188  *  Defines a user plus the corresponding useroffset and lastread
189  *  values.  The current values are copied to the global equivalents
190  *  (to avoid extra work).
191  */
192 
193 typedef struct _user
194 {
195     char *name;
196     char *lastread;
197     char *robotname;
198     unsigned long offset;
199     int offs_defined;
200 }
201 USER;
202 
203 
204 /* The internal area structure. Contains all info relevant for an area. */
205 
206 typedef struct _area
207 {
208     int status;                 /* status of the area, 0 = closed, 1 = open */
209     FIDO_ADDRESS addr;          /* the address to use in this message */
210     char *description;          /* what the user calls the area */
211     char *tag;                  /* what confmail calls it! */
212     char *path;                 /* where the area is on disk */
213 
214     unsigned int local     : 1;  /* local message area */
215     unsigned int netmail   : 1;  /* netmail message area */
216     unsigned int echomail  : 1;  /* echomail area */
217     unsigned int news      : 1;  /* usenet news area */
218     unsigned int uucp      : 1;  /* usenet mail area */
219     unsigned int new       : 1;  /* a message has been entered */
220     unsigned int priv      : 1;  /* default private */
221     unsigned int hold      : 1;  /* default hold */
222     unsigned int direct    : 1;  /* default direct */
223     unsigned int crash     : 1;  /* default crash */
224     unsigned int killsent  : 1;  /* default crash */
225     unsigned int eightbits : 1;  /* use charset kludging */
226     unsigned int scanned   : 1;  /* area has been scanned */
227     unsigned int recodedsc : 1;  /* recode areatag from IBMPC to local chrs */
228 
229     int group;                  /* Group handle */
230     int areanumber;             /* Number of this area. Normally corresponds
231                                    to the array index. Needed to make qsort
232                                    stable when sorting the areas */
233 
234     int template;               /* index into template array */
235     int username;               /* index into username array */
236 
237     unsigned int msgtype;       /* the message type */
238     int board;                  /* if a quickbbs area, which board */
239     unsigned long first;        /* first message in the area? */
240     unsigned long last;         /* last message in the area */
241     unsigned long current;      /* current message in the area */
242     unsigned long messages;     /* how many messages in the area */
243     unsigned long lastread;     /* the highest message read */
244 }
245 AREA;
246 
247 /*
248  *  The internal message structure.  Built to reflect both Squish
249  *  (32-bit) and other messagebase structures.
250  */
251 
252 typedef struct _msg
253 {
254     unsigned long msgnum;       /* message number (UMSGID) */
255     char *reply;                /* id of message this is a reply to */
256     char *msgid;                /* this messages msgid */
257     char *isfrom;               /* who from */
258     char *isto;                 /* who to */
259     char *subj;                 /* message subject */
260     char *replyarea;            /* AREA: kludge */
261     char *charset_name;         /* CHRS: kludge - first string */
262     int   charset_level;        /* CHRS: kludge - FTSC 0054 level number */
263 
264     unsigned int new        : 1;  /* new message? */
265     unsigned int change     : 1;  /* message been changed? */
266     unsigned int scanned    : 1;  /* msg been scanned? */
267     unsigned int newrcvd    : 1;  /* msg just received? */
268     unsigned int soteot     : 1;  /* msg sot/eot protected? */
269     unsigned int invkludges : 1;  /* invalidate kludges? */
270     unsigned int rawcopy    : 1;  /* copy msg text/ctrlinfo raw? */
271     unsigned int has_timezone:1;  /* if timezone contains valid information */
272 
273     time_t timestamp;           /* creation date, */
274     time_t time_arvd;           /* time message arrived */
275     int timezone;               /* offset from utc in minutes, east = + */
276 
277     unsigned long replyto;      /* thread to previous msg */
278     unsigned long replies[10];  /* thread to next msg(s) */
279 
280     struct _attributes attrib;  /* message attribute */
281     int times_read;             /* times msg been read */
282     int cost;                   /* cost of message */
283 
284     FIDO_ADDRESS to;            /* destination address of message */
285     FIDO_ADDRESS from;          /* origin address of message */
286     LINE *text;                 /* the message buffer */
287 }
288 msg;
289 
290 /* A command/label assignment structure (for the keyboard) */
291 
292 struct _command
293 {
294     char *label;
295     void (*action) (void);
296 };
297 
298 /* Handle for msgbase access functions */
299 
300 typedef struct _msghandle
301 {
302     msg *(*MsgReadHeader) (unsigned long n, int type);
303     char *(*MsgReadText) (unsigned long n);
304     int (*MsgWriteHeader) (msg * m, int type);
305     int (*MsgWriteText) (char *text, unsigned long n, unsigned long mlen);
306     int (*MsgDelete) (unsigned long n);
307     int (*AreaSetLast) (AREA * a);
308     long (*MsgAreaOpen) (AREA * a);
309     int (*MsgAreaClose) (void);
310     int (*MsgClose) (void);
311     unsigned long (*UidToMsgn) (unsigned long n);
312     unsigned long (*MsgnToUid) (unsigned long n);
313     int (*MsgLockArea) (void);
314     int (*MsgUnlockArea) (void);
315 }
316 msghandle;
317 
318 /* These are the system strings, for access across the system */
319 
320 struct _sv
321 {
322     char *username;             /* who is you */
323     char *quotestr;             /* how to prefix a quote */
324     char *fidolist;             /* nodelist user list */
325     char *userlist;             /* personal user list */
326     char *origin;               /* origin line */
327     char *outfile;              /* default export filename */
328     char *infile;               /* default import filename */
329     char *home;                 /* home directory */
330     char *lastread;             /* name of the lastread file */
331     char *cfgfile;              /* name of the config file */
332     char *echotoss;             /* echotoss log file name */
333     char *template;             /* template file */
334     char *nodepath;             /* path to current nodelist */
335     char *nodebase;             /* base (current) nodelist name */
336     char *sysop;                /* name of sysop */
337     char *swap_path;            /* swap path */
338     char *helpfile;             /* helpfile name */
339     char *uucpgate;             /* the UUCP gate name to send to */
340     char *comspec;              /* file spec of command processor */
341     char *editorName;           /* name of external editor */
342     char *quickbbs;             /* where a quickbbs file is */
343     char *fecfgpath;            /* path of fastecho configuration file */
344     char *output_charset;       /* charset to use for output if the "8" */
345                                 /* flag is set */
346     char *sort_criteria;        /* sort criteria for areas */
347     char *special_characters;   /* allowed ASCII codes >= 128 */
348     char *freqarea;             /* area tag for area to make f.req.in */
349     char *input_charset;        /* charset  assumed when reading mail
350                                    without CHRS kludge. */
351     char *enforced_charset;     /* input charset that is always enforced */
352     char *uucpreplyto;          /* a replyto: string for e-mail */
353     char *freqflags;            /* flags to use for file requests */
354     char *printer;              /* printer port or command name */
355     char *readmap;              /* READMAPS.DAT filename */
356     char *writemap;             /* WRITMAPS.DAT filename */
357 };
358 
359 /* These are the system switches, for access across the system */
360 
361 struct _swv
362 {
363     unsigned long useroffset;   /* offset into lastread file */
364     int area;                   /* current area number */
365     int areas;                  /* how many message areas */
366     int maxareas;               /* how much room in arealist array */
367     int aliascount;             /* how many AKAs aliases do you have? */
368     int otheraliases;           /* how many aliases for other nodes? */
369     int maxotheraliases;        /* consume memory in Zimbabwe ;-) */
370     int numtemplates;           /* how many templates in use? */
371     int domains;                /* how many domains listed */
372     int rm;                     /* the current right margin */
373     int qm;                     /* the current quote margin */
374     int orgrm;                  /* the right margin as desired by the user */
375     int orgqm;                  /* the quote margin as desired by the user */
376     int pointnet;               /* private net number of point */
377     int tabsize;                /* how many spaces for a tab */
378     int nodelists;              /* number of nodelists */
379     int rquote;                 /* dfns for the reply funcs; quote */
380     int rotharea;               /* reply other area */
381     int rfollow;                /* reply followup */
382     int rextra;                 /* reply extra - user definable */
383     int gate;                   /* zone/domain gate messages? */
384     int override;               /* override the area origin line */
385     int redraw;                 /* redraw screen header? */
386     int msgids;                 /* add msgid lines */
387     int opusdate;               /* put in the opus time stamp */
388     int shownotes;              /* show hidden lines */
389     int showseenbys;            /* show seenby lines */
390     int showorigins;            /* show origin lines */
391     int showtearlines;          /* show tear lines */
392     int confirmations;          /* confirm deletes, aborts? */
393     int datearrived;            /* show the date msg arrived? */
394     int showaddr;               /* shows curr address on screen */
395     int use_lastr;              /* whether to use lastread/current */
396     int qquote;                 /* quote quotes? */
397     int savecc;                 /* save cc original copy? */
398     int rawcc;                  /* save the raw cc msg? */
399     int chopquote;              /* chop off the end of quoted msgs? */
400     int hardquote;              /* don't reformat quoted text? */
401     int showcr;                 /* show CRs? */
402     int showeol;                /* show eol? */
403     int showrealmsgn;           /* show real msg#s in <alt><l> */
404     int usemouse;               /* use the mouse? */
405     int tabexpand;              /* expand tabs? */
406     int editcronly;             /* show CRs in editor only */
407     int usepid;                 /* use a PID instead of a tear line */
408     int soteot;                 /* use SOT/EOT */
409     int showtime;               /* show time in main message area? */
410     int importfn;               /* show the filename headers on import */
411     int dmore;                  /* display msg numbers at top of screen */
412     int statbar;                /* show statbar */
413     int showsystem;             /* show system name? */
414     int extformat;              /* format externally-edited messages? */
415     int arealistexactmatch;     /* exact match area names in area list? */
416     int echoflags;              /* use FLAGS control line in echomail? */
417     int netmailvia;             /* use Via control line in netmail? */
418     int domainorigin;           /* write domain information to origin line? */
419     int rightnextunreadarea;    /* key right to next unread area? */
420     int usetearlines;           /* add tear lines in echomail? */
421     int useoriginlines;         /* add origin lines in echomail? */
422     int edittearlines;          /* add tearlines to template message */
423     int editoriginlines;        /* add originlines to template message */
424     int lowercase;              /* Convert filenames to lower case */
425     int adaptivecase;           /* Case insenstive behaviour on Unix */
426     int receiveallnames;        /* Switch rvd on for mail to all configured */
427                                 /* user names, or only for the active one? */
428     int receivealladdr;         /* similar thing for FTN addresses */
429     int squish_lock;            /* Lock message base for better speed */
430     int carthy;                 /* behaviour of delete_line at last line */
431     int direct_list;            /* jump directly to message listing mode */
432     int areadesc;               /* how to build areadesc from areafile */
433     int areadefinesuser;        /* the selected area defines the username */
434     int groupareas;             /* # of areas in current group selection */
435     int group;                  /* currently selected group, 0 = none */
436     int groupseparators;        /* do we want to draw horizontal bars? */
437     int grouparea;              /* SW->area = grouparealist[SW->grouparea] */
438     int areafilegroups;         /* want to read group info from areafile? */
439     int domainmsgid;		/* show msgid's with domain string? */
440     int tzutc;                  /* generate TZUTC kludge line? */
441     int xxltearline;            /* allow tearline > 35 characters? */
442 };
443 
444 
445 #ifndef INCL_MAIN
446 
447 extern struct _swv *switch_vars;  /* array of switches */
448 extern struct _sv *string_vars;   /* array of strings */
449 extern msghandle msgdo[];         /* msgbase functions */
450 extern FIDO_ADDRESS *domain_list; /* list of ^aDOMAIN lookups */
451 extern FIDO_ADDRESS *alias;       /* list of AKA's */
452 extern FIDO_ADDRESS uucp_gate;    /* closest UUCP gate */
453 extern D_LIST *node_lists;        /* list of v7 nodelists */
454 extern AREA *arealist;            /* list of areas for system */
455 extern ALIAS *aliaslist;          /* list of alias lookups */
456 extern USER user_list[MAXUSERS];  /* list of system users */
457 extern char **templates;          /* list of templates */
458 extern char **origins;            /* list of alternative origins */
459 extern int n_origins;             /* number of alternative origins */
460 extern msg *message;              /* current message */
461 extern unsigned int *macros[41];  /* macros */
462 extern int maxy;                  /* max y pos, 1 origin */
463 extern int maxx;                  /* max x pos, 1 origin */
464 extern int maxx_force;
465 extern int maxy_force;
466 extern int cur_start;             /* these are ega/vga default */
467 extern int cur_end;               /* cursor sizes */
468 extern int rot13;                 /* rot13 this message? */
469 extern int stripSoft;             /* strip soft-crs? */
470 extern int softcrxlat;            /* soft cr replacement if not zero */
471 extern char *msgbuf;              /* message buffer for reading, size BUFLEN */
472 extern int msgederr;              /* global error number */
473 extern int cmd_dbginfo;           /* show debugging info at startup? */
474 extern int areas_type;            /* areas read from fastecho */
475 extern int scan;                  /* scan areas for new mail at startup? */
476 extern int *grouparealist;
477 
478 #endif
479 
480 /* various and sundry macros */
481 
482 #define release(s)                {if (s != NULL) free(s); s = NULL;}
483 
484 #define MsgReadHeader(n,type)     (msgdo[CurArea.msgtype].MsgReadHeader(n,type))
485 #define MsgReadText(n)            (msgdo[CurArea.msgtype].MsgReadText(n))
486 #define MsgWriteHeader(m,type)    (msgdo[CurArea.msgtype].MsgWriteHeader(m,type))
487 #define MsgWriteText(text,n,mlen) (msgdo[CurArea.msgtype].MsgWriteText(text,n,mlen))
488 #define MsgDelete(n)              (msgdo[CurArea.msgtype].MsgDelete(n))
489 #define AreaSetLast(a)            (msgdo[CurArea.msgtype].AreaSetLast(a))
490 #define MsgAreaOpen(a)            (msgdo[CurArea.msgtype].MsgAreaOpen(a))
491 #define MsgAreaClose()            (msgdo[CurArea.msgtype].MsgAreaClose())
492 #define MsgClose()                (msgdo[CurArea.msgtype].MsgClose())
493 #define UidToMsgn(n)              (msgdo[CurArea.msgtype].UidToMsgn(n))
494 #define MsgnToUid(n)              (msgdo[CurArea.msgtype].MsgnToUid(n))
495 #define MsgLockArea()             (msgdo[CurArea.msgtype].MsgLockArea())
496 #define MsgUnlockArea()           (msgdo[CurArea.msgtype].MsgUnlockArea())
497 
498 #define DOROT13(c) ((rot13 == 0) ? (c) : handle_rot((c)))
499 
500 /* prototypes */
501 
502 msg *KillMsg(msg * m);
503 int confirm(char *option);
504 void arealist_area_scan(int);
505 void e_assignkey(unsigned int key, char *label);
506 void r_assignkey(unsigned int key, char *label);
507 void area_scan(int);
508 void dolist(void);
509 void dispose(msg * message);
510 void set_nongrouped_area(int newarea); /* argument is absolute area number */
511 void set_area(int newgrouparea);       /* argument is a group area number */
512 void cleanup(char *msg,...);
513 void SetupArea(void);
514 int dv_running(void);
515 void shell_to_dos(void);
516 void scan_all_areas(void);
517 void scan_unscanned_areas(void);
518 
519 #endif
520