4 # Copyright 2003 Luke Plant <L.Plant.98@cantab.net>
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 ##############################################################################
23 # This script is a text viewer designed to be used with sylpheed-claws actions
24 # Set up an action with the command line: textviewer.sh %p |
26 # The script will try to detect file type automatically, and then
27 # invokes a relevant program to print the file in plain text to
28 # the standard output.
30 # From v 0.9.7claws7, sylpheed-claws sets the temporary file
31 # of a part to XXXXXX.mimetmp.[filename of attachment]
32 # This means we can use the extension of the filename for checking.
33 # Also use the program 'file' if that fails.
35 # To extend the script just follow the patterns that already exist, or
36 # contact the author if you have problems.
38 ##############################################################################
43 # - added matcher and action for OpenOffice Writer documents
47 # - changed page width parameter for antiword
48 # - fixed matcher for 'diffs'
49 # - added a matcher and action for bzip2 - bzip2 files
50 # are decompressed and textviewer.sh run on the result
51 # - similarly decompress gzip files and run textviewer.sh
52 # on the result, insteading of doing 'gzip -l'
55 # added the script to sylpheed-claws/tools
58 # - use 'fold' after 'unrtf' to wrap to a nice width
59 # - added basic file sanity checks
62 # Added recognition for "Zip " from 'file' output
65 # Initial public release
67 ###############################################################################
71 echo "No filename supplied." >&2
72 echo "Usage: textviewer.sh FILE" >&2
78 echo "File \"$1\" does not exist or is not a regular file." >&2
84 echo "Cannot read file \"$1\"." >&2
88 FILETYPE=`file --brief "$1"` ||
90 echo "Please install the command 'file' to use this script." >&2
97 *.tar.gz|*.tgz) TYPE=TARGZ ;;
98 *.tar.bz) TYPE=TARBZ ;;
105 *.sxw) TYPE=OOWRITER ;;
111 "'diff'"*) TYPE=TEXT ;;
118 "smtp mail text"* | "RFC 822 mail text"*)
120 "Bourne shell script"* | "Bourne-Again shell script"*)
126 TARGZ) echo -e "Tarball contents:\n" ;
129 TARBZ) echo -e "Tarball contents:\n" ;
132 BZIP) TMP=`mktemp "$1".temp.XXXXXXX` || exit 1;
133 bunzip2 -c "$1" > "$TMP" || exit 1;
137 GZIP) TMP=`mktemp "$1".temp.XXXXXXX` || exit 1;
138 gunzip -c "$1" > "$TMP" || exit 1;
142 TAR) echo -e "Tar archive contents:\n" ;
145 ZIP) unzip -l "$1" ;;
147 RTF) which unrtf > /dev/null 2>&1 ||
149 echo "Program 'unrtf' for displaying RTF files not found" >&2
152 unrtf -t text "$1" 2>/dev/null | egrep -v '^### ' | fold -s -w 72 ;;
156 MSWORD) which antiword > /dev/null 2>&1 ||
158 echo "Program 'antiword' for displaying MS Word files not found" >&2
161 antiword -w 72 "$1" ;;
163 OOWRITER) which ooo2txt > /dev/null 2>&1 ||
165 echo "Program 'ooo2txt' for converting OpenOffice Writer files not files not found" >&2
170 *) echo "Unsupported file type \"$FILETYPE\", cannot display.";;