[comp.windows.news] NeWS mail notifier

jh@Ist.CO.UK (Jeremy Huxtable) (08/15/88)

Here is (yet) another NeWS mail notifier which shows you when mail
arrives and allows you to read the article.  It was inspired by the
recent posting to this group by Josh Siegel.

When mail arrives you get a little envelope appearing on your screen
which is the icon for a window displaying the offending article.

Documentation consists of the comment at the top of the program.

Suggestions for enhancements will be gratefully received.  Some possible
ones are:

     o Use a TextCanvas type window for reading the mail item.
     o For short messages, pop up a postcard rather than an envelope.
     o For really long messages, pop up a parcel icon.
     o For really short messages, pop up a telegram and change all
       the message into upper case with periods replaced by STOP
       etc.

-----------------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:  newsbiff.c newsbiff.cps Makefile
# Wrapped by jh@iscream on Mon Aug 15 15:13:12 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f newsbiff.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"newsbiff.c\"
else
echo shar: Extracting \"newsbiff.c\" \(2692 characters\)
sed "s/^X//" >newsbiff.c <<'END_OF_newsbiff.c'
X/*
X** Created By:
X**
X**      Jeremy Huxtable (jh@ist.co.uk)
X**
X**      Mon Aug 15 12:33:25 BST 1988
X**
X*/
X
X/*
X**LIBS: -lcps
X*/
X
X/*
X** newsbiff.c:
X**
X** Usage: newsbiff host username [port]
X**
X** Inspired by the program posted by Josh Siegel (siegel@hc.dspo.gov),
X** this program will notify you via your NeWS server when new mail arrives.
X** The mail item should be given as standard input.  The program opens a
X** connection to the NeWS server (if any) on <host.port>, checks that the
X** user is the same as <username>, and pops up an icon shaped like an
X** envelope. You can click on this icon to get a window displaying the
X** whole mail item.
X**
X** To use this you must change two files:
X**
X**      1) in your "user.ps" you need a line of the form:
X**              UserProfile /UserName (<name>) put
X**         and you probably need to disable network security:
X**              systemdict /NetSecurityWanted false put
X**
X**      2) in your ".forward" file in your home directory
X**         you need a line of the form:
X**              <user>,|"newsbiff <host> <user> <port>"
X**        for example, my one goes:
X**              jh,|"/u/jh/bin/newsbiff isharp jh 2000"
X**
X** Of course, this is only a "biff" type program. It merely tells you
X** that mail has arrived and lets you read it, nothing else.
X**
X** Any suggestions for enhancements gratefully received.
X*/
X
X#ifdef SYSVREF
X#ifdef INTERLANTCP
X#include <interlan/il_types.h>
X#include <interlan/netdb.h>
X#include <interlan/in.h>
X#else
X#include <sys/types.h>
X#endif
X#else
X#include <sys/types.h>
X#include <netdb.h>
X#include <netinet/in.h>
X#endif
X
X#include <psio.h>
X#include "newsbiff.h"
X
X#define MAXSTR  256
X
Xmain(argc, argv)
X	int     argc;
X	char    *argv[];
X{
X	struct hostent *hp;
X	char    from[MAXSTR];
X	char    line[MAXSTR];
X	char    server[MAXSTR];
X	int     port = 2000;
X	int     count = 0;
X
X	if (argc != 3 && argc != 4)
X		exit(1);
X
X	if (argc == 4)
X		port = atoi(argv[3]);
X
X	if (!(hp = gethostbyname(argv[1])))
X		exit(2); /* Host unknown */
X
X	/*
X	** There ought to be a better way of doing this rather than
X	** putting NEWSSERVER into the environment.
X	*/
X	sprintf(server, "NEWSSERVER=%lu.2000;%s\n", ntohl(*(u_long *)hp->h_addr), argv[1]);
X	putenv(server);
X	if (!ps_open_PostScript())
X		exit(3); /* Can't contact NeWS server */
X
X	ps_username(line);
X	if (strcmp(line, argv[2]) != 0)
X		exit(4); /* User name doesn't match */
X
X	strcpy(from, "Anon");
X	ps_begin_list();
X	while (fgets (line, 255, stdin)) {
X		line[strlen(line)-1] = 0;
X		if (count++ > 50) {
X			ps_string("More follows......");
X			break;
X		}
X		ps_string(line);
X		sscanf(line, "From: %s", from);
X	}
X	ps_end_list();
X	ps_mailwindow(from);
X	ps_close_PostScript();
X	exit(0);
X}
END_OF_newsbiff.c
if test 2692 -ne `wc -c <newsbiff.c`; then
    echo shar: \"newsbiff.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f newsbiff.cps -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"newsbiff.cps\"
