UNIX PC: email program to call favorite mailer when <MSG> is pressed.

Lenny Tropiano lenny at icus.islp.ny.us
Tue Oct 24 14:59:14 AEST 1989


I know this was posted a while back, but for the benefit of those who
don't know about it, here it is again.  I also made a *FEW* changes to
the program so that it will only call (exec) your mailer ONCE, if it
is already running.  If it is already running, as suggested by Todd Day,
I should just select that window.  Well that's what I did.  It prevents
those obnoxious messages from elm, saying that a temporary lock file is
out there (when you have <MSG> key bouncing )... blah, blah, blah ... 

-- cut here -- -- cut here -- -- cut here -- -- cut here -- -- cut here --
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  Makefile email.c
# Wrapped by lenny at icus on Tue Oct 24 00:54:23 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f Makefile -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"Makefile\"
else
echo shar: Extracting \"Makefile\" \(760 characters\)
sed "s/^X//" >Makefile <<'END_OF_Makefile'
X#
X# Makefile to compile email.c  (Security fix, and exec your favorite mailer)
X# By Lenny Tropiano
X# (c)1989 ICUS Software Systems UUCP:  ...icus!lenny -or- lenny at icus.islp.ny.us
X#
XLDFLAGS=-s
XLIBS=/lib/crt0s.o /lib/shlib.ifile
X#
X# Define the name of your favorite mailer
X#
XPROGNAME=elm
X#
X# Define the full path to your favorite mailer
X#
XPROGPATH=/usr/lbin/elm
X#
X# Define the label of your mail window
X#
XWIND_LABEL="Mail Window"
X#
XCFLAGS=-v -O -DPROGNAME=\"$(PROGNAME)\" -DPROGPATH=\"$(PROGPATH)\" -DWIND_LABEL=\"$(WIND_LABEL)\"
X
Xemail:  email.o
X	@echo "Loading ..."
X	$(LD) $(LDFLAGS) -o email email.o $(LIBS) 
X#
Xinstall: email
X	mv email /usr/bin/email
X	chown bin /usr/bin/email
X	chgrp mail /usr/bin/email
X	chmod 511 /usr/bin/email
Xclean:
X	rm -f email *.o core
END_OF_Makefile
if test 760 -ne `wc -c <Makefile`; then
    echo shar: \"Makefile\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f email.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"email.c\"
else
echo shar: Extracting \"email.c\" \(4597 characters\)
sed "s/^X//" >email.c <<'END_OF_email.c'
X/************************************************************************\
X**                                                                      **
X** Program name:    email.c (Security fix and exec favorate mailer)     **
X** Programmer:      Lenny Tropiano                                      **
X** E-Mail address:  ...!icus!lenny -or- lenny at icus.islp.ny.us           **
X** Organization:    ICUS Software Systems     (c)1987,1989              **
X** Date:            December 4, 1987                                    **
X** Revision:        October 24, 1989                                    **
X**                                                                      **
X**************************************************************************
X**                                                                      **
X** Program use:  If the program is placed in the /usr/bin directory     **
X**               /etc/smgr (Status Manager) will find this first, and   **
X**               will try to exec it when the <MSG> button is pressed   **
X**               and the <Mail ICON> is visible.                        **
X**                                                                      **
X**               This program will allow you to run your favorite       **
X**               mailer (mine is elm, but substitute yours in the       **
X**               appropriate spots in the Makefile).  If for some       **
X**               your mailer cannot be exec'd, it will default to       **
X**               /bin/mail.                                             **
X**                                                                      **
X**               As per a suggestion on the net, by Todd Day            **
X**               (todd at ivucsb.sba.ca.us <Todd Day>), Message-ID:        **
X**               <1989Oct22.000322.1187 at ivucsb.sba.ca.us>, he requested **
X**               that subsequent pressing of the <MSG> key doesn't      **
X**               re-exec another copy of your mailer, but if it is      **
X**               already running, find that window and select it.       **
X**               I thought this was a good idea, implemented it, and    **
X**               here you go!                                           **
X**                                                                      **
X** Disclaimer:   If you are running the AT&T Electronic Mail package    **
X**               do not install this program, it will overwrite the     **
X**               package (which is called /usr/bin/email).              **
X**                                                                      **
X**************************************************************************
X** Permission is granted to distribute this program by any means as     **
X** long as credit is given for my work.     I would also like to see    **
X** any modifications or enhancements to this program.                   **
X\************************************************************************/
X
X#include <stdio.h>
X#include <pwd.h>
X#include <fcntl.h>
X#include <sys/types.h>
X#include <sys/window.h>
X
X#ifndef PROGNAME
X# define PROGNAME "elm"
X#endif
X#ifndef PROGPATH
X# define PROGPATH "/usr/lbin/elm"
X#endif
X#ifndef WIND_LABEL
X# define WIND_LABEL "Mail Window"	/* window label			*/
X#endif
X
X#define NUM_WIN 12			/* max number of windows	*/
X
Xextern char **environ;
Xstruct utdata ut;
X
Xmain(argc,argv)
Xint   argc;
Xchar *argv[];
X{
X	/* email is exec'd from smgr with /usr/bin/email -i -u <user> */
X
X	struct	passwd	*pswd, *getpwnam();
X	char	arg[30], home[30], shell[30], mail[30];
X
X	if (argv[1] == NULL)
X		exit(1);
X
X	check_window();
X
X	setpwent();
X	if ((pswd = getpwnam(argv[3])) == NULL)
X		exit(1);
X
X	setgid(pswd->pw_gid);
X	setuid(pswd->pw_uid);
X
X	putenv("PATH=:/bin:/usr/bin:/usr/lbin:");
X	sprintf(home,"HOME=%s",pswd->pw_dir);
X	chdir(pswd->pw_dir);
X	putenv(home);
X	sprintf(shell,"SHELL=%s",pswd->pw_shell);
X	putenv(shell);
X	putenv("TERM=s4");
X	sprintf(mail,"MAIL=/usr/mail/%s",pswd->pw_name);
X	putenv(mail);
X	endpwent();
X
X	ut.ut_num = WTXTUSER;
X	sprintf(ut.ut_text,WIND_LABEL);
X	(void)ioctl(0, WIOCSETTEXT, &ut);
X
X	execle(PROGPATH,PROGNAME,0,environ);
X	execle("/bin/mail",0,environ);
X	perror("exec() failed");
X	exit(1);
X}
X
X
Xcheck_window()
X{
X	int  wfd, win;
X	char windev[9];
X
X	for (win=1;win<=NUM_WIN;win++) {
X		sprintf(windev,"/dev/w%d",win);
X		if ((wfd = open(windev, O_RDONLY)) != -1) {
X			ut.ut_num = WTXTUSER;
X			if (ioctl(wfd, WIOCGETTEXT, &ut) != -1) 
X				if (strcmp(ut.ut_text,WIND_LABEL) == 0) {
X					(void)ioctl(wfd, WIOCSELECT);
X					close(wfd);
X					exit(0);
X				}
X		}
X		close(wfd);
X	}
X}
X
END_OF_email.c
if test 4597 -ne `wc -c <email.c`; then
    echo shar: \"email.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0
-- 
| Lenny Tropiano            ICUS Software Systems      [w] +1 (516) 589-7930 |
| lenny at icus.islp.ny.us     Telex; 154232428 ICUS      [h] +1 (516) 968-8576 |
| {ames,pacbell,decuac,hombre,sbcs,attctc}!icus!lenny     attmail!icus!lenny |
+------- ICUS Software Systems -- PO Box 1;  Islip Terrace, NY  11752 -------+



More information about the Comp.sys.att mailing list