#! /bin/sh
-(
- echo "Subject: Kalender für den `LANG=de_DE date +"%d. %B"`"
- echo "To: Martin Schulze <joey@infodrom.org>"
- echo
- calendar -l 0 -w 0 -t `date +%d.%m`
+# mail-calendar - send information about historical dates
+# Copyright (c) 2002,3 Martin Schulze <joey@infodrom.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
+
+# http://cvs.infodrom.org/calendar/mail-calendar?cvsroot=infodrom
+# :pserver:anonymous@cvs.infodrom.org:/var/cvs/infodrom co calendar/mail-calendar
+#
+# $Id$
+
+#
+# Important note: this program requires the FreeBSD version of
+# calendar. The OpenBSD version uses incompatible commandline
+# options and doesn't provide features used by this program.
+#
+
+opt_subject="Calendar for"
+opt_dateform="%B %d"
+opt_to=$LOGNAME
+opt_advance=0
+
+usage()
+{
+ echo "mail-calendar [-h|--help] [-l|--lang locale] [-t|--to addr] [-a|--advance days]"
+}
+
+# Parse arguments
+while [ $# -gt 0 ]
+do
+ case $1 in
+ -h|--help)
+ usage
+ exit
+ ;;
+ -l|--lang)
+ if [ $# -gt 1 ]
+ then
+ opt_lang=$2
+ shift
+ fi
+ ;;
+ -t|--to)
+ if [ $# -gt 1 ]
+ then
+ opt_to=$2
+ shift
+ fi
+ ;;
+ -a|--advance)
+ if [ $# -gt 1 ]
+ then
+ opt_advance=$2
+ shift
+ fi
+ ;;
+ esac
+ shift
+done
-) | /usr/sbin/sendmail joey
+# Add support for non-english languages/locales
+case $opt_lang in
+de_DE)
+ opt_subject="Kalender für den"
+ opt_dateform="%d. %B"
+esac
+
+secs=$[ $opt_advance * 86400 ]
+
+c_date=`date -d now+${secs}seconds +%d.%m`
+s_date=`LANG=$opt_lang date -d now+${secs}seconds "+$opt_dateform"`
+
+tmp=`tempfile`
+trap 'rm -f $tmp' INT EXIT
+
+calendar -l 0 -w 0 -t $c_date > $tmp
+
+if [ -s $tmp ]
+then
+ (
+ echo "Subject: $opt_subject $s_date"
+ echo "To: $opt_to"
+ echo "Content-Type: text/plain; charset=iso-8859-1"
+ echo "Content-Disposition: inline"
+ echo "Content-Transfer-Encoding: 8bit"
+ echo
+ cat $tmp
+ ) | /usr/sbin/sendmail "$opt_to"
+fi