# Copyright (c) 1991, Andrew Rosen.
# All rights reserved.
#
# This  software is supplied free of charge.  This software, or any part
# of it,  may  not  be  redistributed or otherwise made available to, or
# used  by,  any  other  person  without the inclusion of this copyright
# notice.  This software may not be used to make a profit in any way.
#
# This  software  is provided with absolutely no warranty, to the extent
# permitted  by  applicable  state law.  In no event, unless required by
# applicable law,  will the author(s) of this software be liable for any
# damages caused by this software.


## Create database if necessary
if ! ( -f ${aliasdb} ) then
  cp /dev/null ${aliasdb}
  echo "Created empty database ${aliasdb}"
endif


## Search for user's alias in database
set tuple = `grep ":${address}${dollar}" ${aliasdb}`
if ( ${#tuple} == 0 ) then
  set tuple = `grep ":${address} " ${aliasdb}`
endif

if ( ${#tuple} != 0 ) then
  echo "User at ${address} has an alias"

  set alias = `echo "${tuple}" | cut -d':' -f1`
  set reply = `echo "${tuple}" | cut -d':' -f2- | awk '{ print $1 }'`
  set name  = `echo "${tuple}" | cut -d':' -f2- | awk '{ print $2, $3, $4, $5 }'`

  echo "  alias is ${alias}"
  echo "  reply address is ${reply} ${name}"

  exit 1
endif

echo "User at ${address} does not have an alias"
exit 0
