#! /bin/bash -posix
# -*-sh-mode-*-

#     Copyright (C) 1998  Thomas Roessler <roessler@guug.de>
# 
#     This program is free software; you can redistribute it and/or modify
#     it under the terms of the GNU General Public License as published by
#     the Free Software Foundation; either version 2 of the License, or
#     (at your option) any later version.
# 
#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU General Public License for more details.
# 
#     You should have received a copy of the GNU General Public License
#     along with this program; if not, write to the Free Software
#     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

# $Id: lbdb-fetchaddr.sh.in,v 1.4 1999/01/11 23:05:06 roland Exp $

umask 077

dotlock=/usr/bin/mutt_dotlock
prefix=/usr
exec_prefix=${prefix}
fetchaddr=${prefix}/lib/lbdb/fetchaddr
db=$HOME/.lbdb/m_inmail.list

if [ ! -f $db ]; then
  touch $db
  if [ ! -f $db ]; then
    echo "Can't create $db" >&2
    exit 1
  fi
fi

if ! $dotlock -r 10 -f $db ; then
  echo "Can't lock $db [dotlock returned $rv]." >&2
  exit 1
fi

if $fetchaddr >> $db ; then
  ${prefix}/lib/lbdb/munge < $db > $db.$$.tmp
  mv -f $db.$$.tmp $db
fi

$dotlock -u $db
