#!/bin/sh # # octet-filter - a program to deal with application/octet type MIME # parts. # # Based on # # mutt.octet.filter - Octet filter for use with the mutt autoview # facility # # Copyright (C) 1997,1998,1999 David A Pearson # davep@hagbard.demon.co.uk # # 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., 675 Mass Ave, Cambridge, MA 02139, # USA. # # In your .mailcap, add the following line: # # application/octet-stream; octet-filter %s; copiousoutput # # Then add the line # # auto_view application/octet-stream # # to your ~/.muttrc (use your filename of choice). # ShowTGZ() { ( gzcat "$1" || cat $1 ) 2>/dev/null | tar tvf - 2>/dev/null } ShowGZIP() { gzip -l "$1" 2>/dev/null } ShowZIP() { unzip -l "$1" 2>/dev/null } ShowCPIOZ() { ( gzcat "$1" || cat $1 ) 2>/dev/null | cpio -it 2>/dev/null } ShowTBZ2() { ( bunzip2 -c "$1" || cat $1 ) 2>/dev/null | tar tvf - 2>/dev/null } ShowZIP() { unzip -l "$1" 2>/dev/null } ShowPKGZ() { ( gzcat "$1" || cat $1 ) 2>/dev/null | pkginfo -l -d - 2>/dev/null } ShowARJ() { unarj l "$1" 2>/dev/null } ShowVCard() { vcard-filter < "$1" } ShowRTF() { rtfreader < "$1" } ShowTIF() { tiffinfo "$1" } ShowPDF() { pdfinfo "$1" } ShowMSWord() { catdoc "$1" } ShowHTML() { lynx -dump -force_html "$1" } Showdata() { echo `basename "$1"`: unprintable data } DisplayFileType() { echo "[-- `basename $0` file type: \"$1\" --]" echo } ShowFileType() { FILE_TYPE=echo `file -z "$1" 2>/dev/null | cut -d' ' -f 2-` DisplayFileType "$FILE_TYPE" } # Main part of script. if [ "$1" = "" ] then echo "syntax: `basename '$0'` file" else FILE_TYPE=`file -z "$1" 2>/dev/null` if [ $? -gt 0 ] then FILE_TYPE=`file "$1" 2>/dev/null` fi FILE_TYPE=`echo "$FILE_TYPE" | cut -d' ' -f 2-` DisplayFileType "$FILE_TYPE" case "$FILE_TYPE" in *tar*archive* ) ShowTGZ "$1";; *cpio*archive* ) ShowCPIOZ "$1";; *Zip*archive* ) ShowZIP "$1";; *Rich*Text*Format* ) ShowRTF "$1";; *bzip2*archive* ) ShowTBZ2 "$1";; *ARJ*archive* ) ShowARJ "$1.";; # "." gets round bug in unarj. *pkg*Datastream* ) ShowPKGZ "$1";; *TIFF*Image* ) ShowTIFF "$1";; *PDF*document* ) ShowPDF "$1";; *gzip* ) ShowGZIP "$1";; *ascii*text* ) cat -v "$1";; *c*program*text* ) cat -v "$1";; *HTML* ) ShowHTML "$1";; *data*compress*data*) Showdata "$1";; *ELF*Intel* ) Showdata "$1";; *Microsoft*Office*Document* ) ShowMSWord "$1";; data ) Showdata "$1";; * ) cat -v "$1";; esac fi