Annotation of 43BSDReno/contrib/mh/uip/msgchk.c, revision 1.1.1.1

1.1       root        1: /* msgchk.c - check for mail */
                      2: 
                      3: #include "../h/mh.h"
                      4: #include <stdio.h>
                      5: #include "../zotnet/mts.h"
                      6: #include "../zotnet/tws.h"
                      7: #include <sys/types.h>
                      8: #include <sys/stat.h>
                      9: #include <pwd.h>
                     10: 
                     11: /*  */
                     12: 
                     13: static struct swit switches[] = {
                     14: #define        HELPSW  0
                     15:     "help", 4,
                     16: 
                     17: #ifdef POP
                     18: #define        HOSTSW  1
                     19:     "host host", 0,
                     20: #define        USERSW  2
                     21:     "user user", 0,
                     22: 
                     23: #define        RPOPSW  3
                     24:     "rpop", 0,
                     25: #define        NRPOPSW 4
                     26:     "norpop", 0,
                     27: #endif POP
                     28: 
                     29: 
                     30:     NULL, NULL
                     31: };
                     32: 
                     33: /*  */
                     34: 
                     35: #define        NONEOK  0x0
                     36: #define        UUCPOLD 0x1
                     37: #define        UUCPNEW 0x2
                     38: #define        UUCPOK  (UUCPOLD | UUCPNEW)
                     39: #define        MMDFOLD 0x4
                     40: #define        MMDFNEW 0x8
                     41: #define        MMDFOK  (MMDFOLD | MMDFNEW)
                     42: 
                     43: 
                     44: #ifdef POP
                     45: int    snoop = 0;
                     46: #endif POP
                     47: 
                     48: 
                     49: #ifdef SYS5
                     50: struct passwd  *getpwuid(), *getpwnam();
                     51: #endif SYS5
                     52: 
                     53: /*  */
                     54: 
                     55: /* ARGSUSED */
                     56: 
                     57: main(argc, argv)
                     58:        int argc;
                     59:        char *argv[];
                     60: {
                     61:     int     vecp = 0;
                     62: #ifdef POP
                     63:     int            rpop = 1;
                     64: #endif POP
                     65:     char   *cp,
                     66: #ifdef POP
                     67:            *host = NULL,
                     68: #endif POP
                     69:             buf[80],
                     70:          **ap,
                     71:           **argp,
                     72:           *arguments[MAXARGS],
                     73:            *vec[50];
                     74:     struct passwd  *pw;
                     75: 
                     76:     invo_name = r1bindex (argv[0], '/');
                     77:     mts_init (invo_name);
                     78: #ifdef POP
                     79:     if (pophost && *pophost)
                     80:        host = pophost;
                     81:     if ((cp = getenv ("MHPOPDEBUG")) && *cp)
                     82:        snoop++;
                     83: #endif POP
                     84:     if ((cp = m_find (invo_name)) != NULL) {
                     85:        ap = brkstring (cp = getcpy (cp), " ", "\n");
                     86:        ap = copyip (ap, arguments);
                     87:     }
                     88:     else
                     89:        ap = arguments;
                     90:     (void) copyip (argv + 1, ap);
                     91:     argp = arguments;
                     92: 
                     93: /*  */
                     94: 
                     95:     while (cp = *argp++) {
                     96:        if (*cp == '-')
                     97:            switch (smatch (++cp, switches)) {
                     98:                case AMBIGSW: 
                     99:                    ambigsw (cp, switches);
                    100:                    done (1);
                    101:                case UNKWNSW: 
                    102:                    adios (NULLCP, "-%s unknown", cp);
                    103:                case HELPSW: 
                    104:                    (void) sprintf (buf, "%s [switches] [users ...]",
                    105:                            invo_name);
                    106:                    help (buf, switches);
                    107:                    done (1);
                    108: 
                    109: #ifdef POP
                    110:                case HOSTSW: 
                    111:                    if (!(host = *argp++) || *host == '-')
                    112:                        adios (NULLCP, "missing argument to %s", argp[-2]);
                    113:                    continue;
                    114:                case USERSW: 
                    115:                    if (!(cp = *argp++) || *cp == '-')
                    116:                        adios (NULLCP, "missing argument to %s", argp[-2]);
                    117:                    vec[vecp++] = cp;
                    118:                    continue;
                    119:                case RPOPSW: 
                    120:                    rpop++;
                    121:                    continue;
                    122:                case NRPOPSW: 
                    123:                    rpop = 0;
                    124:                    continue;
                    125: #endif POP
                    126:            }
                    127:        vec[vecp++] = cp;
                    128:     }
                    129: 
                    130: /*  */
                    131: 
                    132: #ifdef POP
                    133:     if (!*host)
                    134:        host = NULL;
                    135:     if (!host || !rpop)
                    136:        (void) setuid (getuid ());
                    137: #endif POP
                    138:     if (vecp == 0) {
                    139: #ifdef POP
                    140:        if (host)
                    141:            remotemail (host, NULLCP, rpop, 1);
                    142:        else
                    143: #endif POP
                    144:            if ((pw = getpwuid (getuid ())) == NULL)
                    145:                adios (NULLCP, "you lose");
                    146:            else
                    147:                checkmail (pw, 1);
                    148:     }
                    149:     else {
                    150:        vec[vecp] = NULL;
                    151: 
                    152:        for (vecp = 0; cp = vec[vecp]; vecp++)
                    153: #ifdef POP
                    154:            if (host)
                    155:                remotemail (host, cp, rpop, 0);
                    156:            else
                    157: #endif POP
                    158:                if (pw = getpwnam (cp))
                    159:                    checkmail (pw, 0);
                    160:                else
                    161:                    advise (NULLCP, "no such user as %s", cp);
                    162:     }
                    163: 
                    164:     done (0);
                    165: }
                    166: 
                    167: /*  */
                    168: 
                    169: checkmail(pw, personal)
                    170:        register struct passwd  *pw;
                    171:        int personal;
                    172: {
                    173:     int     mf;
                    174:     char    buffer[BUFSIZ];
                    175:     struct stat st;
                    176: 
                    177:     (void) sprintf (buffer, "%s/%s",
                    178:            mmdfldir[0] ? mmdfldir : pw -> pw_dir,
                    179:            mmdflfil[0] ? mmdflfil : pw -> pw_name);
                    180: #ifndef        MF
                    181:     st.st_size = 0;
                    182:     st.st_atime = st.st_mtime = 0;
                    183: #endif MF
                    184:     mf = (stat (buffer, &st) == NOTOK || st.st_size == 0) ? NONEOK
                    185:        : st.st_atime <= st.st_mtime ? MMDFNEW : MMDFOLD;
                    186: 
                    187: #ifdef MF
                    188:     if (umincproc != NULL && *umincproc != NULL) {
                    189:        (void) sprintf (buffer, "%s/%s",
                    190:                uucpldir[0] ? uucpldir : pw -> pw_dir,
                    191:                uucplfil[0] ? uucplfil : pw -> pw_name);
                    192:        mf |= (stat (buffer, &st) == NOTOK || st.st_size == 0) ? NONEOK
                    193:            : st.st_atime <= st.st_mtime ? UUCPNEW : UUCPOLD;
                    194:     }
                    195: #endif MF
                    196: 
                    197:     if ((mf & UUCPOK) || (mf & MMDFOK)) {
                    198:        printf (personal ? "You have " : "%s has ", pw -> pw_name);
                    199:        if (mf & UUCPOK)
                    200:            printf ("%s old-style bell", mf & UUCPOLD ? "old" : "new");
                    201:        if ((mf & UUCPOK) && (mf & MMDFOK))
                    202:            printf (" and ");
                    203:        if (mf & MMDFOK)
                    204:            printf ("%s%s", mf & MMDFOLD ? "old" : "new",
                    205:                mf & UUCPOK ? " Internet" : "");
                    206:        printf (" mail waiting");
                    207:     }
                    208:     else
                    209:        printf (personal ? "You don't %s%s" : "%s doesn't %s",
                    210:                personal ? "" : pw -> pw_name, "have any mail waiting");
                    211: 
                    212: #ifndef        MF
                    213:     if (st.st_atime)
                    214:        printf ("; last read on %s",
                    215:                dasctime (dlocaltime ((long *) & st.st_atime), TW_NULL));
                    216: #endif MF
                    217: 
                    218:     printf ("\n");
                    219: }
                    220: 
                    221: /*  */
                    222: 
                    223: #ifdef POP
                    224: extern char response[];
                    225: 
                    226: 
                    227: remotemail(host, user, rpop, personal)
                    228:        register char *host;
                    229:        char *user;
                    230:        int rpop, personal;
                    231: {
                    232:     int     nmsgs,
                    233:             nbytes;
                    234:     char   *pass;
                    235: 
                    236:     if (rpop) {
                    237:        if (user == NULL)
                    238:            user = getusr ();
                    239:        pass = getusr ();
                    240:     }
                    241:     else
                    242:        ruserpass (host, &user, &pass);
                    243: 
                    244:     if (pop_init (host, user, pass, snoop, rpop) == NOTOK
                    245:            || pop_stat (&nmsgs, &nbytes) == NOTOK
                    246:            || pop_quit () == NOTOK) {
                    247:        advise (NULLCP, "%s", response);
                    248:        return;
                    249:     }
                    250: 
                    251:     if (nmsgs) {
                    252:        printf (personal ? "You have " : "%s has ", user);
                    253:        printf ("%d message%s (%d bytes)",
                    254:                nmsgs, nmsgs != 1 ? "s" : "", nbytes);
                    255:     }
                    256:     else
                    257:        printf (personal ? "You don't %s%s" : "%s doesn't %s",
                    258:                personal ? "" : user, "have any mail waiting");
                    259:     printf (" on %s\n", host);
                    260: }
                    261: #endif POP
                    262: 
                    263: /*
                    264:  * XXX We need to force config.o to be linked in to get around
                    265:  * library order problems
                    266:  */
                    267: /* XXX don't bother if linking with the shared library */
                    268: #ifndef SHARED
                    269: static void
                    270: kludge()
                    271: {
                    272:        (void)libpath((char *)0);
                    273: }
                    274: #endif

unix.superglobalmegacorp.com

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