rndm_luser /.mutt/bin/octet-filter

Taken from www.davep.org/mutt/. Added ``ShowRar''.
#!/bin/sh
#
#     mutt.octet.filter - Octet filter for use with the mutt autoview facility
#     Copyright (C) 1997,1998,1999,2000 David A Pearson
#   
#     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.
#

#
# This script file is a pretty brain-dead, last resort, "works for me"
# utility that will attempt to make sense of any octet-stream data
# that is received as part of an email and act as a filter for use
# with mutt's auto_view ability.
#
# Here is how I use it. In my ~/.mutt_mailcap (use your filename of
# choice) I have the following entry:
#
# application/octet-stream; mutt.octet.filter %s; copiousoutput
#
# All you then need to do is add a line like:
#
# auto_view application/octet-stream 
#
# to your ~/.muttrc (use your filename of choice).
#
# In it's current state the script isn't perfect, it's your typical
# "works for me" type of script and is offered in the hope that it
# maybe handy and that you can do something with it.
#
# All comments/flames/feedback can be directed to:
#
#               davep@davep.org
#

# $OrigLog: mutt.octet.filter,v $
# Revision 1.6  2000/05/10 13:34:19  davep
# Added patch from Aaron Schrab for handling RPM files.
#
# Revision 1.5  2000/02/28 15:28:13  davep
# Added support for .tar.bz2 files (thanks to Dirk Pirschel for that).
#
# Revision 1.4  1999/08/02 12:39:27  davep
# Minor nit-fix.
#
# Revision 1.3  1999/04/13 17:17:03  davep
# Added support for displaying .o files.
#
# Revision 1.2  1999/01/27 17:35:25  davep
# Added handling for .bz2 files (thanks to Lars Hecking for that).
# Added handling of MSWord documents (requires catdoc).
#
# Revision 1.1  1998/10/14 16:00:25  davep
# Initial revision
#
# http://www.davep.org/mutt/
# ftp://ftp.mutt.org/mutt/contrib/mutt-octet-filter.tar.gz

ShowTAR()
{
    tar tvvf "$1" 2> /dev/null
}

ShowTGZ()
{
    tar tzvvf "$1" 2> /dev/null
}

ShowTBZ()
{
    bzip2 -dc "$1" | tar -tvv -f- 2> /dev/null
}

ShowGZIP()
{
    gzip -dc "$1" 2> /dev/null
}

ShowBZIP()
{
    bzip2 -dc "$1" 2> /dev/null
}

ShowZIP()
{
    unzip -l "$1" 2> /dev/null
}

ShowARJ()
{
    unarj l "$1" 2> /dev/null
}

ShowEXE()
{
    echo $(basename "$1"): DOS/Windows executable
}

ShowOBJ()
{
    echo $(basename "$1"): DOS/Windows object file
}

ShowLIB()
{
    echo $(basename "$1"): MS-DOS program library
}

ShowNG()
{
    echo $(basename "$1"): Norton Guide Database
}

ShowVCard()
{
    cat "$1" | vcard-filter
}

ShowTIF()
{
    tiffinfo "$1"
}

ShowMSWord()
{
    #lhalw --column 80 --to_stdout "$1" 2> /dev/null
    #word2x-filter < $1
    #catdoc "$1"
    antiword "$1"
}

ShowObject()
{
    nm "$1"
}

ShowRPM()
{
    rpm -qip "$1"
}

ShowDEB()
{
   dpkg --info $1; dpkg --contents $1; 
}

ShowData()
{
    echo $(basename "$1"): unprintable data
}

ShowRar()
{
    rar lt "$1"
}

DisplayFileType()
{
    echo "[-- $(basename $0) file type: \"$1\" --]"
    echo
}

ShowFileType()
{
    FILE_TYPE=$(echo $(file -L "$1" 2> /dev/null) | cut -d' ' -f 2-)
    DisplayFileType "$FILE_TYPE"
}

