Description: Changes recover script so it can be run by init
This was mostly just merging code from the previous init script
Author: Bryan Quigley <bryan.quigley@canonical.com>

---
Bug-Debian: https://bugs.debian.org/796635
Bug-Ubuntu: https://launchpad.net/bugs/1489939
Forwarded: no
Last-Update: <2024-02-15>

diff --git a/dist/recover.in b/dist/recover.in
index 8b87a6b..daa9ced 100644
--- a/dist/recover.in
+++ b/dist/recover.in
@@ -8,11 +8,18 @@ RECDIR="@vi_cv_path_preserve@"
 SENDMAIL="@vi_cv_path_sendmail@"
 
 echo 'Recovering nvi editor sessions.'
+sessions_found=""
 
 # Check editor backup files.
 vibackup=`echo $RECDIR/vi.*`
 if [ "$vibackup" != "$RECDIR/vi.*" ]; then
 	for i in $vibackup; do
+                # Discard symlinks
+                if test -L $i ; then
+                        rm -f $i
+                        continue
+                fi
+
 		# Only test files that are readable.
 		if test ! -r $i; then
 			continue
@@ -36,6 +43,12 @@ fi
 virecovery=`echo $RECDIR/recover.*`
 if [ "$virecovery" != "$RECDIR/recover.*" ]; then
 	for i in $virecovery; do
+                # Discard symlinks
+                if test -L $i ; then
+                        rm -f $i
+                        continue
+                fi
+
 		# Only test files that are readable.
 		if test ! -r $i; then
 			continue
@@ -49,11 +62,21 @@ if [ "$virecovery" != "$RECDIR/recover.*" ]; then
 		# Delete any recovery files that are zero length, corrupted,
 		# or that have no corresponding backup file.  Else send mail
 		# to the user.
-		recfile=`awk '/^X-vi-recover-path:/{print $2}' < $i`
-		if test -n "$recfile" -a -s "$recfile"; then
-			$SENDMAIL -t < $i
-		else
-			rm $i
-		fi
+                recfile=`awk '/^X-vi-recover-path:/{print $2}' < $i`
+                if test -n "$recfile" -a -s "$recfile"; then
+                        sessions_found="yes"
+                        owner=`stat --format='%U' $recfile`
+                        (su nobody -s /bin/sh -c "$SENDMAIL $owner" < $i &) </dev/null >/dev/null 2>&0
+                else
+                        rm $i
+                fi
 	done
 fi
+
+if [ -n "$sessions_found" ] ; then 
+        echo "done."
+else
+        echo "none found."
+fi
+
+
