mutt_bgrun_evince (3773B)
1 #!/bin/sh 2 # @(#) mutt_bgrun $Revision: 1.4 $ 3 4 # mutt_bgrun - run an attachment viewer from mutt in the background 5 # Copyright (C) 1999-2002 Gary A. Johnson 6 # 7 # This program is free software; you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation; either version 2 of the License, or 10 # (at your option) any later version. 11 # 12 # This program is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with this program; if not, write to the Free Software 19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 21 # SYNOPSIS 22 # mutt_bgrun viewer [viewer options] file 23 # 24 # DESCRIPTION 25 # Mutt invokes external attachment viewers by writing the 26 # attachment to a temporary file, executing the pipeline specified 27 # for that attachment type in the mailcap file, waiting for the 28 # pipeline to terminate, writing nulls over the temporary file, 29 # then deleting it. This causes problems when using graphical 30 # viewers such as qvpview and acroread to view attachments. 31 # 32 # If qvpview, for example, is executed in the foreground, the mutt 33 # user interface is hung until qvpview exits, so the user can't do 34 # anything else with mutt until he or she finishes reading the 35 # attachment and exits qvpview. This is especially annoying when 36 # a message contains several MS Office attachments--one would like 37 # to have them all open at once. 38 # 39 # If qvpview is executed in the background, it must be given 40 # enough time to completely read the file before returning control 41 # to mutt, since mutt will then obliterate the file. Qvpview is 42 # so slow that this time can exceed 20 seconds, and the bound is 43 # unknown. So this is again annoying. 44 # 45 # The solution provided here is to invoke the specified viewer 46 # from this script after first copying mutt's temporary file to 47 # another temporary file. This script can then quickly return 48 # control to mutt while the viewer can take as much time as it 49 # needs to read and render the attachment. 50 # 51 # EXAMPLE 52 # To use qvpview to view MS Office attachments from mutt, add the 53 # following lines to mutt's mailcap file. 54 # 55 # application/msword; mutt_bgrun qvpview %s 56 # application/vnd.ms-excel; mutt_bgrun qvpview %s 57 # application/vnd.ms-powerpoint; mutt_bgrun qvpview %s 58 # 59 # AUTHOR 60 # Gary A. Johnson 61 # <garyjohn@spk.agilent.com> 62 # 63 # ACKNOWLEDGEMENTS 64 # My thanks to the people who have commented on this script and 65 # offered solutions to shortcomings and bugs, especially Edmund 66 # GRIMLEY EVANS <edmundo@rano.org> and Andreas Somogyi 67 # <aso@somogyi.nu>. 68 69 prog=${0##*/} 70 71 # Check the arguments first. 72 73 # Separate the arguments. Assume the first is the viewer, the last is 74 # the file, and all in between are options to the viewer. 75 76 viewer="evince" 77 78 while [ "$#" -gt "1" ] 79 do 80 options="$options $1" 81 shift 82 done 83 84 file=$1 85 86 # Create a temporary directory for our copy of the temporary file. 87 # 88 # This is more secure than creating a temporary file in an existing 89 # directory. 90 91 tmpdir=~/temp/$LOGNAME$$ 92 umask 077 93 mkdir "$tmpdir" || exit 1 94 tmpfile="$tmpdir/${file##*/}" 95 96 # Copy mutt's temporary file to our temporary directory so that we can 97 # let mutt overwrite and delete it when we exit. 98 99 cp "$file" "$tmpfile" 100 101 # Run the viewer in the background and delete the temporary files when done. 102 # add some grace time to reload the file with a different encoding in fx 103 104 ( 105 "$viewer" $options "$tmpfile" 106 sleep 30 107 rm -f "$tmpfile" 108 rmdir "$tmpdir" 109 ) &