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