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