checkmail (a cute little mailchecking utility)

Scott Mesches mesches at sunybcs.UUCP
Mon Aug 4 10:50:43 AEST 1986


CHECKMAIL(1)     Local UNIX Programmer's Manual      CHECKMAIL(1)



NAME
     checkmail - check the status of your and others mail

SYNOPSIS
     checkmail [ -q ] [ user ... ]

DESCRIPTION
     checkmail tells whether you have, mail (old mail), new mail,
     no mail, or no mailbox on the machine it is executed on.

     By default, checkmail only reports the status of your mail-
     box, it returns a status of one if you have new mail and
     zero otherwise.  If you specify a list of users, it tells
     you the state of their mailbox(s).

     If you have a .hushlogin file, it defeats mail checking on
     login.  This program can then be used to re-instate this. It
     can also check your mail on login, and if you have new mail
     start up a mail job in the background with the following in
     your .login file.

          checkmail
          if ($status != 0) then
               mail &
          endif

     with the -q option, checkmail is quiet, has no output but
     still sets the status flag.

BUGS
     biff if the user is logged in and they have biff set to y,
     the status returned will be that of old mail.

     from If the user executes the command "from" it will also
     appear as old mail.

SEE ALSO
     chtim(1), stat(2), biff(1), from(1)

AUTHOR
     Scott Mesches

# This is a shell archive.  Remove anything before this line, then
# unpack it by saving it in a file and typing "sh file".  (Files
# unpacked will be owned by you and have default permissions.)
#
# This archive contains:
# checkmail.1 checkmail.c

echo x - checkmail.1
sed -e 's/^X//' > "checkmail.1" << '//E*O*F checkmail.1//'
X.TH CHECKMAIL 1 "15 July 1986" "" "Local UNIX Programmer's Manual"
X.SH NAME
Xcheckmail \- check the status of your and others mail
X.SH SYNOPSIS
X.B checkmail 
X[
X-q
X] [
Xuser ...  
X]
X.SH DESCRIPTION
Xcheckmail tells whether you have, mail (old mail), new mail, no mail,
Xor no mailbox on the machine it is executed on.
X.PP
XBy default,
X.I checkmail
Xonly reports the status of your mailbox, it returns a status of one
Xif you have 
X.I "new mail"
Xand zero otherwise.
XIf you specify a list of users, it tells you
Xthe state of their mailbox(s).
X.PP
XIf you have a .hushlogin file, it defeats mail checking on login.
XThis program can then be used to re-instate this. It can also check 
Xyour mail on login, and if you have new mail start up a mail job 
Xin the background with the following in your
X.I .login 
Xfile.
X
X.nf
X	checkmail
X	if ($status != 0) then
X		mail &
X	endif
X.fi
X.PP
Xwith the -q option, checkmail is quiet, has no output but still 
Xsets the status flag.
X.SH BUGS
X.I biff
Xif the user is logged in and they have biff set to y, the status 
Xreturned will be that of old mail.
X.PP
X.I from
XIf the user executes the command "from" it will also appear as old mail.
X.SH "SEE ALSO"
Xchtim(1), stat(2), biff(1), from(1)
X.SH AUTHOR
XScott Mesches
//E*O*F checkmail.1//

echo x - checkmail.c
sed -e 's/^X//' > "checkmail.c" << '//E*O*F checkmail.c//'
X#ifndef lint
Xstatic char *sccsid = "@(#)checkmail.c	1.4 (Scott Mesches) 7/18/86";
X#endif
X
X/*
X * checkmail  -- Mail checker for me and other folks.
X * 		Returns a status of one for new mail, zero otherwise.
X * 		-q option supresses output and only affects status.
X * Usage: checkmail [ -q ] [ name... ]
X */
X
X#include <stdio.h>
X#include <pwd.h>
X#include <sys/types.h>
X#include <sys/stat.h>
X
X#define	MAILDIR	"/usr/spool/mail"
X#define	TRUE	1
X#define	FALSE	0
X
Xmain (argc, argv)
Xint     argc;
Xchar   *argv[];
X{
X	int     i, qflag = FALSE;
X	struct passwd  *getpwuid (), *pwd;
X
X	if (argc == 1) {
X		if ((pwd = getpwuid (getuid ())) == NULL) {
X			perror (*argv);
X			exit (1);
X		}
X		printf ("You have ");
X		exit (status (pwd -> pw_name,qflag));
X	}
X	else {
X		if (*argv[1] == '-') {
X			if (!strcmp("-q",argv[1])) {
X				qflag = TRUE;
X				if ((pwd = getpwuid (getuid ())) == NULL) {
X					perror (*argv);
X					exit (1);
X				}
X				(void)status (pwd -> pw_name,qflag);
X			}
X			else
X				fprintf(stderr,"Usage: %s [ -q ] [ user ... ]\n", argv[0]);
X		}
X		else
X			for (i = 1; i < argc; i++) {
X				printf ("%s has ", argv[i]);
X				(void)status (argv[i],qflag);
X		}
X	}
X}
X
Xstatus (name,flag)
Xchar	*name;
Xint		flag;
X{
X    char    path[1024];
X    struct stat st;
X
X    (void) sprintf (path, "%s/%s", MAILDIR, name);
X    if (stat (path, &st)) {
X		if (flag == FALSE)
X			printf ("no mailbox.\n");
X		return (0);
X    }
X    if (st.st_size == 0) {
X		if (flag == FALSE)
X			printf ("no mail.\n");
X	}
X    else
X		if (st.st_mtime > st.st_atime) {
X			if (flag == FALSE)
X				printf ("new mail.\n");
X			return (1);
X		}
X		else
X			if (flag == FALSE)
X				printf ("mail.\n");
X	return(0);
X}
//E*O*F checkmail.c//

exit 0



More information about the Comp.sources.unix mailing list