4 # Copyright (c) 1997 Doug Muth, Wescosville, Pennsylvania USA
7 # Permission is hereby granted, free of charge, to any person obtaining a copy
8 # of this software and associated documentation files (the "Software"), to deal
9 # in the Software without restriction, including without limitation the rights
10 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 # copies of the Software, and to permit persons to whom the Software is
12 # furnished to do so, subject to the following conditions:
14 # The above copyright notice and this permission notice shall be included in
15 # all copies or substantial portions of the Software.
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 # Please send bug reports, suggestions, and flames to: dmuth@ot.com
27 # This shell script is used as a "frontend" for running fetchmail. It will
28 # start up fetchmail and save the session to disk, generate statistics
29 # of the e-mail that you downloaded, and tell you how many messages
30 # you have in various folders. A copy of these results are also
33 # An rc file is also supported. If the file $HOME/.runfetchmailrc
34 # exists, it will be sourced. This way, you can place runfetchmail
35 # into /usr/local/bin, and individual users can have their own settings.
37 # Pre-requisites: You must have procmail, or at least `mailstat', a
38 # utility that comes with procmail, running on your system. You must
39 # also have `timer', a shell script written by me, if you would like the
40 # total time that the transfer took to be displayed.
42 # Syntax: runfetchmail [-every]
43 # -every Downloads all messages from the mailserver, regardless of
44 # their size and whether they have been previously downloaded.
46 # Changes in version 1.1: The argument "-every" is supported. I removed the
47 # $EXIT_CODE variable since I had problems assigning the exit code from
50 # Command line to run fetchmail
51 FETCHMAIL="/usr/local/bin/fetchmail"
53 # Your procmail logfile
54 LOG=$HOME/procmail/log
56 # Do we want to use timer? Set to 0 to disable.
59 # Our path to sendmail with parameters
60 SENDMAIL="/usr/bin/sendmail -oi -t"
65 # The folders that I should check for the number of messages
66 FOLDERS="$MAIL $HOME/mail/lists"
68 # Number of seconds to "sleep" for while procmail finishes up, increase
69 # this if you have a really slow system
72 # Do we want to use mailstat? Set to 0 to disable
75 # Do we want to e-mail the output to myself? Set to 0 to disable.
76 # I strongly suggest doing this so that if you lose your connection to
77 # the net part of the way through a download, you can see how much
82 # End of user defined variables
85 # The temp file, and ensure my privacy!
86 TMP=/tmp/fetchmail.sh.$$
88 # The version of this program
89 VERSION="Runfetchmail 1.1"
92 trap "rm -f $TMP; echo ""Exiting at user request"" ; \
93 test $TIMER -eq 1 && timer -stop -id $$ >/dev/null; exit 1" \
96 # Source the user's rc file if it exists
97 test -e $HOME/.runfetchmailrc && . $HOME/.runfetchmailrc
100 { # This procedure tells me how many messages there are in each folder
105 echo "There are `frm $D |wc -l` messages in $D"
113 test $TIMER -eq 1 && timer -start -id $$ -quiet
117 # pause for a short while
118 echo "Now sleeping for $LATENT seconds..."
119 echo -n "Zzz...Zzz...Zzz..."
121 echo "wakeup time! <yawn>"
125 { # Prepare the statistics
127 # Ensure we have a log file
128 test ! -e $LOG && touch $LOG
130 echo -e "\n\t\t\t $VERSION Statistics"
131 test $MAILSTAT -eq 1 && mailstat -k <$LOG
134 test $TIMER -eq 1 && echo -e "\n`timer -stop -id $$ -quiet` have elapsed."
138 { # Let's prepare our e-mail
139 cat <<EOF >$TMP
140 From: $LOGNAME ($VERSION)
143 Subject: Mail stats from `date "+%D %X"`
150 # Let's have some initial cleanup
154 # Create and secure the temporary file
155 test $E_MAIL -eq 1 && { cat /dev/null >$TMP; chmod 600 $TMP }
157 # Prepare the e-mail before the logs are added to it
158 test $E_MAIL -eq 1 && prepmail
160 # See if we are downloading every message or not
161 if test "$1" = "-every"
163 FETCHMAIL="$FETCHMAIL -a -l 0"
167 # Fetch the mail and have the output written to stdout and (optionally) $TMP
168 test $E_MAIL -eq 1 && getmail $@ 2>&1 |tee -a $TMP || getmail $@
172 # Do the same thing with the statistics
173 test $E_MAIL -eq 1 && stats $@ 2>&1 |tee -a $TMP || stats $@
175 # Now send $TMP to myself and clean up the mess
176 test $E_MAIL -eq 1 && { cat $TMP |$SENDMAIL; rm -f $TMP }
178 # cleanup the log file for next time