All pastes #783984 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-11-19 13:46 UTC
rendered paste body
#!/bin/sh
# @(#) mutt_netscape $Revision: 1.1 $

#   mutt_netscape - run netscape from mutt in the background
#   Copyright (C) 1999-2001 Gary A. Johnson
#
#   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-1307, USA.

# SYNOPSIS
#	mutt_netscape file
#
# DESCRIPTION
#	Mutt invokes external attachment viewers by writing the
#	attachment to a temporary file, executing the pipeline specified
#	for that attachment type in the mailcap file, waiting for the
#	pipeline to terminate, writing nulls over the temporary file,
#	then deleting it.  This causes problems when using netscape to
#	view HTML attachments.
#
#	If netscape is executed in the foreground, the mutt user
#	interface is hung until netscape exits, so the user can't do
#	anything else with mutt until he or she finishes reading the
#	attachment and exits netscape.
#
#	If netscape is executed in the background, it must be given
#	enough time to completely read the file before returning control
#	to mutt, since mutt will then obliterate the file.
#
#	The solution provided here is to invoke netscape from this
#	script after first copying mutt's temporary file to another
#	temporary file.  This script can then quickly return control to
#	mutt while netscape can take as much time as it needs to read
#	and render the attachment.
#
# EXAMPLE
#	To use netscape to view HTML attachments from mutt, add the
#	following line to mutt's mailcap file.
#
#	text/html;	mutt_netscape %s
#
# BUGS
#	This script does not rm the the "temporary" file created in
#	/tmp, so the user should clean these out periodically.	Because
#	most users have netscape running all the time, and because the
#	/opt/spk/inv/netscape invocatable executes netscape in the
#	background, this script cannot determine when netscape and/or
#	the user is done with a file.
#
# AUTHOR
#	Gary A. Johnson
#	<garyjohn@spk.agilent.com>

# Check the arguments.

if [ "$#" -ne "1" ]
then
    echo "usage: ${0##*/} file" >&2
    exit 1
fi

# Create a temporary directory for our copy of the temporary file.
#
# This is more secure than creating a temporary file in an existing
# directory.

tmpdir=$(mktemp -d || exit 1)
umask 077
# mkdir "$tmpdir" || exit 1
tmpfile="$tmpdir/${1##*/}"

# Copy mutt's temporary file to our temporary directory so that netscape
# can still access the file after this script exits and mutt overwrites
# and deletes its temporary file.

cp "$1" "$tmpfile"

# Try to open a new window from an already-running netscape.  If that
# fails--there is no netscape already running--launch a new netscape.

epiphany --new-window file:$tmpfile 2> /dev/null || 
    epiphany file:$tmpfile

echo "sleep 20 && rm $tmpfile &&  rmdir $tmpdir" | at -M now 2>/dev/null