#! /bin/sh

#
#     Copyright (c) 2000 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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
#
#    Modified by Nicols Lichtmaier to be a customization file for the
#    `bug' reporting tool.


prefix=/usr
DEBUGGER=/usr/bin/gdb
SENDMAIL=/usr/sbin/sendmail
sysconfdir=/etc
sharedir=/usr/share/mutt

SCRATCH=${TMPDIR-/tmp}/`basename $0`.`hostname`.$$

mkdir ${SCRATCH} || \
{ 
	echo "`basename $0`: Can't create temporary directory." >& 2 ; 
	exit 1 ; 
}

trap "rm -r -f ${SCRATCH} ; trap '' 0 ; exit" 0 1 2

debug_gdb ()
{
	cat << EOF > $SCRATCH/gdb.rc
set width 180
bt
quit
EOF
	$DEBUGGER -n -x "$SCRATCH/gdb.rc" -c "$CORE" $(which mutt)
}

include_file ()
{
	(
	echo
	echo "--- Begin $1"
	sed -e 's/^-/- -/' $1 | egrep -v '^[ 	]*(#|$)'
	echo "--- End $1"
	echo
	) >&3
}

echo

if test -x $DEBUGGER ; then
	test -f core && CORE=core
	echo "If mutt has crashed, it may have saved some  program state in"
	echo "a file named core.  We can include this information with the bug"
	echo "report if you wish so."
	echo "Do you want to include information gathered from a core file?"
	echo "If yes, please enter the path - otherwise just say no: [$CORE]"
	echo -n "> "
	read _CORE
	test "$_CORE" && CORE="$_CORE"
fi

echo -n "Do you want to include your personal mutt configuration files? [Y|n] $c"
read personal
case "$personal" in
[nN]*)  personal=no  ;;
    *)  personal=yes ;;
esac

(
if test "$CORE" && test -f "$CORE" ; then
	echo 
	echo "-- Core Dump Analysis Output"
	echo

	case "$DEBUGGER" in
		*gdb) debug_gdb $CORE ;;
	esac
	
	echo
fi
) >&3

if test "$personal" = "yes" ; then
	CANDIDATES=".muttrc-${MUTTVERSION} .muttrc .mutt/muttrc-${MUTTVERSION} .mutt/muttrc"
	MATCHED="none"
	for f in $CANDIDATES; do
		if test -f "${HOME}/$f" ; then
			MATCHED="${HOME}/$f"
			break
	        fi
	done
	
	if test "$MATCHED" = "none" ; then
		echo "Warning: Can't find your personal .muttrc." >&3
	else
		include_file $MATCHED
	fi
fi
