#--------------------------------CUT HERE-------------------------------------
#! /bin/sh
#
# This is a shell archive.  Save this into a file, edit it
# and delete all lines above this comment.  Then give this
# file to sh by executing the command "sh file".  The files
# will be extracted into the current directory owned by
# you with default permissions.
#
# The files contained herein are:
#
# -rw-r--r-- 1 jsweet 1074 Dec 3 00:19 Makefile
# -rw-r--r-- 1 jsweet 953 Dec 3 00:34 README
# -r-xr-xr-x 1 jsweet 7121 Mar 7 00:43 mail.weather.ext
# -r-xr-xr-x 1 jsweet 2002 Nov 11 00:49 mhnsend
# -r--r--r-- 1 jsweet 3378 Dec 3 00:03 mail.weather.ext.l
#
echo 'x - Makefile'
if test -f Makefile; then echo 'shar: not overwriting Makefile'; else
sed 's/^X//' << '________This_Is_The_END________' > Makefile
X# Makefile for MH-MIME weather stuff
X# Author: Jerry Sweet <jsweet@irvine.com>
X# $Header: /t/users/jsweet/src/mh-front/RCS/Makefile.weather,v 1.1 1992/11/14 02:06:21 jsweet Exp jsweet $
X
X# Define this if make doesn't know about environment variables
X# HOME=/q2/uh/jsweet
X
X# N.B.: If you modify this, keep the trailing slash (/)!
X# This is where the programs get installed.
XBINDIR=$(HOME)/bin/
X
X# These rules prevent make from going berserk with .l files:
X.DEFAULT:
X.SUFFIXES:
X
XBINSTUFF=$(BINDIR)mail.weather.ext $(BINDIR)mhnsend
X
XSTUFF=Makefile README mail.weather.ext mhnsend mail.weather.ext.l
X
Xinstall: $(BINSTUFF)
X
Xuushar: mhweather.shar.uu
X
Xshar: mhweather.shar
X
Xmhweather.shar: $(STUFF)
X	mkshar -h mhweather.shar $(STUFF)
X
Xmhweather.shar.uu: mhweather.shar
X	uuencode mhweather.shar <mhweather.shar >mhweather.shar.uu
X
X$(BINDIR)mail.weather.ext: mail.weather.ext
X	-rm -f $(BINDIR)mail.weather.ext
X	cp mail.weather.ext $(BINDIR)
X	chmod 555 $(BINDIR)mail.weather.ext
X
X$(BINDIR)mhnsend: mhnsend
X	-rm -f $(BINDIR)mhnsend
X	cp mhnsend $(BINDIR)
X	chmod 555 $(BINDIR)mhnsend
X
X
________This_Is_The_END________
if test `wc -l < Makefile` -ne 42; then
	echo 'shar: Makefile was damaged during transit (should have been 42 bytes)'
fi
fi		; : end of overwriting check
echo 'x - README'
if test -f README; then echo 'shar: not overwriting README'; else
sed 's/^X//' << '________This_Is_The_END________' > README
Xmhweather.shar - package of stuff to mail a current weather report in
X                 MIME format
X
XRequirements: perl 4.0 or later and MH-MIME (MH 6.7.2+MIME or MH 6.7.3 or 
Xlater).
X
XFor more information use "nroff -man mail.weather.ext.l" to find out
Xabout the mail.weather.ext program.
X
XManifest:
X
X  -rw-r--r--  1 jsweet       1074 Dec  3 00:19 Makefile
X  -rw-r--r--  1 jsweet        657 Dec  3 00:34 README
X  -r-xr-xr-x  1 jsweet       7155 Dec  3 00:05 mail.weather.ext
X  -r--r--r--  1 jsweet       3378 Dec  3 00:03 mail.weather.ext.l
X  -r-xr-xr-x  1 jsweet       2002 Nov 11 00:49 mhnsend
X
XYou may need to tweak the Makefile to specify where you want things
Xinstalled.  There are helpful comments in the Makefile to let you
Xknow what to change.  Run "make" to install.
X
XAuthor: Jerry Sweet <jsweet@irvine.com>
X
XThanks to Marshall T. Rose for suggesting external body parts (not to
Xmention providing the nifty MH-MIME stuff in the first place!).
X
________This_Is_The_END________
if test `wc -l < README` -ne 26; then
	echo 'shar: README was damaged during transit (should have been 26 bytes)'
