p.s. - forgive me if this turns out to be a repost but I don't think the
previous attempt made it through the smtp server
Got it three times, thanks :-)
On Wed, Apr 24, 2002 at 10:26:11PM -0400, Stephen Watts wrote:
All,
I am trying to use fetchmail to take care of a 'pop before smtp'
authorization scheme my isp has implemented.
I have a script with the line: "/usr/bin/fetchmail -c -f /etc/fetchmailrc"
The script is called by mailprogram and therefore fetchmail (running under
mailprogram) doesn't work:
- fetchmail doesn't seem to have an option to provide a password to a pop
account w/o using fetchmailrc
- fetchmail can't access fetchmailrc because a: fetchmailrc is not owned by
mailprogram
b:
fetchmailrc can not have permissions greater than 710
- can not chown of fetchmailrc to mailprogram because no user by that name
- can not create user of that name because is a system account
A: put your fetchmailrc in ~/.fetchmailrc with the correct permissions. (See
fetchmail man page)
you may be able to override the /etc/fetchmailrc stuff there.
So, is there any way to run fetchmail from a script called by a program
and/or another way to do a dummy login to a pop account, ie. I tried:
'telnet mail.isp.com 110 < popscript' but just get disconnected by the
remote.
If worst comes to worst I'll install expect but would prefer to do it with
what's already on the system.
The scripts below were quick hacks that were asupposed to be "temporary" (ha ! )
As you've already noted, Expect seems to be the best answer.
Here is a small script I use to get the current count of emails on my pop
server.
Note - the user name and password are hardcoded into these examples.
Better practice is to pass them in on the command line and immediately wipe
the command line so the password and login can not be seen in a "ps" command.
This script is called "getmailcount", "mename" = login name, "xyzzy" isa the
password.
##############################################################################
#!/usr/bin/expect
log_user 0
eval spawn telnet -l mename pop.rcn.com 110
expect "starting."
send "user mename\r"
expect "mename."
send "pass xyzzy\r"
expect "octets"
send "stat\r"
expect "\r\n"
expect "+OK "
# log_user 1
expect -re "\[0-9]* "
set answer $expect_out(0,string)
send_user "$answer \r\n"
expect -re "\[0-9]*\r\n"
# log_user 0
send "quit\r"
expect "signing off"
exit
################################################################################
Here is another script I use to interactively get some, all or none of my email.
It is helpful when i am using multiple email clients from differnt locations.
I have two versions. One fetches mail but leaves it on the server, the other
fetches and deletes the fetched mail.
################## START Script ####################
############# These functions are actually in a seperate file which is sourced
# into the script
#
# functions used in this script :
#
#
# function which gets a yes, or a no, or a number
#
#
function get_yes_no_number {
noans=t
prompt="$*"
#
while [ $noans = t ] ; do
read intext?"${prompt} ( use y for yes, n for no, or enter a
number )"
#
case $intext in
[0-9]*)
echo $intext
noans=f;;
[Yy])
echo y
noans=f;;
[Nn])
echo n
noans=f;;
esac
done
}
typeset -xf get_yes_no_number {
#
#
# function which gets a yes or a no, returns "y" or "n"
#
#
function getyesno {
noans=t
prompt="$*"
#
while [ $noans = t ] ; do
read intext?"${prompt} ( Must use y for yes, n for no )"
if [ "x$intext" = xy ] ; then
echo y
noans=f
elif [ "x$intext" = xn ] ; then
echo n
noans=f
fi
done
}
typeset -xf getyesno
#
#
#
# function which echos a prompt for text and returns the entered text
#
#
function gettxt {
read text?"Please enter the $* "
echo $text
}
typeset -xf gettxt
#
#
#
#
# Verifytxt: verifies that the text data field is what the user wants it
to be.
# Syntax: xxx=`verifytxt "Prompt for user" "Contents of data text
field"`
# Example: answer=`verifytxt "$Prompt_for_message_count" "$count"`
#
function verifytxt {
desc=$1
name=$2
read ans?"$desc : $name
Enter a new value or just press enter to keep the current value >> "
if [ "x$ans" != x ] ; then
ans=`verifytxt "$desc" "$ans"`
echo $ans
else
echo $name
fi
}
typeset -xf verifytxt
#
#
#
if [ "x$DEBUG" = "xT" ] ; then
set -vx
fi
#
#set -vx
############ End of functions section, begin actual script
####################################################################################
#
#
############## BEGIN MAIN
#
#
####################################################################################
####### GLOBAL VARS - SAVE TEXT SPACE IN LINES AND MAKE IT EASIER TO
####### CHANGE THE CONFIGURATION
# Var holding location of program which gets the number of emails currently on
the server
BB=`/usr/local/bin/getmailcount`
# Var holding prompt for getting numbers
prompt="number of messages you want to get ?"
# Var holding the debugging option for the mail command
debugopt=""
# Var holding the command to get the mail
mailcommand="fetchmail $debugopt --logfile ~/maillog -a -b"
# if there is a numeric argument on the command line, fetch just that many
emails
if [ $# -eq 1 ]; then
echo $mailcommand $1 -B $1
$mailcommand $1 -B $1
echo "End mail command run"
exit 1
fi
# Otherwise, ask the user how many to get. "Y" defaults to "all", "n" exits.
count=${BB%% *}
echo "There are $count messages waiting on the server."
ans=`get_yes_no_number "You can fetch some or all those messages now.
Enter \"y\" to fetch all, or a number to fetch some, and \"n\" to quit without
fetching any.
" `;
case $ans in
[y])
# mailcommand="fetchmail -v --logfile ~/maillog -a -b ${count} -B
${count}"
echo $mailcommand $count -B $count
$mailcommand $count -B $count ;;
[0-9]*)
count=`verifytxt "$prompt" "$ans" `
# mailcommand="fetchmail -v --logfile ~/maillog -a -b ${count} -B
${count}"
echo $mailcommand $count -B $count
$mailcommand $count -B $count
echo "End mail command run";;
esac
#
#########################################################################