ShowMISC()
{
    FILE_TYPE=$(file -L -z "$1" 2> /dev/null)

    if [ $? -gt 0 ]
    then
	FILE_TYPE=$(file -L "$1" 2> /dev/null)
    fi

    FILE_TYPE=$(echo "$FILE_TYPE" | cut -d' ' -f 2-)

    DisplayFileType "$FILE_TYPE"

    case "$FILE_TYPE" in
	*tar*archive*gzip* ) ShowTGZ  "$1";;
	*tar*archive*      ) ShowTAR  "$1";;
	*gzip*             ) ShowGZIP "$1";;
	*bzip2*            ) ShowBZIP "$1";;
	*ARJ*archive*data* ) ShowARJ  "$1.";; # "." gets round bug in unarj.
	*zip*archive*file* ) ShowZIP  "$1";;
	*DOS*executable*   ) ShowEXE  "$1";;
	*ascii*text*       ) cat      "$1";;
	*c*program*text*   ) cat      "$1";;
	*8086*reloc*Micro* ) ShowOBJ  "$1";;
	*MS-DOS*prog*lib*  ) ShowLIB  "$1";;
	data               ) ShowData "$1";;
	*Microsoft*Word*   ) ShowMSWord "$1";;
	*                  ) cat      "$1";;
    esac
}

if [ "$1" = "" ]
then
    echo "syntax: $(basename '$0') file"
else
    case "$1" in
	*.ARJ )     ShowFileType "$1"; ShowARJ    "$1";;
	*.LIB )     ShowFileType "$1"; ShowLIB    "$1";;
	*.LOG )     ShowFileType "$1"; cat        "$1";;
	*.NG )      ShowFileType "$1"; ShowNG     "$1";;
	*.OBJ )     ShowFileType "$1"; ShowOBJ    "$1";;
	*.TIF )     ShowFileType "$1"; ShowTIF    "$1";;
	*.Z )       ShowFileType "$1"; ShowGZIP   "$1";;
	*.ZIP )     ShowFileType "$1"; ShowZIP    "$1";;
	*.arj )     ShowFileType "$1"; ShowARJ    "$1";;
	*.deb )	    ShowFileType "$1"; ShowDEB    "$1";;
	*.gz )      ShowFileType "$1"; ShowGZIP   "$1";;
	*.lib )     ShowFileType "$1"; ShowLIB    "$1";;
	*.log )     ShowFileType "$1"; cat        "$1";;
	*.ng )      ShowFileType "$1"; ShowNG     "$1";;
	*.obj )     ShowFileType "$1"; ShowOBJ    "$1";;
	*.tar )     ShowFileType "$1"; ShowTAR    "$1";;
	*.tar.Z )   ShowFileType "$1"; ShowTGZ    "$1";;
	*.tar.gz )  ShowFileType "$1"; ShowTGZ    "$1";;
	*.tar.z )   ShowFileType "$1"; ShowTGZ    "$1";;
	*.tgz )     ShowFileType "$1"; ShowTGZ    "$1";;
	*.tif )     ShowFileType "$1"; ShowTIF    "$1";;
	*.vcf )     ShowFileType "$1"; ShowVCard  "$1";;
	*.z )       ShowFileType "$1"; ShowGZIP   "$1";;
	*.zip )     ShowFileType "$1"; ShowZIP    "$1";;
        *.DOC )     ShowFileType "$1"; ShowMSWord "$1";;
        *.bz2 )     ShowFileType "$1"; ShowBZIP   "$1";;
        *.doc )     ShowFileType "$1"; ShowMSWord "$1";;
        *.o )       ShowFileType "$1"; ShowObject "$1";;
        *.rar )     ShowFileType "$1"; ShowRar    "$1";;
        *.rpm )     ShowFileType "$1"; ShowRPM    "$1";;
        *.tar.bz2 ) ShowFileType "$1"; ShowTBZ    "$1";;
        *.tbz2 )    ShowFileType "$1"; ShowTBZ    "$1";;
	* )         ShowMISC "$1";;
    esac
fi