Subject: Solaris Calendar Manager and procmail

From: Andrew Cosgriff <[email-masked]>
Date: Tue, 24 Jan 1995 16:09:15 +1100

--------

Hi everyone,
 I've hacked up a recipe (and Perl script) to allow remote addition of 
appointments using Sun's Calendar Manager.

It works like so :

i) The Subject: header matches "Appointment"
ii) User and Date are logged
ii) The body is passed to a Perl script (add-app) that grabs the details from 
the text and runs 'cm_insert' to insert the appointment (it also logs the 
'cm_insert' command line).
iii) The output of the cm_insert is returned by mail to the user.

I've also written a zsh function to mail off an appointment, which takes 
similar arguments to cm_insert.

The format of the mail is :

On (date)
>From (time)
To (time)
Do (text)

Everything's optional except the start time (although cm_insert doesn't even 
have to have this, I thought i preferred it this way)

The relevant parts are below (as MIME parts), and are also available from my 
mail server as :

dot-files/procmailrc
perl/add-app
zsh/sendapp

(These are linked to the "online" versions I'm editing and/or using, so 
they're guaranteed to be absolutely up-to-date)

Comments, suggestions (and especially improvements) welcome !

(Oh yes, security is non-existent, although there isn't much that could happen 
apart from filling up the calendar database with appointments (kind of like 
filling up the mail spool I suppose) - feel free to improve on this aspect, 
please ! :)

Enjoy,
 Andrew.
FROMSIG="Andrew's Mail Gremlin <$MYADDR>"
MYADDR=[email-masked]
CALENDARLOG=$MAILDIR/calendar.log
########################################
#
# Allow insertion of Calendar Manager appointments
#
:0
* ^Subject: Appointment
* !^X-Loop: $MYADDR
{
	FROM=`formail -rt -xTo:`

	:0fhw
	| (echo "`date` :$FROM" >> $CALENDARLOG; \
		formail -rI"From: $FROMSIG" \
			-I"X-Loop: $MYADDR" \
			-I"Subject: Calendar Insertion")

	#
	# rsh to buddha because it's running Solaris 2.4 - Solaris 2.3's
	# cm_insert doesn't seem to like the date format (whichever date
	# format you happen to choose - i tried YY/MM/DD, DD/MM/YY and
	# MM/DD/YY, and it complained all three times !)
	#
	:0afbw:calendar.lock
	| rsh buddha $HOME/bin/add-app

	:0abh
	| $SENDMAIL -oi -t
}

#! /usr/local/misc/bin/perl
#
# add-app - Procmail support to add an appointment with cm_insert.
#
# 1995 Andrew J. Cosgriff, UNICO Computer Systems Pty Ltd
# [email-masked]
#
# Creation Date : Tue Jan 24 13:31:53 1995
# $Revision: 1.1 $
# $Date: 1995/01/24 04:56:09 $
#
########################################
$CALENDAR="andrew\@zardoz";
#
# It's optimal if this is the same as CALENDARLOG in .procmailrc
#
$LOGFILE="$ENV{'HOME'}/Mail/calendar.log";
$date = $start = $end = $what = "";
#
# Get the details from the message
#
while (<>) {
    if ( m/\b^[Oo]n\s+([\w\/]+)\b/ ) {
	$date = "$1";
	print;
    }
  elsif (m/\b[Ff]rom\s+(\w+):(\w+)\b/) {
	$start = "$1:$2";
	print;
    } elsif (m/\b[Tt]o\s+(\w+):(\w+)\b/) {
	$end = "$1:$2";
	print;
    } elsif (m/\b[Dd]o\s+(.*)$/) {
	$what = $1;
	print;
    }
}
#
# Sanity check
#
if ( $start eq "" ) {
    print "You must give a start time !\n";
    exit 1;
}
#
# Build the command line
#
$cmd_string = "/usr/openwin/bin/cm_insert -c $CALENDAR -s $start";
if ( $date ne "" ) {
    $cmd_string .= " -d $date";
}
if ( $end ne "" ) {
    $cmd_string .= " -e $end";
}
if ( $what ne "" ) {
    $cmd_string .= " -w $what";
}
#
# Log the command line
#
open(LOG,">> $LOGFILE") || die "Can't open logfile !";
print LOG "$cmd_string\n";
close(LOG);
print "\n$cmd_string\n";
#
# Do it
#
system $cmd_string;
exit $?
########################################
#
# $Id: add-app,v 1.1 1995/01/24 04:56:09 andrew Exp andrew $
#

#! /opt/local/bin/zsh
#
# sendapp - Send an appointment to cm by mail
#
# This uses my .procmailrc which passes appointments to a Perl script that
# runs cm_insert to add the appointment...
#
# 1995 Andrew J. Cosgriff, UNICO Computer Systems Pty Ltd
# [email-masked]
#
# Creation Date : Tue Jan 24 15:19:55 1995
# $Revision: 1.1 $
# $Date: 1995/01/24 04:56:26 $
#
########################################
usage="Syntax : `basename $0` [-s <time>|-e <time>|-d <date>|-w <what>|-t 
<addr>]
  -s <time> : start time (required)
  -e <time> : end time
  -d <date> : date
  -w <what> : text for the appointment
  -t <addr> : recipient of the mail"

local start end date what to tmpfile

tmpfile=/tmp/$0.tmp.$$

while getopts s:e:d:w:h opt
do
  case $opt
{
  s) start=$OPTARG ;;
  e) end=$OPTARG ;;
  d) date=$OPTARG ;;
  w) what=$OPTARG ;;
  t) to=$OPTARG ;;
  h) echo $usage ;
    return 1;;
}
done
shift `expr $OPTIND - 1`

if [[ "$start" = "" ]]
then
  echo "Must specify a start time \!"
  return 1;
fi

touch $tmpfile
echo "From $start" >> $tmpfile
[[ "$end" != "" ]] && echo "To $end" >> $tmpfile
[[ "$date" != "" ]] && echo "On $date" >> $tmpfile
[[ "$what" != "" ]] && echo "Do $what" >> $tmpfile

mailx -s Appointment ${to:[email-masked]} < $tmpfile

/bin/rm -f $tmpfile
########################################
#
# $Id: sendapp,v 1.1 1995/01/24 04:56:26 andrew Exp andrew $
#

 - Andrew J. Cosgriff -  (BH) [email-masked] (AH) [email-masked]
 UNICO Computer Systems | Email Server (BH addr.) : "send file help" as subject
       "Teamwork is essential -- it allows you to blame someone else."