head	1.4;
access;
symbols
	4-6-2:1.4
	4-6-1:1.4
	4-6-0:1.4
	4-5-8:1.4
	4-5-7:1.4
	4-5-6:1.4
	4-5-5:1.4
	4-5-4:1.4
	4-5-3:1.4
	4-5-2:1.4
	4-5-1:1.4
	4-5-0bis:1.4
	4-5-0:1.4
	4-4-9:1.4
	4-4-8:1.4
	4-4-7:1.4
	4-4-6bis:1.4
	4-4-6:1.4
	4-4-5bis:1.4
	4-4-5:1.4
	4-4-4:1.4
	4-4-3:1.4
	4-4-2:1.4
	4-4-1:1.4
	4-4-0:1.4
	4-3-9:1.4
	4-3-8bis:1.4
	4-3-8:1.4
	cmetz3:1.4
	cmetz2:1.4
	cmetz1:1.4
	4-3-7:1.4
	4-3-6:1.3
	4-3-5:1.3
	4-3-4:1.3
	4-3-3:1.3
	4-3-2:1.2
	4-3-1:1.2
	4-3-0:1.2
	4-2-9:1.2
	4-2-8:1.1;
locks; strict;
comment	@# @;


1.4
date	98.02.02.13.48.17;	author esr;	state Exp;
branches;
next	1.3;

1.3
date	97.11.22.07.26.20;	author esr;	state Exp;
branches;
next	1.2;

1.2
date	97.09.29.19.39.14;	author esr;	state Exp;
branches;
next	1.1;

1.1
date	97.09.29.19.38.12;	author esr;	state Exp;
branches;
next	;


desc
@@


1.4
log
@Author's 1.1 version.
@
text
@#!/bin/sh
# Runfetchmail 1.1
#
# Copyright (c) 1997 Doug Muth, Wescosville, Pennsylvania USA
# All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# Please send bug reports, suggestions, and flames to: dmuth@@ot.com
#
# This shell script is used as a "frontend" for running fetchmail.  It will
#	start up fetchmail and save the session to disk, generate statistics
#	of the e-mail that you downloaded, and tell you how many messages
#	you have in various folders.  A copy of these results are also
#	e-mailed to you.
#
# An rc file is also supported.  If the file $HOME/.runfetchmailrc 
#	exists, it will be sourced.  This way, you can place runfetchmail
#	into /usr/local/bin, and individual users can have their own settings.
#
# Pre-requisites: You must have procmail, or at least `mailstat', a 
#	utility that comes with procmail, running on your system.  You must 
#	also have `timer', a shell script written by me, if you would like the 
#	total time that the transfer took to be displayed.
#
# Syntax: runfetchmail [-every]
#	-every Downloads all messages from the mailserver, regardless of
#		their size and whether they have been previously downloaded.
#
# Changes in version 1.1: The argument "-every" is supported.  I removed the
#	$EXIT_CODE variable since I had problems assigning the exit code from 
#	fetchmail to it.

# Command line to run fetchmail
FETCHMAIL="/usr/local/bin/fetchmail"

# Your procmail logfile
LOG=$HOME/procmail/log

# Do we want to use timer?  Set to 0 to disable.
TIMER=1

# Our path to sendmail with parameters
SENDMAIL="/usr/bin/sendmail -oi -t"

# Who am I?
SELF="dmuth@@ot.com"

# The folders that I should check for the number of messages
FOLDERS="$MAIL $HOME/mail/lists"

# Number of seconds to "sleep" for while procmail finishes up, increase
# 	this if you have a really slow system
LATENT=10

# Do we want to use mailstat?  Set to 0 to disable
MAILSTAT=1

# Do we want to e-mail the output to myself?  Set to 0 to disable.
# I strongly suggest doing this so that if you lose your connection to
#	the net part of the way through a download, you can see how much 
#	progess was made
E_MAIL=1

###
# End of user defined variables
###

# The temp file, and ensure my privacy!
TMP=/tmp/fetchmail.sh.$$

# The version of this program
VERSION="Runfetchmail 1.1"

# Trap errors
trap "rm -f $TMP; echo ""Exiting at user request"" ; \
test $TIMER -eq 1 &amp;&amp; timer -stop -id $$ &gt;/dev/null; exit 1" \
2 3 4 15

# Source the user's rc file if it exists
test -e $HOME/.runfetchmailrc &amp;&amp; . $HOME/.runfetchmailrc

num_mail()
{ # This procedure tells me how many messages there are in each folder
for D in $* 
do
	if test -f $D
	then
		echo "There are `frm $D |wc -l` messages in $D"
	fi
done
}

getmail()
{ # Fetch the mail!

test $TIMER -eq 1 &amp;&amp; timer -start -id $$ -quiet

$FETCHMAIL $@@

# pause for a short while
echo "Now sleeping for $LATENT seconds..."
echo -n "Zzz...Zzz...Zzz..."
sleep $LATENT
echo "wakeup time! &lt;yawn&gt;"
}

stats()
{ # Prepare the statistics

# Ensure we have a log file
test ! -e $LOG &amp;&amp; touch $LOG  

echo -e "\n\t\t\t   $VERSION Statistics"
test $MAILSTAT -eq 1 &amp;&amp; mailstat -k &lt;$LOG
echo ""
num_mail $FOLDERS
test $TIMER -eq 1 &amp;&amp; echo -e "\n`timer -stop -id $$ -quiet` have elapsed."
}

