Added ISO-8859-1 support so I can read umlauts again
[infodrom/calendar] / mail-calendar
1 #! /bin/sh
2
3 #   mail-calendar - send information about historical dates
4 #   Copyright (c) 2002,3  Martin Schulze <joey@infodrom.org>
5 #
6 #   This program is free software; you can redistribute it and/or modify
7 #   it under the terms of the GNU General Public License as published by
8 #   the Free Software Foundation; either version 2 of the License, or
9 #   (at your option) any later version.
10 #
11 #   This program is distributed in the hope that it will be useful,
12 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #   GNU General Public License for more details.
15 #
16 #   You should have received a copy of the GNU General Public License
17 #   along with this program; if not, write to the Free Software
18 #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
19
20 #   http://cvs.infodrom.org/calendar/mail-calendar?cvsroot=infodrom
21 #   :pserver:anonymous@cvs.infodrom.org:/var/cvs/infodrom co calendar/mail-calendar
22 #  
23 #   $Id$
24
25 #
26 #   Important note: this program requires the FreeBSD version of
27 #   calendar.  The OpenBSD version uses incompatible commandline
28 #   options and doesn't provide features used by this program.
29 #
30
31 opt_subject="Calendar for"
32 opt_dateform="%B %d"
33 opt_to=$LOGNAME
34 opt_advance=0
35
36 usage()
37 {
38     echo "mail-calendar [-h|--help] [-l|--lang locale] [-t|--to addr] [-a|--advance days]"
39 }
40
41 # Parse arguments
42 while [ $# -gt 0 ]
43 do
44     case $1 in
45     -h|--help)
46         usage
47         exit
48         ;;
49     -l|--lang)
50         if [ $# -gt 1 ]
51         then
52             opt_lang=$2
53             shift
54         fi
55         ;;
56     -t|--to)
57         if [ $# -gt 1 ]
58         then
59             opt_to=$2
60             shift
61         fi
62         ;;
63     -a|--advance)
64         if [ $# -gt 1 ]
65         then
66             opt_advance=$2
67             shift
68         fi
69         ;;
70     esac
71     shift
72 done
73
74 # Add support for non-english languages/locales
75 case $opt_lang in
76 de_DE)
77         opt_subject="Kalender für den"
78         opt_dateform="%d. %B"
79 esac
80
81 secs=$[ $opt_advance * 86400 ]
82
83 c_date=`date -d now+${secs}seconds +%d.%m`
84 s_date=`LANG=$opt_lang date -d now+${secs}seconds "+$opt_dateform"`
85
86 tmp=`tempfile`
87 trap 'rm -f $tmp' INT EXIT
88
89 calendar -l 0 -w 0 -t $c_date > $tmp
90
91 if [ -s $tmp ]
92 then
93     (
94         echo "Subject: $opt_subject $s_date"
95         echo "To: $opt_to"
96         echo "Content-Type: text/plain; charset=iso-8859-1"
97         echo "Content-Disposition: inline"
98         echo "Content-Transfer-Encoding: 8bit"
99         echo
100         cat $tmp
101     ) | /usr/sbin/sendmail "$opt_to"
102 fi