[comp.sys.next] Audio Mail Attention Signal

iansmith@kong.gatech.edu (Ian E. Smith) (03/29/90)

I noticed that a couple of people were commenting on the idea of having an
audio alert when you get new mail, similar to biff.  Well, I've hacked up 
this little bit of code that does the trick.   As I said before, its a hack,
so please don't flame me on it, or worse, run lint on it!

Its called sideways, and if you enter "sideways &" from the command line it
is enabled.  It wakes up about every 30 seconds (and you can hack this for
you desperate mail readers) and looks to see if you have received new mail. 
If you have, it plays the file /LocalLibrary/Sounds/mail.snd.  You can 
also enter "sideways <foo>.snd &" and sideways will play the file foo.snd
in that same directory.  

It attempts to validate that you are on the console when you try to run side-
ways, but it might become confused if you are on the console and then try to
rlogin from another machine and run it. 

The name? Why Sideways? Two reasons:
1) The dog biff at u.c. berkley.
2) The dog Sideways here at Ga. tech.
Any more questions?

May I suggest (with a relatively straight face) that you put a sound in your
LocalLibrary called sideways which is a dog barking.  Use that as your sound
for the program sideways for an extra dose of history.

To get it to run:
1) Extract this message to a file called "sideways.c" .
2) Use your editor to extract everything up to the dotted line.
3) type:  cc sideways.c -o sideways -lsys_s
     
Enjoy!     
Ian 

------------------------------8X Cut here X8-----------------------------------
/* 				Sideways       
			Audio Mail Attention Signal 
				  by
			       Ian Smith                                   
	         of The Software Engineering Research Center                 */

/* compile this program with the following command :
cc sideways.c -o sideways -lsys_s                                            */

/* to use this program type:
sideways <soundfile>  &

You must include the .snd extension on <soundfile>.  Also, if your NeXT has a
different directory setup than most, you might want to hack up the the MAILPATH
and SOUNDPATH defined below                                                  */

#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <pwd.h>
#include <utmp.h>

#define MAILPATH "/usr/spool/mail/"
#define SOUNDPATH "/LocalLibrary/Sounds/"
#define DEFAULTSOUND "mail.snd"
#define SLEEPTIME 30

/* this function determines if a user is on the console */
int ison_console(u)
	char *u;
{
	char name[9];
	FILE *users;
	struct utmp myutmp;

	name[8]='\0';
	users=fopen("/etc/utmp","r");
        if (users==NULL) return(-1);
	while (!(feof(users)))
	{
		fread(&myutmp,sizeof(myutmp),1,users);
		strncpy(name,myutmp.ut_name,8);
		if ((name[0]!='\0') && (strcmp(name,u)==0))
		{
			fclose(users);
			if (strncmp(myutmp.ut_line,"console",7)==0)         
				return(1);
			else return(-2);
		}
	}
	fclose(users);
	return(-1);
}

main (argc,argv)
	int argc;	
	char **argv;
{
	struct stat *buf;
	long oldtime;
	struct passwd user,*usr;
	char uname[9],mailfilename[30],soundfilename[80],mailsound[40];
	
	if (argc==1) 
		strcpy(mailsound,DEFAULTSOUND);
	else
		strcpy(mailsound,argv[1]);

	strcpy(mailfilename,MAILPATH);
	usr=&user;
	usr=getpwuid(getuid());
	uname[8]='\0';
        strcpy(uname,usr->pw_name);
	strcat(mailfilename,uname);
	if (ison_console(uname)!=1) 
	{
		printf("\n You must be on the console to use sideways. ");
		printf("\n From remote, use biff instead.\n");
		exit(1);
	}
	strcpy(soundfilename,SOUNDPATH);
	strcat(soundfilename,mailsound);
	buf=(struct stat *)malloc(sizeof(struct stat));
	stat("/usr/spool/mail/iansmith",buf);
	oldtime=buf->st_atime;
	while (1) 
	{
		stat(mailfilename,buf);
		if (buf->st_atime != oldtime) 
		{
			SNDPlaySoundfile(soundfilename,0);
			oldtime=buf->st_atime;
	        }
		sleep(SLEEPTIME) ;
	}
}

lacsap@mit-amt.MEDIA.MIT.EDU (Pascal Chesnais) (03/29/90)

and yet another alternative mail sound notification is on my system
which hacks up comsat... look on plethora.media.mit.edu (18.85.1.50)
pub dir for inspiration...

pasc
-- 
Pascal Chesnais, Research Specialist, Electronic Publishing Group
Media Laboratory, E15-348, 20 Ames Street, Cambridge, Ma, 02139 (617) 253-0311
email: lacsap@plethora.media.mit.edu (NeXT)