prepmail()
{ # Let's prepare our e-mail
cat &lt;&lt;EOF &gt;$TMP
From: $LOGNAME ($VERSION)
To: $LOGNAME
X-Loop: $SELF
Subject: Mail stats from `date "+%D %X"`

EOF
}

### Main Program

# Let's have some initial cleanup
rm -f $LOG
clear

# Create and secure the temporary file
test $E_MAIL -eq 1 &amp;&amp; { cat /dev/null &gt;$TMP; chmod 600 $TMP }

# Prepare the e-mail before the logs are added to it
test $E_MAIL -eq 1 &amp;&amp; prepmail

# See if we are downloading every message or not
if test "$1" = "-every"
then
	FETCHMAIL="$FETCHMAIL -a -l 0"
	shift
fi

# Fetch the mail and have the output written to stdout and (optionally) $TMP
test $E_MAIL -eq 1 &amp;&amp; getmail $@@ 2&gt;&amp;1 |tee -a $TMP || getmail $@@

clear

# Do the same thing with the statistics
test $E_MAIL -eq 1 &amp;&amp; stats $@@ 2&gt;&amp;1 |tee -a $TMP || stats $@@

# Now send $TMP to myself and clean up the mess
test $E_MAIL -eq 1 &amp;&amp; { cat $TMP |$SENDMAIL; rm -f $TMP }

# cleanup the log file for next time
rm -f $LOG

# The End

@


1.3
log
@Ready to ship, I think.
@
text
@d2 1
a2 1
# Runfetchmail 1.0
d25 2
d33 4
d42 7
a48 1
# Please send bug reports, suggestions, and flames to: dmuth@@ot.com
d51 1
a51 1
FETCHMAIL="/usr/local/bin/fetchmail $*"
a87 3
# Fetchmail's exit code
EXIT_CODE=0

d89 1
a89 1
VERSION="Runfetchmail 1.0"
d93 1
a93 1
test $TIMER -eq 1 && timer -stop -id $$ >/dev/null; exit 1" \
d97 1
a97 1
test -e $HOME/.runfetchmailrc && . $HOME/.runfetchmailrc
d113 1
a113 1
test $TIMER -eq 1 && timer -start -id $$ -quiet
d115 1
a115 2
$FETCHMAIL
EXIT_CODE=$?
d121 1
a121 1
echo "wakeup time! <yawn>"
d128 1
a128 1
test ! -e $LOG && touch $LOG  
d131 1
a131 1
test $MAILSTAT -eq 1 && mailstat -k <$LOG
d134 1
a134 2
test $TIMER -eq 1 && echo -e "\n`timer -stop -id $$ -quiet` have elapsed."
echo -e "\nFetchmail's exit code was: $EXIT_CODE\n"
d139 1
a139 1
cat <<EOF >$TMP
d155 1
a155 2
test $E_MAIL -eq 1 && cat /dev/null >$TMP
test $E_MAIL -eq 1 && chmod 600 $TMP
d158 8
a165 1
test $E_MAIL -eq 1 && prepmail
d168 1
a168 1
test $E_MAIL -eq 1 && getmail $@@ 2>&1 |tee -a $TMP || getmail $@@
d173 1
a173 1
test $E_MAIL -eq 1 && stats $@@ 2>&1 |tee -a $TMP || stats $@@
d176 1
a176 2
test $E_MAIL -eq 1 && cat $TMP |$SENDMAIL
test $E_MAIL -eq 1 && rm -f $TMP
d182 1
@


1.2
log
@Added runfetchmail.
@
text
@d2 23
a24 5
# Copyright by Doug Muth (dmuth@@ot.com) 1997
# This program is free for NON-COMMERCIAL use.
#     If you want to use it commercially, please contact me, I'll be happy
#     to work out an agreement.

d31 6
a36 5
#	Pre-requisites: You must have procmail, or at least `mailstat', a 
#		utility that comes with procmail, running on your system.
#		You must also have `timer', a shell script written by me, if
#		you would like the total time that the transfer took to be
#		displayed.
a46 9
# The temp file, and ensure my privacy!
TMP=/tmp/fetchmail.sh.$$
touch $TMP
chmod 600 $TMP

# Trap errors
trap "rm -f $TMP; echo ""Exiting at user request"" ; \
test $TIMER -eq 1 && timer -stop -id $$ >/dev/null; exit 1" 2 3 4 15

d54 1
a54 2
FOLDERS="$MAIL mail/virus-l mail/procmail-d mail/lists mail/spam.list \
mail/fight-censorship"
d56 2
a57 1
# Number of seconds to "sleep" for while procmail finishes up
d60 16
d79 11
d111 1
a111 1
echo "Zzz...Zzz...Zzz..."
d113 1
d119 2
a120 1
test ! -e $LOG && touch $LOG  # Ensure we have a log file
d122 2
a123 2
echo -e "\n\t\t\t   Fetchmail Statistics"
mailstat -k <$LOG
d133 1
a133 1
From: $LOGNAME (Fetchmail)
d143 1
a143 1
# let's have some initial cleanup
d147 9
a155 1
prepmail
a156 1
getmail $* 2>&1 |tee -a $TMP
a157 1
stats $* 2>&1 |tee -a $TMP
d159 6
a164 3
# now send it and clean up the mess
cat $TMP |$SENDMAIL
rm -f $TMP
d168 2
@


1.1
log
@Initial revision
@
text
@d1 119
@
