#!/bin/bash
#
# $Id$

export ORIGINAL=$1
shift

if [ -z "$ORIGINAL" ] ; then
  echo "FATAL: No file specified to edit."
  exit 1
fi

if [ ! -f "$ORIGINAL" ] ; then 
  echo "FATAL: No such file: $ORIGINAL"
  exit 2
fi

export GPGNAME=$(echo "$ORIGINAL" |egrep "\.(gpg|pgp)$" 2>/dev/null)
if [ -z "$GPGNAME" ] ; then
  echo "FATAL: File not named .gpg or .pgp: $ORIGINAL"
  exit 3
fi

ENCTOLIST=$(gpg --decrypt --list-only --status-fd 1 2>/dev/null $ORIGINAL |grep ENC_TO |awk '{print $3}')
#echo "ENCTOLIST=$ENCTOLIST"
RECIPIENTS=$(gpg --list-keys $ENCTOLIST |egrep "<.*@.*>" |cut -f2 -d '<' |cut -f1 -d '>')
#echo "RECIPIENTS=$RECIPIENTS"

echo "$ORIGINAL is decryptable for:"
#gpg --list-keys $ENCTOLIST 
#gpg --list-keys $ENCTOLIST |egrep "<.*@.*>" |sed -e 's/uid\s*//' |sort |uniq
gpg --list-keys $ENCTOLIST |egrep "^uid" |sed -e 's/uid\s*//' |sort |uniq