else
echo shar: Extracting \"newsbiff.cps\" \(2574 characters\)
sed "s/^X//" >newsbiff.cps <<'END_OF_newsbiff.cps'
X%
X% NeWS interface for the "newsmail" program.
X%
X
X#define NAME_TAG        1
X
X% Get the user name of the owner of the NeWS server
Xcdef ps_username(string s) => NAME_TAG(s)
X    UserProfile /UserName known
X    { UserProfile /UserName get }
X    { (?) } ifelse
X    NAME_TAG tagprint typedprint
X
X% Three procedures for sending down an array of strings
Xcdef ps_begin_list()
X    [
X
Xcdef ps_end_list()
X    ]
X
Xcdef ps_string(string s)
X    s
X
X% Actually create the icon.
Xcdef ps_mailwindow(string sender)
X
X/MailWindow DefaultWindow [
X    /Text       % Text of the mail item
X    /Sender     % Name of the sender
X]
Xclassbegin
X    /TextFont /Times-Roman findfont 14 scalefont def
X    /SmallFont /Times-Roman findfont 7 scalefont def
X    /Margin 10 def
X
X    /new { % text sender => instance
X	/new super send begin
X	    /Sender exch def
X	    /Text exch def
X	    /Iconic? true def
X	    /IconX 50 def
X	    /IconY 800 def
X	    /IconWidth 64 def
X	    /IconHeight 40 def
X
X	    IconX IconY         % position of window
X	    % Now calculate the width and height of the window
X	    TextFont setfont
X	    0 Text { stringwidth pop max } forall
X	    Margin 2 mul add BorderLeft add BorderRight add % Width
X
X	    TextFont fontheight Text length mul Margin 2 mul add
X	    BorderTop add BorderBottom add % Height
X
X	    3 2 roll 1 index sub IconHeight add 3 1 roll % Adjust Y position
X	    reshape             % Shape the window
X	    IconX IconY move    % Move the icon to its proper place
X	    currentdict
X	end
X    } def
X
X    % Write the mail item into the window.
X    /PaintClient {
X	1 fillcanvas 0 setgray
X	TextFont setfont
X	Margin ClientHeight Margin sub TextFont fontheight sub moveto
X	Text {
X	    show
X	    Margin currentpoint exch pop moveto
X	    0 TextFont fontheight neg rmoveto
X	} forall
X    } def
X
X    % Make the Icon look like an envelope.
X    /PaintIcon {
X	gsave
X	IconCanvas setcanvas
X	1 fillcanvas 0 strokecanvas
X	matrix currentmatrix
X	IconWidth IconHeight scale
X	0 0 moveto 0 1 lineto .5 .3 lineto 1 1 lineto
X	1 0 lineto closepath clip                 % Set flap clipping path
X	0 0 moveto .5 .7 lineto 1 0 lineto stroke % Draw two lines clipped by flap
X	initclip                                  % Reset clip path
X	0 1 moveto .5 .3 lineto 1 1 lineto stroke % Draw flap
X	.5 .7 moveto
X	setmatrix
X	SmallFont setfont Sender cshow
X	grestore
X    } def
X
Xclassend def
X
X% Create the window.  We create a new process group so that the window
X% does not get zapped when the C program closes its socket.
X{
X    newprocessgroup
X    sender framebuffer /new MailWindow send
X    /map exch send
X} fork clear
END_OF_newsbiff.cps
if test 2574 -ne `wc -c <newsbiff.cps`; then
    echo shar: \"newsbiff.cps\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f Makefile -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"Makefile\"
else
echo shar: Extracting \"Makefile\" \(202 characters\)
sed "s/^X//" >Makefile <<'END_OF_Makefile'
XCFLAGS=-O
XINCLUDE=-I/usr/NeWS/include
XLIBS=/usr/NeWS/lib/libcps.a
X
Xnewsbiff: newsbiff.c newsbiff.h
X	$(CC) $(CFLAGS) $(INCLUDE) newsbiff.c -o newsbiff $(LIBS)
X
Xnewsbiff.h: newsbiff.cps
X	cps newsbiff.cps
END_OF_Makefile
if test 202 -ne `wc -c <Makefile`; then
    echo shar: \"Makefile\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0