#!/bin/sh

######### Pine sending filter ###########
## arg 1 is ignored by this script
# thisscript  _TMPFILE_ _RECIPIENTS_ 
#
# $Id: marpAddRecipientsToWhiteList,v 1.5 2003/06/01 23:32:52 alan Exp alan $
#
#########################################


##########  user configuration  ####################
MARP_DIR="${HOME}/.procmail/marp"
####################################################

MARP_WHITELIST="${MARP_DIR}/white.list"


# lock the whitelist
lockfile ${MARP_WHITELIST}.lock
# make sure the white list exist in an acceptable format
if [ ! -s ${MARP_WHITELIST} ]; then
  echo "This file should not be empty" >> ${MARP_WHITELIST}
fi

ARGCTR=1
for THISONE do
  # echo -e "\ntesting"
  echo
  if [ ${ARGCTR} -eq 1 ]; then 
    echo "not this one ${THISONE}"
  else 
    echo ${THISONE}
    if [ `echo ${THISONE} | grep -F -ixc -f ${MARP_WHITELIST}` -eq 0 ]; then
      echo "${THISONE} is not in the white list"
      echo "Adding name to whitelist"
      echo ${THISONE} >> ${MARP_WHITELIST}
    else
      echo "${THISONE} is in the white list"
    fi
  fi
 ARGCTR=$[${ARGCTR} + 1]
done

# unlock the whitelist
rm -f ${MARP_WHITELIST}.lock

sleep  5s

