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