4 # Copyright 2003 Luke Plant <L.Plant.98@cantab.net>
5 # and Johann Koenig <johann@mental-graffiti.com>
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License
9 # as published by the Free Software Foundation; either version 2
10 # of the License, or (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
22 ##############################################################################
24 # This script is a text viewer designed to be used with sylpheed-claws actions
25 # Set up an action with the command line: textviewer.sh %p |
27 # The script will try to detect file type automatically, and then
28 # invokes a relevant program to print the file in plain text to
29 # the standard output.
31 # From v 0.9.7claws7, sylpheed-claws sets the temporary file
32 # of a part to XXXXXX.mimetmp.[filename of attachment]
33 # This means we can use the extension of the filename for checking.
34 # Also use the program 'file' if that fails.
36 # To extend the script just follow the patterns that already exist, or
37 # contact the author if you have problems.
39 ##############################################################################
44 # - added support for perl and shell scripts, and recognize that
45 # 'file' will always return 'text' somewhere in its output for
46 # files that, well, contain text
49 # - added brief messages describing whats going on
52 # - added support for 'pdftotext,' from xpdf-utils debian package
55 # - added matcher and action for OpenOffice Writer documents
59 # - changed page width parameter for antiword
60 # - fixed matcher for 'diffs'
61 # - added a matcher and action for bzip2 - bzip2 files
62 # are decompressed and textviewer.sh run on the result
63 # - similarly decompress gzip files and run textviewer.sh
64 # on the result, insteading of doing 'gzip -l'
67 # added the script to sylpheed-claws/tools
70 # - use 'fold' after 'unrtf' to wrap to a nice width
71 # - added basic file sanity checks
74 # Added recognition for "Zip " from 'file' output
77 # Initial public release
79 ###############################################################################
83 echo "No filename supplied." >&2
84 echo "Usage: textviewer.sh FILE" >&2
90 echo "File \"$1\" does not exist or is not a regular file." >&2
96 echo "Cannot read file \"$1\"." >&2
100 FILETYPE=`file --brief "$1"` ||
102 echo "Please install the command 'file' to use this script." >&2
107 *.doc) TYPE=MSWORD ;;
109 *.tar.gz|*.tgz) TYPE=TARGZ ;;
110 *.tar.bz2|*.tar.bz) TYPE=TARBZ ;;
112 *.bz2|*.bz) TYPE=BZIP ;;
117 *.sxw) TYPE=OOWRITER ;;
126 *"text"*) TYPE=TEXT ;;
129 "POSIX tar archive"*) TYPE=TAR ;;
137 TARGZ) echo -e "Gzip'd tarball contents:\n" ;
140 TARBZ) echo -e "Bzip'd tarball contents:\n" ;
143 BZIP) TMP=`mktemp "$1".temp.XXXXXXX` || exit 1;
144 bunzip2 -c "$1" > "$TMP" || exit 1;
145 echo -e "Re-running \"$0\" on bunzip'd contents of \"$1\":\n";
149 GZIP) TMP=`mktemp "$1".temp.XXXXXXX` || exit 1;
150 gunzip -c "$1" > "$TMP" || exit 1;
151 echo "Re-running \"$0\" on gunzip'd contents of \"$1\":\n";
155 TAR) echo -e "Tar archive contents:\n" ;
158 ZIP) echo -e "Zip file contents:\n" ;
161 RTF) which unrtf > /dev/null 2>&1 ||
163 echo "Program 'unrtf' for displaying RTF files not found" >&2
166 echo -e "Displaying \"$1\" using \"unrtf\":\n";
167 unrtf -t text "$1" 2>/dev/null | egrep -v '^### ' | fold -s -w 72 ;;
171 MSWORD) which antiword > /dev/null 2>&1 ||
173 echo "Program 'antiword' for displaying MS Word files not found" >&2
176 echo -e "Displaying \"$1\" using \"antiword\":\n";
177 antiword -w 72 "$1" ;;
179 OOWRITER) which ooo2txt > /dev/null 2>&1 ||
181 echo "Program 'ooo2txt' for converting OpenOffice Writer files not files not found" >&2
184 echo -e "Displaying \"$1\" using \"ooo2txt\":\n";
187 PDF) which pdftotext > /dev/null 2>&1 ||
189 echo "Program 'pdftotext' for converting Adobe Portable Document Format to text not found" >&2
192 echo -e "Displaying \"$1\" using \"pdftotext\":\n";
195 *) echo "Unsupported file type \"$FILETYPE\", cannot display.";;