Xref: utzoo unix-pc.sources:411 comp.sys.att:7871 Path: utzoo!attcan!utgpu!watmath!uunet!cs.utexas.edu!mailrus!rutgers!att!icus!lenny From: lenny@icus.islp.ny.us (Lenny Tropiano) Newsgroups: unix-pc.sources,comp.sys.att Subject: UNIX PC: email program to call favorite mailer when is pressed. Keywords: email, , mailer Message-ID: <993@icus.islp.ny.us> Date: 24 Oct 89 04:59:14 GMT Organization: ICUS Software Systems, Islip, New York Lines: 206 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 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 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@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 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@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 button is pressed ** X** and the 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@ivucsb.sba.ca.us ), Message-ID: ** X** <1989Oct22.000322.1187@ivucsb.sba.ca.us>, he requested ** X** that subsequent pressing of the 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 X#include X#include X#include X#include 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 */ 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