fi
fi		; : end of overwriting check
echo 'x - mail.weather.ext'
if test -f mail.weather.ext; then echo 'shar: not overwriting mail.weather.ext'; else
sed 's/^X//' << '________This_Is_The_END________' > mail.weather.ext
X#!/usr/bin/perl
X#
X# mail.weather.ext - mail today's weather report using external body parts
X#
X# Usage: mail.weather [-debug] [-help] [-key file] [-verbose] address ...
X#
X# Author: Jerry Sweet <jsweet@irvine.com>
X#
X# $Header: /sparc/users/jsweet/src/weather/mhweather/RCS/mail.weather.ext,v 1.16 1993/03/07 08:43:40 jsweet Exp $
X
X#
X# Subprograms
X#
X
Xsub gripe {
X  print STDERR "$prog: ", @_, "\n";
X}
X
Xsub barf {
X  &gripe(@_);
X  exit 1;
X}
X
Xsub cmd {
X  local($_, $exit_on_error) = @_;
X  local($st);
X
X  if ($debug || $verbose) {
X    print "\t$_\n";
X  }
X
X  $st = system "$_";
X
X  if ($st >> 8 && $exit_on_error) {
X    split;
X    &barf("$_[0] failed with status ", $st >> 8);
X  }
X}
X
Xsub sh {
X  # Shell command, exit on error.
X
X  local($_) = @_;
X  &cmd($_, 1);
X}
X
Xsub one_hour_earlier {
X  local($tt_hour, $tt_mday, $tt_mon) = @_;
X
X  if (--$tt_hour < 0) {
X    $tt_hour = 23;
X    if (--$tt_mday < 0) {
X      if (--$tt_mon < 0) {
X        $tt_mon = 11;
X      }
X      $tt_mday = $lastday[$tt_mon];
X    }
X  }
X
X  ($tt_hour, $tt_mday, $tt_mon);
X}
X
Xsub read_profile {
X  # Defines associative array %PROFILE_COMPONENT indexed by lower case
X  # component name.  Continuation lines are tacked on.  New
X  # occurrences of a component wipe out previous occurrences of the
X  # same component, but probably shouldn't.
X
X  local($profile) = defined $ENV{'MH'} ? $ENV{'MH'} : 
X					 $ENV{'HOME'} . "/.mh_profile";
X  local($profile_component) = 'x-bogus';
X  local($_);
X  
X  &barf("can't open profile \"$profile\" - $!")
X	unless open(PROFILE, "<$profile");
X
X  while (<PROFILE>) {
X    /^(\S+):\s*/ && do {
X      	  ($profile_component = $1) =~ tr/A-Z/a-z/;
X	  $_ = $';
X	  s/\s+$//;
X      	  $PROFILE_COMPONENT{$profile_component} = $_;
X        };
X  
X    /^[ \t]/ && do {
X	  s/\s+$//;
X      	  $PROFILE_COMPONENT{$profile_component} .= $_;
X        };
X  }
X}
X
Xsub ext_local_file {
X  local($type, $explanation, $name, $site) = @_;
X  local($continue);
X
X  $continue = $site ? "; \\\\" : '';
X
X  print FORM <<"xxEndExternLocalFile";
X#@$type [$explanation] \\
X	access-type=local-file; \\
X	name="$name"$continue
XxxEndExternLocalFile
X
X  if ($site) {
X    print FORM "\tsite=\"$site\"\n";
X  }
X}
X
Xsub ext_anon_ftp {
X  local($type, $explanation, $site, $dir, $name, $expiration, $size) = @_;
X  local($continue);
X
X  $continue = ($expiration || $size) ? "; \\" : '';
X
X  print FORM <<"xxEndExternAnonFTPxx";
X#@${type} [${explanation}] \\
X	access-type=anon-ftp; \\
X	name="${name}"; \\
X	directory="${dir}"; \\
X	site="${site}"${continue}
XxxEndExternAnonFTPxx
X
X  $continue = $size ? "; \\" : '';
X
X  if ($expiration) {
X    print FORM "\texpiration=\"${expiration}\"${continue}\n";
X  }
X
X  if ($size) {
X    print FORM "\tsize=${size}\n";
X  }
X}
X
Xsub ftp_gif {
X  local($explanation, $name, $exp, $size) = @_;
X
X  &ext_anon_ftp('image/gif', $explanation, $wsite, $wdir, $name, $exp, $size);
X}
X
X#
X# Main
X#
X
X($prog = $0) =~ s|.*/||;
X
X$paths = '/usr/local/bin/mh:/usr/local/bin';
X
X$ENV{'MHCONTEXT'} = '/dev/null';	# No context changes here...
X$ENV{'PATH'} = $ENV{'HOME'} . '/bin:' . $paths . ':' . $ENV{'PATH'};
X
X$wsite = 'vmd.cso.uiuc.edu';
X$wdir  = 'wx';
X$wxkey = 'WXKEY.GIF';
X
X# Check the profile.
X
X&read_profile;
Xif (defined $PROFILE_COMPONENT{$prog}) {
X  push(@Args, split(' ', $PROFILE_COMPONENT{$prog}));
X}
X
X# Check the command line arguments.
X
Xpush(@Args, @ARGV);
X
Xwhile ($_ = shift @Args) {
X  /^-debug$/	&& do { $debug++; next; };
X
X  /^-help$/	&& do {
X      print <<"xxEndHelpxx";
X$prog - mail today's weather report
XUsage: $prog [-(no)debug] [-help] [-key file] [-(no)verbose] address ...
XOptions:
X  -debug        print the message draft and invoke default whatnow
X  -help         print this message
X  -key file     local path to weather key image file; FTP-ed if omitted
X  -verbose	print shell commands as they're executed
X  address       destination e-mail address(es)
XxxEndHelpxx
X
X      exit 1;
X    };
X
X  /^-key$/ && do {
X	$keyfile = shift @Args;
X	next;
X    };
X
X  /^-nodebug$/ && do { --$debug; next; };
X  /^-noverbose$/ && do { --$verbose; next; };
X
X  /-verbose$/ && do { ++$verbose; next; };
X
X  /^[^\-]/	&& do {
X	push(@address, $_);
X	next;
X    };
X
X  &barf("unrecognized command line option \"$_\"");
X}
X
X$debug = $debug > 0;
X$verbose = $verbose > 0;
X
X&barf("no destination e-mail address specified") 
X	unless $#address >= 0;
X
Xif ($keyfile && ! -r $keyfile) {
X  $keyfile = '';
X}
X
X$recipients = join (', ', @address);
X
X$formfile = "/tmp/$prog.$$";
X
X&barf("can't open temporary formfile $formfile - $!") unless
X	open(FORM, ">$formfile");
X
X# Figure out which file to get; if we're not past the half-hour mark,
X# use the previous hour's file.
X
X($tt_sec,$tt_min,$tt_hour,$tt_mday,$tt_mon,$tt_year,$tt_wday,
X	$tt_yday,$tt_isdst) = gmtime(time);
X
X@lastday = (31, ($tt_year % 4 == 0) ? 29 : 28, 
X	    31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
X
Xif ($tt_min < 30) {
X  ($tt_hour, $tt_mday, $tt_mon) = 
X	&one_hour_earlier($tt_hour, $tt_mday, $tt_mon);
X}
X
X$datestr = sprintf("%02d%02d%02d", $tt_mon + 1, $tt_mday, $tt_hour);
X$gmt = sprintf("%02d/%02d %02d00 GMT", $tt_mon + 1, $tt_mday, $tt_hour);
X$sagmt = sprintf("%02d00 GMT %02d/%02d", $tt_hour, $tt_mon + 1, $tt_mday);
X
X$surface_analysis_gif = sprintf("SA%s.GIF", $datestr);
X
X($ett_hour, $ett_mday, $ett_mon) = 
X	&one_hour_earlier($tt_hour, $tt_mday, $tt_mon);
X
X$e_datestr = sprintf("%02d%02d%02d", $ett_mon + 1, $ett_mday, $ett_hour);
X$egmt = sprintf("%02d00 GMT %02d/%02d", $ett_hour, $ett_mon + 1, $ett_mday);
X
X
X$satellite_photo_gif = sprintf("CI%s.GIF", $e_datestr);
X
X@m_name = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
X		'Sep', 'Oct', 'Nov', 'Dec');
X
X$exp_hour = $tt_hour;
X$exp_mday = $tt_mday;
X$exp_mon  = $tt_mon;
X$exp_year = $tt_year;
X
Xif (++$exp_mday > $lastday[$exp_mon]) {
X  $exp_mday = 1;
X  if (++$exp_mon > 11) {
X    $exp_mon = 1;
X    if (++$exp_year > 99) {
X      $exp_year = 0;
X    }
X  }
X}
X
X$expire_time = sprintf(
X	"%d %s %02d %02d:%02d:%02d GMT",
X	$exp_mday, $m_name[$exp_mon], $exp_year,
X	$exp_hour, 0, 0);
X
X$inum = $keyfile ? 'two' : 'three';
X
X
X# Print the mhn composition template:
X
Xprint FORM <<"xxEndForm10xx";
XTo: $recipients
XSubject: weather report: $gmt
X--------
X#<text/richtext [explanation]
X<paragraph>You may FTP $inum images:</paragraph>
X<paragraph><indent><fixed>
X$surface_analysis_gif: surface analysis at $sagmt<nl>
XxxEndForm10xx
X
Xif (! $keyfile) {
X  print FORM <<"xxEndForm15xx";
X$wxkey:    map symbol key<nl>
XxxEndForm15xx
X}
X
Xprint FORM <<"xxEndForm20xx";
X$satellite_photo_gif: satellite photo at $egmt
X</fixed></indent></paragraph>
X#
X#begin [weather report: $gmt] parallel
XxxEndForm20xx
X
X&ftp_gif('surface analysis + radar summary', 
X	$surface_analysis_gif, $expire_time, 50000);
X
X$keyfile ?
X  &ext_local_file('image/gif', 'weather map symbol key', $keyfile) :
X  &ftp_gif('weather map symbol key', $wxkey, 0, 18867);
X
X&ftp_gif('satellite photo', $satellite_photo_gif, $expire_time, 170000);
X
Xprint FORM "#end\n";
X
X
X
X&barf("problem closing formfile $formfile - $!") unless
X	close(FORM);
X
Xif ($debug) {
X  system '/bin/cat', $formfile;
X}
X
Xif ($debug) {
X  &sh("comp -form $formfile -noedit");
X}
Xelse {
X  &sh("comp -form $formfile -whatnowproc mhnsend");
X}
X
Xunlink $formfile;
Xexit 0;
X
________This_Is_The_END________
if test `wc -l < mail.weather.ext` -ne 328; then
	echo 'shar: mail.weather.ext was damaged during transit (should have been 328 bytes)'
