Annotation of coherent/a/tmp/smail/main.c, revision 1.1

1.1     ! root        1: /*
        !             2: **
        !             3: **  rmail/smail - UUCP mailer with automatic routing.
        !             4: **
        !             5: **  Christopher Seiwald                /+\
        !             6: **  [email protected]       +\
        !             7: **  January, 1985              \+/
        !             8: **
        !             9: */
        !            10: 
        !            11: #ifndef lint
        !            12: static char    *sccsid="@(#)main.c     2.5 (smail) 9/15/87";
        !            13: #endif
        !            14: 
        !            15: /*
        !            16: **
        !            17: **  usage:     rmail [options] address...
        !            18: **             smail [options] address...
        !            19: **  options:
        !            20: **             -d              debug - verbose and don't invoke mailers.
        !            21: **             -v              verbose - just verbose.
        !            22: **             -A              print mapped addresses.  don't invoke mailers.
        !            23: **             -h hostname     set hostname 
        !            24: **             -H hostdomain   set hostdomain (default hostname.MYDOM)
        !            25: **             -p pathfile     path database filename
        !            26: **             -r              force routing of host!address
        !            27: **             -R              reroute even explicit path!user
        !            28: **             -l              user@domain goes to local mailer
        !            29: **             -L              all mail goes local
        !            30: **             -q number       mail queueing cost threshold
        !            31: **             -m number       limit on number of uux_noqueue jobs
        !            32: **             -u string       string of flags for uux
        !            33: **              -F address      name to substitute in From: line
        !            34: **             -a aliasfile    aliases filename (not used with SENDMAIL)
        !            35: **             -n namelist     list of full names for simple aliases
        !            36: */
        !            37: 
        !            38: #include       <stdio.h>
        !            39: #include       <ctype.h>
        !            40: #include       "defs.h"
        !            41: 
        !            42: void close_fds();
        !            43: 
        !            44: int exitstat = 0;              /* exit status, set by resolve, deliver */
        !            45: 
        !            46: enum edebug debug     = NO;    /* set by -d or -v option               */
        !            47: enum ehandle handle   = HANDLE;        /* which mail we can handle, see defs.h */
        !            48: enum erouting routing = ROUTING;/* to route or not to route, see defs.h */
        !            49: 
        !            50: char hostname[SMLBUF]   = "";  /* set by -h, defaults in defs.h        */
        !            51: char hostdomain[SMLBUF] = "";  /* set by -H, defaults in defs.h        */
        !            52: char hostuucp[SMLBUF] = "";    /* built with hostname+".UUCP"          */
        !            53: 
        !            54: char *pathfile  = PATHS;       /* or set by -p                         */
        !            55: char *uuxargs   = NULL;                /* or set by -u                         */
        !            56: 
        !            57: char *aliasfile =
        !            58: #ifdef ALIAS
        !            59:                ALIAS;          /* or set by -a                         */
        !            60: #else
        !            61:                NULL;
        !            62: #endif
        !            63: 
        !            64: #ifdef HOMEALIASES
        !            65: char *homealias;
        !            66: #endif
        !            67: 
        !            68: char *fnlist    =
        !            69: #ifdef FULLNAME
        !            70:                FULLNAME;       /* or set by -n                         */
        !            71: #else
        !            72:                NULL;
        !            73: #endif
        !            74: 
        !            75: int  queuecost  = QUEUECOST;   /* or set by -q                         */
        !            76: char *from_addr = NULL;                /* or set by -F                         */
        !            77: int  maxnoqueue = MAXNOQUEUE;  /* or set by -m                         */
        !            78: 
        !            79: int  getcost    = 
        !            80: #ifdef GETCOST
        !            81:                1;      /* get cost of path even if not routing */
        !            82: #else
        !            83:                0;
        !            84: #endif
        !            85: 
        !            86: char *spoolfile = NULL;                /* name of the file containing letter   */
        !            87: FILE *spoolfp;                 /* file pointer to spoolfile            */
        !            88: int  spoolmaster = 0;          /* indicates 'control' of spoolfile     */
        !            89: 
        !            90: void spool();
        !            91: 
        !            92: 
        !            93: /*
        !            94: **
        !            95: **  rmail/smail: mail stdin letter to argv addresses.
        !            96: **
        !            97: **  After processing command line options and finding our host and domain 
        !            98: **  names, we map addresses into <host,user,form,cost> sets.  Then we deliver.
        !            99: **
        !           100: */
        !           101: 
        !           102: main(argc, argv)
        !           103: int argc;
        !           104: char *argv[];
        !           105: {
        !           106:        char *hostv[MAXARGS];           /* UUCP neighbor                */
        !           107:        char *userv[MAXARGS];           /* address given to host        */
        !           108:        int  costv[MAXARGS];            /* cost of resolved route       */
        !           109:        enum eform formv[MAXARGS];      /* invalid, local, or uucp      */
        !           110:        char *p;
        !           111:        int c;
        !           112:        int  printaddr  = 0;            /* or set by -A                 */
        !           113:        int nargc;
        !           114:        char **nargv, **alias();
        !           115: 
        !           116:        char *optstr = "cdvArRlLH:h:p:u:q:a:n:m:f:F:";
        !           117:        extern char *optarg;
        !           118:        extern int optind;
        !           119: 
        !           120:        /* Clean up any open file descriptors which may have been
        !           121:           dumped on us.
        !           122:        */
        !           123:        (void) close_fds();
        !           124: 
        !           125: /*
        !           126: **  see if we aren't invoked as rmail
        !           127: */
        !           128:        if((p = rindex(argv[0], '/')) == NULL) {
        !           129:                p = argv[0];
        !           130:        } else {
        !           131:                p++;
        !           132:        }
        !           133: 
        !           134:        if(*p != 'r' ) {
        !           135:                handle = ALL;
        !           136:        }
        !           137: 
        !           138: /*
        !           139: **  Process command line arguments
        !           140: */
        !           141:        while ((c = getopt(argc, argv, optstr)) != EOF) {
        !           142:                switch ( c ) {
        !           143:                case 'd': debug      = YES;             break;
        !           144:                case 'v': debug      = VERBOSE;         break; 
        !           145:                case 'A': printaddr  = 1;               break; 
        !           146:                case 'F': from_addr  = optarg;          break;
        !           147:                case 'r': routing    = ALWAYS;          break;
        !           148:                case 'R': routing    = REROUTE;         break;
        !           149:                case 'l': handle     = JUSTUUCP;        break;
        !           150:                case 'L': handle     = NONE;            break;
        !           151:                case 'f': spoolfile  = optarg;          break;
        !           152:                case 'p': pathfile   = optarg;          break;
        !           153:                case 'u': uuxargs    = optarg;          break;
        !           154:                case 'a': aliasfile  = optarg;          break;
        !           155:                case 'n': fnlist     = optarg;          break;
        !           156:                case 'H': (void) strcpy(hostdomain, optarg);    break;
        !           157:                case 'h': (void) strcpy(hostname, optarg);      break;
        !           158:                case 'm': if(isdigit(*optarg)) {
        !           159:                                  maxnoqueue = atoi(optarg);
        !           160:                          }
        !           161:                          break;
        !           162:                case 'c': getcost     = 1;              break;
        !           163:                case 'q': if(isdigit(*optarg)) {
        !           164:                                  queuecost = atoi(optarg);
        !           165:                          }
        !           166:                          break;
        !           167:                default:
        !           168:                        error( EX_USAGE, "valid flags are %s\n", optstr);
        !           169:                }
        !           170:        }
        !           171:        if ( argc <= optind ) {
        !           172:                error( EX_USAGE, "usage: %s [flags] address...\n", argv[0] );
        !           173:        }
        !           174: 
        !           175: /*
        !           176: **  Get our default hostname and hostdomain.
        !           177: */
        !           178:        getmynames();
        !           179: 
        !           180: /*
        !           181: **  Spool the letter in a temporary file.
        !           182: */
        !           183:        nargc = argc - optind;
        !           184:        if(printaddr == 0) {
        !           185:                spool(nargc, &argv[optind]);
        !           186:        }
        !           187: 
        !           188: /*
        !           189: ** Do aliasing and fullname resolution
        !           190: */
        !           191:        nargv = alias(&nargc, &argv[optind]);
        !           192: 
        !           193: /*
        !           194: **  Map argv addresses to <host, user, form, cost>.
        !           195: */
        !           196:        map(nargc, nargv, hostv, userv, formv, costv);
        !           197: /*
        !           198: **  If all we want it mapped addresses, print them and exit.
        !           199: */
        !           200:        if(printaddr) {
        !           201:                int i;
        !           202:                char abuf[SMLBUF];
        !           203:                for(i=nargc-1; i >= 0; i--) {
        !           204:                        if(formv[i] == ERROR) {
        !           205:                                (void) strcpy(abuf, nargv[i]);
        !           206:                        } else {
        !           207:                                build(hostv[i], userv[i], formv[i], abuf);
        !           208:                        }
        !           209:                        (void) fputs(abuf, stdout);
        !           210:                        if(i != 0) (void) putchar(' ');
        !           211:                }
        !           212:                (void) putchar('\n');
        !           213:                exit(0);
        !           214:        }
        !           215: /*
        !           216: **  Deliver.
        !           217: */
        !           218:        deliver(nargc, hostv, userv, formv, costv);
        !           219: /*
        !           220: **  Exitstat was set if any resolve or deliver failed, otherwise 0.
        !           221: */
        !           222:        return( exitstat );
        !           223: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.