Annotation of researchv10no/lbin/mailx/main.c, revision 1.1.1.1

1.1       root        1: #ident "@(#)main.c     1.6 'attmail mail(1) command'"
                      2: #ident "@(#)mailx:main.c       1.13.3.1"
                      3: /*     Copyright (c) 1984 AT&T */
                      4: /*       All Rights Reserved   */
                      5: 
                      6: /*     THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T     */
                      7: /*     The copyright notice above does not evidence any        */
                      8: /*     actual or intended publication of such source code.     */
                      9: 
                     10: #ident "@(#)mailx:main.c       1.13.1.2"
                     11: 
                     12: #include "rcv.h"
                     13: #ifndef preSVr4
                     14: #include <locale.h>
                     15: #endif
                     16: 
                     17: /*
                     18:  * mailx -- a modified version of a University of California at Berkeley
                     19:  *     mail program
                     20:  *
                     21:  * Startup -- interface with user.
                     22:  */
                     23: 
                     24: static void            hdrstop();
                     25: 
                     26: static jmp_buf hdrjmp;
                     27: 
                     28: /*
                     29:  * Find out who the user is, copy his mail file (if exists) into
                     30:  * /tmp/Rxxxxx and set up the message pointers.  Then, print out the
                     31:  * message headers and read user commands.
                     32:  *
                     33:  * Command line syntax:
                     34:  *     mailx [ -i ] [ -r address ] [ -h number ] [ -f [ name ] ]
                     35:  * or:
                     36:  *     mailx [ -i ] [ -r address ] [ -h number ] people ...
                     37:  *
                     38:  * and a bunch of other options.
                     39:  */
                     40: 
                     41: main(argc, argv)
                     42:        char **argv;
                     43: {
                     44:        register char *ef;
                     45:        register int argp;
                     46:        int mustsend, uflag, f, goerr = 0;
                     47:        void (*prevint)();
                     48: /*     struct termio tbuf;                                                     adb */
                     49:        int c;
                     50:        char *cwd, *mf;
                     51: 
                     52:        /*
                     53:         * Set up a reasonable environment.
                     54:         * Figure out whether we are being run interactively, set up
                     55:         * all the temporary files, buffer standard output, and so forth.
                     56:         */
                     57: 
                     58: #ifndef preSVr4
                     59:        /* (void)setlocale(LC_ALL, ""); */
                     60: #endif
                     61: #ifdef SIGCONT
                     62: # ifdef preSVr4
                     63:        sigset(SIGCONT, SIG_DFL);
                     64: # else
                     65:        {
                     66:        struct sigaction nsig;
                     67:        nsig.sa_handler = SIG_DFL;
                     68:        sigemptyset(&nsig.sa_mask);
                     69:        nsig.sa_flags = SA_RESTART;
                     70:        (void) sigaction(SIGCONT, &nsig, (struct sigaction*)0);
                     71:        }
                     72: # endif
                     73: #endif
                     74:        progname = argv[0];
                     75:        uflag = 0;
                     76:        myegid = getegid();
                     77:        myrgid = getgid();
                     78:        myeuid = geteuid();
                     79:        myruid = getuid();
                     80:        mypid = getpid();
                     81:        setgid(myrgid);
                     82:        setuid(myruid);
                     83:        inithost();
                     84:        intty = isatty(0);
                     85:        baud = getbaud();                                               /* adb */
                     86:        image = -1;
                     87: 
                     88:        /*
                     89:         * Now, determine how we are being used.
                     90:         * We successively pick off instances of -r, -h, -f, and -i.
                     91:         * If called as "rmail" we note this fact for letter sending.
                     92:         * If there is anything left, it is the base of the list
                     93:         * of users to mail to.  Argp will be set to point to the
                     94:         * first of these users.
                     95:         */
                     96: 
                     97:        ef = NOSTR;
                     98:        argp = -1;
                     99:        mustsend = 0;
                    100:        if (argc > 0 && **argv == 'r')
                    101:                rmail++;
                    102:        while ((c = getopt(argc, argv, "efFh:HinNr:s:u:UdIT:V")) != EOF)
                    103:                switch (c) {
                    104:                case 'e':
                    105:                        /*
                    106:                         * exit status only
                    107:                         */
                    108:                        exitflg++;
                    109:                        break;
                    110: 
                    111:                case 'r':
                    112:                        /*
                    113:                         * Next argument is address to be sent along
                    114:                         * to the mailer.
                    115:                         */
                    116:                        mustsend++;
                    117:                        rflag = optarg;
                    118:                        break;
                    119: 
                    120:                case 'T':
                    121:                        /*
                    122:                         * Next argument is temp file to write which
                    123:                         * articles have been read/deleted for netnews.
                    124:                         */
                    125:                        Tflag = optarg;
                    126:                        if ((f = creat(Tflag, TEMPPERM)) < 0) {
                    127:                                perror(Tflag);
                    128:                                exit(1);
                    129:                        }
                    130:                        close(f);
                    131:                        /* fall through for -I too */
                    132:                        /* FALLTHROUGH */
                    133: 
                    134:                case 'I':
                    135:                        /*
                    136:                         * print newsgroup in header summary
                    137:                         */
                    138:                        newsflg++;
                    139:                        break;
                    140: 
                    141:                case 'u':
                    142:                        /*
                    143:                         * Next argument is person to pretend to be.
                    144:                         */
                    145:                        uflag++;
                    146:                        strncpy(myname, optarg, PATHSIZE);
                    147:                        break;
                    148: 
                    149:                case 'i':
                    150:                        /*
                    151:                         * User wants to ignore interrupts.
                    152:                         * Set the variable "ignore"
                    153:                         */
                    154:                        assign("ignore", "");
                    155:                        break;
                    156:                
                    157:                case 'U':
                    158:                        UnUUCP++;
                    159:                        break;
                    160: 
                    161:                case 'd':
                    162:                        assign("debug", "");
                    163:                        break;
                    164: 
                    165:                case 'h':
                    166:                        /*
                    167:                         * Specified sequence number for network.
                    168:                         * This is the number of "hops" made so
                    169:                         * far (count of times message has been
                    170:                         * forwarded) to help avoid infinite mail loops.
                    171:                         */
                    172:                        mustsend++;
                    173:                        hflag = atoi(optarg);
                    174:                        if (hflag == 0) {
                    175:                                fprintf(stderr, "-h needs non-zero number\n");
                    176:                                goerr++;
                    177:                        }
                    178:                        break;
                    179: 
                    180:                case 's':
                    181:                        /*
                    182:                         * Give a subject field for sending from
                    183:                         * non terminal
                    184:                         */
                    185:                        mustsend++;
                    186:                        sflag = optarg;
                    187:                        break;
                    188: 
                    189:                case 'f':
                    190:                        /*
                    191:                         * User is specifying file to "edit" with mailx,
                    192:                         * as opposed to reading system mailbox.
                    193:                         * If no argument is given after -f, we read his/her
                    194:                         * $MBOX file or mbox in his/her home directory.
                    195:                         */
                    196:                        ef = (argc == optind || *argv[optind] == '-')
                    197:                                ? "" : argv[optind++];
                    198:                        if (*ef && *ef != '/' && *ef != '+')
                    199:                                cwd = getcwd(NOSTR, PATHSIZE);
                    200:                        break;
                    201: 
                    202:                case 'F':
                    203:                        Fflag++;
                    204:                        mustsend++;
                    205:                        break;
                    206: 
                    207:                case 'n':
                    208:                        /*
                    209:                         * User doesn't want to source
                    210:                         *      /etc/mail/mailx.rc
                    211:                         */
                    212:                        nosrc++;
                    213:                        break;
                    214: 
                    215:                case 'N':
                    216:                        /*
                    217:                         * Avoid initial header printing.
                    218:                         */
                    219:                        noheader++;
                    220:                        break;
                    221: 
                    222:                case 'H':
                    223:                        /*
                    224:                         * Print headers and exit
                    225:                         */
                    226:                        Hflag++;
                    227:                        break;
                    228: 
                    229:                case 'V':
                    230:                        puts(version);
                    231:                        return 0;
                    232: 
                    233:                case '?':
                    234:                default:
                    235:                        goerr++;
                    236:                        break;
                    237:                }
                    238: 
                    239:        if ( optind != argc )
                    240:                argp = optind;
                    241: 
                    242:        /*
                    243:         * Check for inconsistent arguments.
                    244:         */
                    245: 
                    246:        if (newsflg && ef==NOSTR) {
                    247:                fprintf(stderr, "Need -f with -I flag\n");
                    248:                goerr++;
                    249:        }
                    250:        if (ef != NOSTR && argp != -1) {
                    251:                fprintf(stderr, "Cannot give -f and people to send to.\n");
                    252:                goerr++;
                    253:        }
                    254:        if (exitflg && (mustsend || argp != -1))
                    255:                exit(1);        /* nonsense flags involving -e simply exit */
                    256:        if (mustsend && argp == -1) {
                    257:                fprintf(stderr, "The flags you gave are used only when sending mail.\n");
                    258:                goerr++;
                    259:        }
                    260:        if (goerr) {
                    261:                fprintf(stderr,"Usage: %s -eiIUdFnNHV -T FILE -u USER -h hops -r address -s SUBJECT -f FILE users\n", progname);
                    262:                exit(1);
                    263:        }
                    264:        tinit();
                    265:        input = stdin;
                    266:        rcvmode = argp == -1;
                    267:        if (!nosrc)
                    268:                load(MASTER);
                    269:        load(Getf("MAILRC"));
                    270:        check_environment();
                    271: 
                    272:        if (argp != -1) {
                    273:                mail(&argv[argp]);
                    274:                exit(senderr);
                    275:        }
                    276: 
                    277:        /*
                    278:         * Ok, we are reading mail.
                    279:         * Decide whether we are editing a mailbox or reading
                    280:         * the system mailbox, and open up the right stuff.
                    281:         */
                    282: 
                    283:        strcpy(origname, mailname);
                    284: 
                    285:        if (ef != NOSTR) {
                    286:                edit++;
                    287:                ef = *ef ? expand(ef) : Getf("MBOX");
                    288:                strcpy(origname, ef);
                    289:                if (ef[0] != '/') {
                    290:                        if (cwd == NOSTR)
                    291:                                cwd = getcwd(NOSTR, PATHSIZE);
                    292:                        strcat(cwd, "/");
                    293:                        strcat(cwd, ef);
                    294:                        ef = cwd;
                    295:                }
                    296:                strcpy(mailname, ef);
                    297:                editfile = ef;
                    298:        }
                    299: 
                    300:        if (setfile(mailname, edit) < 0)
                    301:                exit(1);
                    302: 
                    303:        if (msgCount > 0 && !noheader && value("header") != NOSTR) {
                    304:                if (setjmp(hdrjmp) == 0) {
                    305:                        if ((prevint = sigset(SIGINT, SIG_IGN)) != (void (*)())SIG_IGN) /* adb */
                    306:                                sigset(SIGINT, hdrstop);
                    307:                        announce();
                    308:                        fflush(stdout);
                    309:                        sigset(SIGINT, prevint);
                    310:                }
                    311:        }
                    312:        if (Hflag || (!edit && msgCount == 0)) {
                    313:                if (!Hflag)
                    314:                        fprintf(stderr, "No mail for %s\n", myname);
                    315:                fflush(stdout);
                    316:                exit(0);
                    317:        }
                    318:        commands();
                    319:        if (!edit) {
                    320:                sigset(SIGHUP, SIG_IGN);
                    321:                sigset(SIGINT, SIG_IGN);
                    322:                sigset(SIGQUIT, SIG_IGN);
                    323:                quit();
                    324:                Verhogen();
                    325:        }
                    326:        exit(0);
                    327:        /* NOTREACHED */
                    328: }
                    329: 
                    330: /*
                    331:  * Interrupt printing of the headers.
                    332:  */
                    333: static void
                    334: hdrstop()
                    335: {
                    336: 
                    337:        clrbuf(stdout);
                    338:        printf("\nInterrupt\n");
                    339:        fflush(stdout);
                    340:        sigrelse(SIGINT);
                    341:        longjmp(hdrjmp, 1);
                    342: }

unix.superglobalmegacorp.com

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