fi
fi		; : end of overwriting check
echo 'x - mhnsend'
if test -f mhnsend; then echo 'shar: not overwriting mhnsend'; else
sed 's/^X//' << '________This_Is_The_END________' > mhnsend
X#!/usr/bin/perl
X#
X# mhnsend - run mhn non-interactively on the draft and then post the draft
X#
X# Author: Jerry Sweet <jns@fernwood.mpk.ca.us>
X#
X# $Id: mhnsend,v 1.3 1992/11/11 08:48:33 jsweet Exp $
X
X#
X# Subprograms
X#
X
X
Xsub barf {
X  print STDERR "$prog: ", @_, "\n";
X  exit 1;
X}
X
Xsub sh {
X  local($_) = @_;
X  local($st);
X
X  if ($verbose) {
X    print "\t$_\n";
X  }
X
X  return if $debug;
X
X  $st = system "$_";
X
X  if ($st >> 8) {
X    split;
X    &barf("$_[0] failed with status ", $st >> 8);
X  }
X}
X
Xsub read_profile {
X  # Defines associative array %PROFILE_COMPONENT indexed by lower case
X  # component name.  Continuation lines are tacked on.  New
X  # occurrences of a component wipe out previous occurrences of the
X  # same component, but probably shouldn't.
X
X  local($profile) = defined $ENV{'MH'} ? $ENV{'MH'} : 
X					 $ENV{'HOME'} . "/.mh_profile";
X  local($profile_component) = 'x-bogus';
X  local($_);
X  
X  &barf("can't open profile \"$profile\" - $!")
X	unless open(PROFILE, "<$profile");
X
X  while (<PROFILE>) {
X    /^(\S+):\s*/ && do {
X      	  ($profile_component = $1) =~ tr/A-Z/a-z/;
X      	  $PROFILE_COMPONENT{$profile_component} = $';
X        };
X  
X    /^[ \t]/ && do {
X      	  $PROFILE_COMPONENT{$profile_component} .= $_;
X        };
X  }
X}
X
X#
X# Main program
X#
X
X($prog = $0) =~ s%.*/%%;
X
X$editor = 'mhn';	# Default editor.
X
X# Check the profile.
X
X&read_profile;
Xif (defined $PROFILE_COMPONENT{$prog}) {
X  push(@Args, split(' ', $PROFILE_COMPONENT{$prog}));
X}
X
X# Check the command line arguments.
X
Xpush(@Args, @ARGV);
X
Xwhile ($_ = shift @Args) {
X  /^-debug$/	&& $debug++;
X  /^-editor$/   && ($editor = shift @Args);
X  /^-verbose$/	&& $verbose++;
X  /^[^\-]/	&& ($file = $_);
X}
X
Xif (! $file) {
X  if (defined $ENV{'mhdraft'}) {
X    $file = $ENV{'mhdraft'};
X  }
X  else {
X    &barf("no draft file specified");
X  }
X}
Xelse {
X  $ENV{'mhdraft'} = $file;
X}
X
X&sh("$editor $file >/dev/null");
X&sh("send $file >/dev/null");
Xprint("\trm $file\n") if ($verbose || $debug);
Xunlink($file) unless $debug;
Xexit 0;
X
________This_Is_The_END________
if test `wc -l < mhnsend` -ne 106; then
	echo 'shar: mhnsend was damaged during transit (should have been 106 bytes)'
