]>
git.rmz.io Git - dotfiles.git/blob - mutt/mutt_bgrun
   2 # @(#) mutt_bgrun $Revision: 1.4 $ 
   4 #   mutt_bgrun - run an attachment viewer from mutt in the background 
   5 #   Copyright (C) 1999-2002 Gary A. Johnson 
   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. 
  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. 
  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. 
  22 #       mutt_bgrun viewer [viewer options] file 
  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.  
  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.  
  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.  
  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.  
  52 #       To use qvpview to view MS Office attachments from mutt, add the 
  53 #       following lines to mutt's mailcap file. 
  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 
  61 #       <garyjohn@spk.agilent.com> 
  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 
  71 # Check the arguments first. 
  75     echo "usage: $prog viewer [viewer options] file" >&2 
  79 # Separate the arguments.  Assume the first is the viewer, the last is 
  80 # the file, and all in between are options to the viewer. 
  85 while [ "$#" -gt "1" ] 
  93 # Create a temporary directory for our copy of the temporary file. 
  95 # This is more secure than creating a temporary file in an existing 
  98 tmpdir
=/tmp
/$LOGNAME$$
 
 100 mkdir "$tmpdir" || exit 1 
 101 tmpfile
="$tmpdir/${file##*/}" 
 103 # Copy mutt's temporary file to our temporary directory so that we can 
 104 # let mutt overwrite and delete it when we exit. 
 106 cp "$file" "$tmpfile" 
 108 # Run the viewer in the background and delete the temporary files when done.  
 111     "$viewer" $options "$tmpfile" >/dev
/null 
2>&1