#!/bin/rc
exec echo user : $user
# This script utilises the upas/fs mounted mail system to mount a remote mailbox and then
# transfer the messages using the local smtp process.
# [email protected]
# 16/7/2002
# run our own copy of factotum so we dont use the current process's one
auth/factotum -n
# we're going to need a clean mail too
upas/fs
# read the parameters from /usr/$user/pop3
# the format of which is line separated records of space or tab separated fields :
# protocol domain username password
# Example :
# pop pop3.aol.om connie secret
#
# $key(1) $key(2) $key(3) $key(4)
#
fn init {
pwfile = /usr/$user/pop3
keep = 0
# -f pwfile <- use a different pw file
while(~ $1 -*){
switch($1){
case -f:
shift
pwfile = $1
case -k:
keep = '1'
}
shift
}
}
fn log_in {
# insert a key into the local factotum
echo 'key proto=pass service=pop dom=' ^$server ^' user=' ^$username ^' !password=' ^$password > /mnt/factotum/ctl
# open the mailbox, it get's mounted as /mail/fs/$username
echo 'open /pop/'^$server ^' ' ^$username > /mail/fs/ctl
}
fn log_out {
echo 'close ' ^$username > /mail/fs/ctl # close the mailbox
# delete the key from factotum so that we can process multiple pop3 boxes on the same domain
echo 'delkey proto=pass service=pop dom=' ^$server ^' user=' ^$username > /mnt/factotum/ctl
}
fn get_msg_list {
ls -d /mail/fs/$username/[0-9]*
}
init
{
key = `{read}
num_msgs = 0
while(test $#key '!=' '0') { # die when null/blank line
username = $key(3)
server = $key(2)
password = $key(4)
switch($key(1)) {
# made it a switch for expansion and comments
case pop3 :
# tell stdout what we're doing
log_in
echo from $username at $server to $user
for (msg in `{get_msg_list}) {
cat $msg/raw | upas/send -b $user
num_msgs = `{echo $num_msgs + 1 | bc}
echo From: `{cat $msg/from} # Tell stdout
echo Subject : `{cat $msg/subject}
if (test $keep '=' '0')
rm $msg # delete message from the remote server
}
log_out
}
key = `{read}
}
} < $pwfile
echo $num_msgs mails processed.
|