fi
fi		; : end of overwriting check
echo 'x - mail.weather.ext.l'
if test -f mail.weather.ext.l; then echo 'shar: not overwriting mail.weather.ext.l'; else
sed 's/^X//' << '________This_Is_The_END________' > mail.weather.ext.l
X.\" $Header: /t/users/jsweet/src/weather/RCS/mail.weather.ext.l,v 1.1 1992/12/03 08:03:01 jsweet Exp $
X.\"
X.\" These definitions were borrowed from the MH docs.
X.\"
X..fc ^ ~
X.\" I pity the fool who tampers with the next line...
X.ds ZZ -man
X.de SC					\" Title section
X.TH \\$1 \\$2 MAIL.WEATHER.EXT
X..
X.de NA					\" Name section
X.SH NAME
X..
X.de SY					\" Synopsis section
X.SH SYNOPSIS
X.in +.5i
X.ti -.5i
X..
X.de DE					\" Description section
X.in -.5i
X.SH DESCRIPTION
X..
X.de De					\" Defaults section
X.SH "DEFAULTS"
X.nf
X..
X.de Bu					\" Bugs section
X.fi
X.SH BUGS
X..
X.de En
X..
X.de ip
X.IP "\\$1" \\$2
X..
X.SC MAIL.WEATHER.EXT 1 local
X.NA
Xmail.weather.ext \- mail MIME weather info
X.SY
Xmail.weather.ext
X\%[\-debug]
X\%[\-help]
X\%[\-key file]
X\%[\-verbose]
Xaddress\ ...
X.PP
Xmhnsend
X.DE
XMail.weather.ext sends a MIME message containing retrieval information
Xfor weather images.
X
XRequirements: perl 4.0 or later and MH with MIME (MH\ 6.7.2+MIME,
XMH 6.7.3, or later).
X
XMail.weather.ext generates an mhn(1) composition template based on
Xthe time of day, then invokes the helper program mhnsend to create
Xa MIME message and to send the message to the specified addresses.
X
XThe \-debug option prints out the mhn composition template and uses
Xthe default whatnowproc, typically whatnow(1).  When \-debug is used,
Xappropriate responses to the "What\ now?" prompt may include "edit\ mhn"
Xin addition to the usual responses.
X
XThe \-help option prints out a help message and exits.
X
XThe \-key option permits a local file to be specified for the weather
Xkey.
XThe \-key option is provided because the "WXKEY.GIF" file, which provides
Xa nicely done key to the surface analysis and radar summary image,
Xis invariant, so there's not much point in retrieving it from the
Xremote system every time.
XDon't use \-key if you send messages to non-local addresses.
X
XThe \-verbose option prints information about what's going on as
Xthe draft is being built.
X
XMhnsend is a helper program used by mail.weather.ext as a "whatnowproc".
XIt's in charge of running mhn and then sending the resulting MIME message.
XMhnsend isn't intended for direct use by humans.
X
X.SH BUGS
X
XThe external files aren't always there, sometimes even hours after
Xthey're supposed to be there.
XIf the files aren't there, you'll see an error about a missing
Xfile when mhn tries to retrieve the files.
X
XThe files expire off the remote system within a day or so, but as of
XMH 6.7.2 with MH-MIME upgrade #10, mhn doesn't pay any attention to
X"expiration" fields in external body parts, although mail.weather.ext
Xprovides them in anticipation of future implementations.
X
XI could've had this program emit MIME information directly, 
Xbut using MH-MIME abstracts things nicely.
XBesides, I wrote this mostly to help myself understand mhn composition files
Xand different kinds of body parts; use the -debug option to see
Xwhat I mean.
X
X.SH AUTHOR
X
XJerry Sweet <jsweet@irvine.com>.  
X
XThe author provides this package free of charge and without warranty
Xof any kind.  If you use the software, you agree to hold harmless the
Xauthor.  
X
X.\" If you sic a lawyer on me because you don't like the way this works,
X.\" I'll deny everything and may bribe your dentist to do sinister, but
X.\" untraceable things to you at your next cleaning appointment, involving
X.\" nitrous oxide, insects, and heated rocks.  :-)
X
X.SH SEE ALSO
X.in +.5i
Xmh(1), mhn(1)
X.in -.5i
X
________This_Is_The_END________
if test `wc -l < mail.weather.ext.l` -ne 116; then
	echo 'shar: mail.weather.ext.l was damaged during transit (should have been 116 bytes)'
fi
fi		; : end of overwriting check
exit 0
