1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T 24 * All Rights Reserved 25 * 26 * 27 * Copyright (c) 1985-2001 by Sun Microsystems, Inc. 28 * All rights reserved. 29 */ 30 31 /* 32 * University Copyright- Copyright (c) 1982, 1986, 1988 33 * The Regents of the University of California 34 * All Rights Reserved 35 * 36 * University Acknowledgment- Portions of this document are derived from 37 * software developed by the University of California, Berkeley, and its 38 * contributors. 39 */ 40 41 #ifndef _MAILX_DEF_H 42 #define _MAILX_DEF_H 43 44 #pragma ident "%Z%%M% %I% %E% SMI" 45 46 #ifdef __cplusplus 47 extern "C" { 48 #endif 49 50 #include <sys/types.h> 51 #include <signal.h> 52 #include <stdio.h> 53 #include <fcntl.h> 54 #include <string.h> 55 #include <termio.h> 56 #include <setjmp.h> 57 #include <time.h> 58 #include <sys/stat.h> 59 #include <maillock.h> 60 #include <ctype.h> 61 #include <errno.h> 62 #ifndef preSVr4 63 # include <unistd.h> 64 # include <stdlib.h> 65 # include <ulimit.h> 66 # include <wait.h> 67 #endif 68 #ifdef VMUNIX 69 #include <sys/wait.h> 70 #endif 71 #include "local.h" 72 #include "uparm.h" 73 74 /* 75 * mailx -- a modified version of a University of California at Berkeley 76 * mail program 77 */ 78 79 #define SENDESC '~' /* Default escape for sending */ 80 #define NMLSIZE 1024 /* max names in a message list */ 81 #define PATHSIZE 1024 /* Size of pathnames throughout */ 82 #define HSHSIZE 59 /* Hash size for aliases and vars */ 83 #define HDRFIELDS 3 /* Number of header fields */ 84 #define LINESIZE 5120 /* max readable line width */ 85 #define STRINGSIZE ((unsigned) 128)/* Dynamic allocation units */ 86 #define MAXARGC 1024 /* Maximum list of raw strings */ 87 #define NOSTR ((char *) 0) /* Nill string pointer */ 88 #define NOSTRPTR ((char **) 0) /* Nill pointer to string pointer */ 89 #define NOINTPTR ((int *) 0) /* Nill pointer */ 90 #define MAXEXP 25 /* Maximum expansion of aliases */ 91 92 #define equal(a, b) (strcmp(a,b)==0)/* A nice function to string compare */ 93 #define fopen(s,t) my_fopen(s,t) /* Keep a list of all opened files */ 94 #define fclose(s) my_fclose(s) /* delete closed file from the list*/ 95 96 struct message { 97 off_t m_offset; /* offset in block of message */ 98 long m_size; /* Bytes in the message */ 99 long m_lines; /* Lines in the message */ 100 long m_clen; /* Content-Length of the mesg */ 101 short m_flag; /* flags, see below */ 102 char m_text; /* TRUE if the contents is text */ 103 /* False otherwise */ 104 }; 105 106 typedef struct fplst { 107 FILE *fp; 108 struct fplst *next; 109 } NODE; 110 111 /* 112 * flag bits. 113 */ 114 115 #define MUSED (1<<0) /* entry is used, but this bit isn't */ 116 #define MDELETED (1<<1) /* entry has been deleted */ 117 #define MSAVED (1<<2) /* entry has been saved */ 118 #define MTOUCH (1<<3) /* entry has been noticed */ 119 #define MPRESERVE (1<<4) /* keep entry in sys mailbox */ 120 #define MMARK (1<<5) /* message is marked! */ 121 #define MODIFY (1<<6) /* message has been modified */ 122 #define MNEW (1<<7) /* message has never been seen */ 123 #define MREAD (1<<8) /* message has been read sometime. */ 124 #define MSTATUS (1<<9) /* message status has changed */ 125 #define MBOX (1<<10) /* Send this to mbox, regardless */ 126 #define MBOXED (1<<11) /* message has been sent to mbox */ 127 128 #define H_AFWDCNT 1 /* "Auto-Forward-Count:" */ 129 #define H_AFWDFROM 2 /* "Auto-Forwarded-From:" */ 130 #define H_CLEN 3 /* "Content-Length:" */ 131 #define H_CTYPE 4 /* "Content-Type:" */ 132 #define H_DATE 5 /* "Date:" */ 133 #define H_DEFOPTS 6 /* "Default-Options:" */ 134 #define H_EOH 7 /* "End-of-Header:" */ 135 #define H_FROM 8 /* "From " */ 136 #define H_FROM1 9 /* ">From " */ 137 #define H_FROM2 10 /* "From: " */ 138 #define H_MTSID 11 /* "MTS-Message-ID:" */ 139 #define H_MTYPE 12 /* "Message-Type:" */ 140 #define H_MVERS 13 /* "Message-Version:" */ 141 #define H_MSVC 14 /* "Message-Service:" */ 142 #define H_RECEIVED 15 /* "Received:" */ 143 #define H_RVERS 16 /* "Report-Version:" */ 144 #define H_STATUS 17 /* "Status:" */ 145 #define H_SUBJ 18 /* "Subject:" */ 146 #define H_TO 19 /* "To:" */ 147 #define H_TCOPY 20 /* ">To:" */ 148 #define H_TROPTS 21 /* "Transport-Options:" */ 149 #define H_UAID 22 /* "UA-Content-ID:" */ 150 #define H_DAFWDFROM 23 /* Hold A-F-F when sending Del. Notf. */ 151 #define H_DTCOPY 24 /* Hold ">To:" when sending Del. Notf.*/ 152 #define H_DRECEIVED 25 /* Hold Rcvd: when sending Del. Notf.*/ 153 #define H_CONT 26 /* Continuation of previous line */ 154 #define H_NAMEVALUE 27 /* unrecognized "name: value" hdr line*/ 155 156 /* 157 * Format of the command description table. 158 * The actual table is declared and initialized 159 * in lex.c 160 */ 161 162 struct cmd { 163 char *c_name; /* Name of command */ 164 int (*c_func)(void *); /* Implementor of the command */ 165 short c_argtype; /* Type of arglist (see below) */ 166 short c_msgflag; /* Required flags of messages */ 167 short c_msgmask; /* Relevant flags of messages */ 168 }; 169 170 /* can't initialize unions */ 171 172 #define c_minargs c_msgflag /* Minimum argcount for RAWLIST */ 173 #define c_maxargs c_msgmask /* Max argcount for RAWLIST */ 174 175 /* 176 * Argument types. 177 */ 178 179 #define MSGLIST 0 /* Message list type */ 180 #define STRLIST 1 /* A pure string */ 181 #define RAWLIST 2 /* Shell string list */ 182 #define NOLIST 3 /* Just plain 0 */ 183 #define NDMLIST 4 /* Message list, no defaults */ 184 185 #define P 040 /* Autoprint dot after command */ 186 #define I 0100 /* Interactive command bit */ 187 #define M 0200 /* Legal from send mode bit */ 188 #define W 0400 /* Illegal when read only bit */ 189 #define F 01000 /* Is a conditional command */ 190 #define T 02000 /* Is a transparent command */ 191 #define R 04000 /* Cannot be called from collect */ 192 193 /* 194 * Oft-used mask values 195 */ 196 197 #define MMNORM (MDELETED|MSAVED)/* Look at both save and delete bits */ 198 #define MMNDEL MDELETED /* Look only at deleted bit */ 199 200 /* 201 * Structure used to return a break down of a head 202 * line 203 */ 204 205 struct headline { 206 char *l_from; /* The name of the sender */ 207 char *l_tty; /* His tty string (if any) */ 208 char *l_date; /* The entire date string */ 209 }; 210 211 #define GTO 1 /* Grab To: line */ 212 #define GSUBJECT 2 /* Likewise, Subject: line */ 213 #define GCC 4 /* And the Cc: line */ 214 #define GBCC 8 /* And also the Bcc: line */ 215 #define GDEFOPT 16 /* And the Default-Options: lines */ 216 #define GNL 32 /* Print blank line after */ 217 #define GOTHER 64 /* Other header lines */ 218 #define GMASK (GTO|GSUBJECT|GCC|GBCC|GDEFOPT|GNL|GOTHER) 219 /* Mask of all header lines */ 220 #define GDEL 128 /* Entity removed from list */ 221 #define GCLEN 256 /* Include Content-Length header */ 222 223 /* 224 * Structure used to pass about the current 225 * state of the user-typed message header. 226 */ 227 228 struct header { 229 char *h_to; /* Dynamic "To:" string */ 230 char *h_subject; /* Subject string */ 231 char *h_cc; /* Carbon copies string */ 232 char *h_bcc; /* Blind carbon copies */ 233 char *h_defopt; /* Default options */ 234 char **h_others; /* Other header lines */ 235 int h_seq; /* Sequence for optimization */ 236 }; 237 238 /* 239 * Structure of namelist nodes used in processing 240 * the recipients of mail and aliases and all that 241 * kind of stuff. 242 */ 243 244 struct name { 245 struct name *n_flink; /* Forward link in list. */ 246 struct name *n_blink; /* Backward list link */ 247 short n_type; /* From which list it came */ 248 char *n_name; /* This fella's name */ 249 char *n_full; /* Full name */ 250 }; 251 252 /* 253 * Structure of a variable node. All variables are 254 * kept on a singly-linked list of these, rooted by 255 * "variables" 256 */ 257 258 struct var { 259 struct var *v_link; /* Forward link to next variable */ 260 char *v_name; /* The variable's name */ 261 char *v_value; /* And it's current value */ 262 }; 263 264 struct mgroup { 265 struct mgroup *ge_link; /* Next person in this group */ 266 char *ge_name; /* This person's user name */ 267 }; 268 269 struct grouphead { 270 struct grouphead *g_link; /* Next grouphead in list */ 271 char *g_name; /* Name of this group */ 272 struct mgroup *g_list; /* Users in group. */ 273 }; 274 275 #define NIL ((struct name *) 0) /* The nil pointer for namelists */ 276 #define NONE ((struct cmd *) 0) /* The nil pointer to command tab */ 277 #define NOVAR ((struct var *) 0) /* The nil pointer to variables */ 278 #define NOGRP ((struct grouphead *) 0)/* The nil grouphead pointer */ 279 #define NOGE ((struct mgroup *) 0) /* The nil group pointer */ 280 #define NOFP ((struct fplst *) 0) /* The nil file pointer */ 281 282 #define TRUE 1 283 #define FALSE 0 284 285 #define DEADPERM 0600 /* permissions of dead.letter */ 286 #define TEMPPERM 0600 /* permissions of temp files */ 287 #define MBOXPERM 0600 /* permissions of ~/mbox */ 288 289 #ifndef MFMODE 290 # define MFMODE 0600 /* create mode for `/var/mail' files */ 291 #endif 292 293 /* 294 * Structure of the hash table of ignored header fields 295 */ 296 struct ignore { 297 struct ignore *i_link; /* Next ignored field in bucket */ 298 char *i_field; /* This ignored field */ 299 }; 300 301 #ifdef preSVr4 302 struct utimbuf { 303 time_t actime; 304 time_t modtime; 305 }; 306 #else 307 # include <utime.h> 308 #endif 309 310 /* 311 * Token values returned by the scanner used for argument lists. 312 * Also, sizes of scanner-related things. 313 */ 314 315 #define TEOL 0 /* End of the command line */ 316 #define TNUMBER 1 /* A message number */ 317 #define TDASH 2 /* A simple dash */ 318 #define TSTRING 3 /* A string (possibly containing -) */ 319 #define TDOT 4 /* A "." */ 320 #define TUP 5 /* An "^" */ 321 #define TDOLLAR 6 /* A "$" */ 322 #define TSTAR 7 /* A "*" */ 323 #define TOPEN 8 /* An '(' */ 324 #define TCLOSE 9 /* A ')' */ 325 #define TPLUS 10 /* A '+' */ 326 327 #define REGDEP 2 /* Maximum regret depth. */ 328 #define STRINGLEN 1024 /* Maximum length of string token */ 329 330 /* 331 * Constants for conditional commands. These describe whether 332 * we should be executing stuff or not. 333 */ 334 335 #define CANY 0 /* Execute in send or receive mode */ 336 #define CRCV 1 /* Execute in receive mode only */ 337 #define CSEND 2 /* Execute in send mode only */ 338 #define CTTY 3 /* Execute if attached to a tty only */ 339 #define CNOTTY 4 /* Execute if not attached to a tty */ 340 341 /* 342 * Flags for msend(). 343 */ 344 345 #define M_IGNORE 1 /* Do "ignore/retain" processing */ 346 #define M_SAVING 2 /* Saving to a file/folder */ 347 348 /* 349 * VM/UNIX has a vfork system call which is faster than forking. If we 350 * don't have it, fork(2) will do . . . 351 */ 352 353 #if !defined(VMUNIX) && defined(preSVr4) 354 #define vfork() fork() 355 #endif 356 #ifndef SIGRETRO 357 #define sigchild() 358 #endif 359 360 361 /* 362 * 4.2bsd signal interface help... 363 */ 364 #ifdef VMUNIX 365 #define sigset(s, a) signal(s, a) 366 #define sigsys(s, a) signal(s, a) 367 #else 368 #ifndef preSVr4 369 /* SVr4 version of sigset() in fio.c */ 370 #define sigsys(s, a) signal(s, a) 371 #define setjmp(x) sigsetjmp((x), 1) 372 #define longjmp siglongjmp 373 #define jmp_buf sigjmp_buf 374 #else 375 #define OLD_BSD_SIGS 376 #endif 377 #endif 378 379 /* 380 * Truncate a file to the last character written. This is 381 * useful just before closing an old file that was opened 382 * for read/write. 383 */ 384 #define trunc(stream) ftruncate(fileno(stream), (long) ftell(stream)) 385 386 /* 387 * The pointers for the string allocation routines, 388 * there are NSPACE independent areas. 389 * The first holds STRINGSIZE bytes, the next 390 * twice as much, and so on. 391 */ 392 393 #define NSPACE 25 /* Total number of string spaces */ 394 struct strings { 395 char *s_topFree; /* Beginning of this area */ 396 char *s_nextFree; /* Next alloctable place here */ 397 unsigned s_nleft; /* Number of bytes left here */ 398 }; 399 400 /* The following typedefs must be used in SVR4 */ 401 #ifdef preSVr4 402 #ifndef sun 403 typedef int gid_t; 404 typedef int uid_t; 405 typedef int mode_t; 406 typedef int pid_t; 407 #endif 408 #endif 409 410 #define STSIZ 40 411 #define TMPSIZ 14 412 /* 413 * Forward declarations of routine types to keep lint and cc happy. 414 */ 415 416 extern int Copy(int *msgvec); 417 extern FILE *Fdopen(int fildes, char *mode); 418 extern int Followup(int *msgvec); 419 extern char *Getf(register char *s); 420 extern int More(int *msgvec); 421 extern int Respond(int *msgvec); 422 extern int Save(int *msgvec); 423 extern int Sendm(char *str); 424 extern int Sput(char str[]); 425 extern int Type(int *msgvec); 426 extern void Verhogen(void); 427 extern char *addone(char hf[], char news[]); 428 extern char *addto(char hf[], char news[]); 429 extern void alter(char name[]); 430 extern int alternates(char **namelist); 431 extern void announce(void); 432 extern int any(int ch, char *str); 433 extern int anyof(register char *s1, register char *s2); 434 extern int argcount(char **argv); 435 extern void assign(char name[], char value[]); 436 extern int blankline(const char linebuf[]); 437 extern struct name *cat(struct name *n1, struct name *n2); 438 extern FILE *collect(struct header *hp); 439 extern void commands(void); 440 extern char *copy(char *str1, char *str2); 441 extern int copycmd(char str[]); 442 extern int deassign(register char *s); 443 extern int delm(int *msgvec); 444 extern struct name *delname(register struct name *np, char name[]); 445 extern int deltype(int msgvec[]); 446 extern char *detract(register struct name *np, int ntype); 447 extern int docomma(char *s); 448 extern int dopipe(char str[]); 449 extern int dosh(char *str); 450 extern int echo(register char **argv); 451 extern int editor(int *msgvec); 452 extern int edstop(int noremove); 453 extern struct name *elide(struct name *names); 454 extern int elsecmd(void); 455 extern int endifcmd(void); 456 extern int execute(char linebuf[], int contxt); 457 extern char *expand(char *name); 458 extern struct name *extract(char line[], int arg_ntype); 459 extern int fferror(FILE *iob); 460 extern int field(char str[]); 461 extern int file(char **argv); 462 extern struct grouphead *findgroup(char name[]); 463 extern void findmail(char *name); 464 extern int first(int f, int m); 465 extern void flush(void); 466 extern int folders(char **arglist); 467 extern int followup(int *msgvec); 468 extern int from(int *msgvec); 469 extern off_t fsize(FILE *iob); 470 extern int getfold(char *name); 471 extern int gethfield(register FILE *f, char linebuf[], register long rem); 472 extern int getline(char *line, int size, FILE *f, int *hasnulls); 473 extern int getmsglist(char *buf, int *vector, int flags); 474 extern int getname(uid_t uid, char namebuf[]); 475 extern int getrawlist(char line[], char **argv, int argc); 476 extern void getrecf(char *buf, char *recfile, int useauthor, int sz_recfile); 477 extern uid_t getuserid(char name[]); 478 extern int grabh(register struct header *hp, int gflags, int subjtop); 479 extern int group(char **argv); 480 extern void hangup(int); 481 extern int hash(char name[]); 482 extern char *hcontents(char hfield[]); 483 extern int headerp(register char *line); 484 extern int headers(int *msgvec); 485 extern int help(void); 486 extern char *helppath(char *file); 487 extern char *hfield(char field[], struct message *mp, char *(*add)(char *, char *)); 488 extern void holdsigs(void); 489 extern int icequal(register char *s1, register char *s2); 490 extern int ifcmd(char **argv); 491 extern int igfield(char *list[]); 492 extern int inc(void); 493 extern void inithost(void); 494 extern int isdir(char name[]); 495 extern int ishead(char linebuf[]); 496 extern int ishfield(char linebuf[], char field[]); 497 extern int ishost(char *sys, char *rest); 498 extern int isign(char *field, int saving); 499 extern void istrcpy(char *dest, int dstsize, char *src); 500 extern void lcwrite(char *fn, FILE *fi, FILE *fo, int addnl); 501 extern void load(char *name); 502 extern int loadmsg(char str[]); 503 extern int lock(FILE *fp, char *mode, int blk); 504 extern void lockmail(void); 505 extern int mail(char **people); 506 extern void mail1(struct header *hp, int use_to, char *orig_to); 507 extern void mapf(register struct name *np, char *from); 508 extern int mboxit(int msgvec[]); 509 extern void mechk(struct name *names); 510 extern int member(register char *realfield, register struct ignore **table); 511 extern int messize(int *msgvec); 512 extern void minit(void); 513 extern int more(int *msgvec); 514 extern long msend(struct message *mailp, FILE *obuf, int flag, int (*fp)(const char *, FILE *)); 515 extern int my_fclose(register FILE *iop); 516 extern FILE *my_fopen(char *file, char *mode); 517 extern char *nameof(register struct message *mp); 518 extern char *netmap(char name[], char from[]); 519 extern int newfileinfo(int start); 520 extern int next(int *msgvec); 521 extern int npclose(FILE *ptr); 522 extern FILE *npopen(char *cmd, char *mode); 523 extern char *nstrcpy(char *dst, int dstsize, char *src); 524 extern char *nstrcat(char *dst, int dstsize, char *src); 525 extern int null(char *e); 526 extern int outof(struct name *names, FILE *fo); 527 extern struct name *outpre(struct name *to); 528 extern void panic(char *str); 529 extern void parse(char line[], struct headline *hl, char pbuf[]); 530 extern int pcmdlist(void); 531 extern int pdot(void); 532 extern int preserve(int *msgvec); 533 extern void printgroup(char name[]); 534 extern void printhead(int mesg); 535 extern int puthead(struct header *hp, FILE *fo, int w, long clen); 536 extern int pversion(char *e); 537 extern void quit(int noremove); 538 extern int readline(FILE *ibuf, char *linebuf); 539 extern void receipt(struct message *mp); 540 extern void relsesigs(void); 541 extern int removefile(char name[]); 542 extern int replyall(int *msgvec); 543 extern int replysender(int *msgvec); 544 extern int respond(int *msgvec); 545 extern int retfield(char *list[]); 546 extern int rexit(int e); 547 extern char *safeexpand(char name[]); 548 extern void *salloc(unsigned size); 549 extern void *srealloc(void *optr, unsigned size); 550 extern int samebody(register char *user, register char *addr, 551 int fuzzy); 552 extern int save(char str[]); 553 extern void savedead(int s); 554 extern char *savestr(char *str); 555 extern int schdir(char *str); 556 extern int screensize(void); 557 extern int scroll(char arg[]); 558 extern int sendm(char *str); 559 extern int set(char **arglist); 560 extern void setclen(register struct message *mp); 561 extern int setfile(char *name, int isedit); 562 extern FILE *setinput(register struct message *mp); 563 extern void setptr(register FILE *ibuf); 564 extern int shell(char *str); 565 #ifndef sigchild 566 extern void sigchild(void); 567 #endif 568 #ifndef sigset 569 extern void (*sigset())(); 570 #endif 571 extern char *skin(char *name); 572 extern char *snarf(char linebuf[], int *flag, int erf); 573 extern int source(char name[]); 574 extern char *splice(char *addr, char *hdr); 575 extern int sput(char str[]); 576 extern void sreset(void); 577 extern void stop(int s); 578 extern int stouch(int msgvec[]); 579 extern int substr(char *string1, char *string2); 580 extern int swrite(char str[]); 581 extern struct name *tailof(struct name *name); 582 extern void tinit(void); 583 extern int tmail(void); 584 extern int top(int *msgvec); 585 extern void touch(int mesg); 586 extern struct name *translate(struct name *np); 587 extern int type(int *msgvec); 588 extern int undelete(int *msgvec); 589 extern int ungroup(char **argv); 590 extern int unigfield(char *list[]); 591 extern void unlockmail(void); 592 extern char **unpack(struct name *np); 593 extern int unread(int msgvec[]); 594 extern int unretfield(char *list[]); 595 extern int unset(char **arglist); 596 extern int unstack(void); 597 extern char *unuucp(char *name); 598 extern struct name *usermap(struct name *names); 599 extern char *value(char name[]); 600 extern char *vcopy(char str[]); 601 extern void vfree(register char *cp); 602 extern int visual(int *msgvec); 603 extern char *yankword(char *name, char *word, int sz, int comma); 604 605 /* 606 * These functions are defined in libmail.a 607 */ 608 #ifdef __cplusplus 609 extern "C" { 610 #endif 611 extern int delempty(mode_t, char *); 612 extern char *maildomain(void); 613 extern void touchlock(void); 614 extern char *xgetenv(char *); 615 extern int xsetenv(char *); 616 #ifdef __cplusplus 617 } 618 #endif 619 620 /* 621 * Standard functions from the C library. 622 * These are all defined in <stdlib.h> and <wait.h> in SVr4. 623 */ 624 #ifdef preSVr4 625 extern long atol(); 626 extern char *getcwd(); 627 extern char *calloc(); 628 extern char *getenv(); 629 extern void exit(); 630 extern void free(); 631 extern char *malloc(); 632 extern time_t time(); 633 extern long ulimit(); 634 extern int utime(); 635 extern int wait(); 636 extern int fputs(); 637 #endif 638 639 #ifdef __cplusplus 640 } 641 #endif 642 643 #endif /* _MAILX_DEF_H */ 644