#! /bin/bash -posix
# -*-sh-mode-*-
#
#     Copyright (C) 1999  Roland Rosenfeld <roland@spinnaker.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-munge.sh.in,v 1.3 1999/09/15 09:43:12 roland Exp $

LBDB_VERSION=0.18.5

umask 077

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

if [ ! -f $db.dirty ]; then
    # Nothing to do
    exit 0
fi

if $dotlock -r 10 -f $db
then
  : # okay, do nothing
else
  echo "Can't lock $db [dotlock returned $rv]." >&2
  exit 1
fi

$munge < $db > $db.$$.tmp
mv -f $db.$$.tmp $db
rm -f $db.dirty

$dotlock -u $db
