-
Notifications
You must be signed in to change notification settings - Fork 0
/
octet-filter
executable file
·245 lines (216 loc) · 6.05 KB
/
octet-filter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#!/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
}
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
*.tar ) ShowFileType "$1"; ShowTAR "$1";;
*.tgz ) ShowFileType "$1"; ShowTGZ "$1";;
*.tar.gz ) ShowFileType "$1"; ShowTGZ "$1";;
*.tar.Z ) ShowFileType "$1"; ShowTGZ "$1";;
*.tar.z ) ShowFileType "$1"; ShowTGZ "$1";;
*.tbz2 ) ShowFileType "$1"; ShowTBZ "$1";;
*.tar.bz2 ) ShowFileType "$1"; ShowTBZ "$1";;
*.Z ) ShowFileType "$1"; ShowGZIP "$1";;
*.z ) ShowFileType "$1"; ShowGZIP "$1";;
*.gz ) ShowFileType "$1"; ShowGZIP "$1";;
*.bz2 ) ShowFileType "$1"; ShowBZIP "$1";;
*.zip ) ShowFileType "$1"; ShowZIP "$1";;
*.ZIP ) ShowFileType "$1"; ShowZIP "$1";;
*.arj ) ShowFileType "$1"; ShowARJ "$1";;
*.ARJ ) ShowFileType "$1"; ShowARJ "$1";;
*.log ) ShowFileType "$1"; cat "$1";;
*.LOG ) ShowFileType "$1"; cat "$1";;
*.obj ) ShowFileType "$1"; ShowOBJ "$1";;
*.OBJ ) ShowFileType "$1"; ShowOBJ "$1";;
*.lib ) ShowFileType "$1"; ShowLIB "$1";;
*.LIB ) ShowFileType "$1"; ShowLIB "$1";;
*.NG ) ShowFileType "$1"; ShowNG "$1";;
*.ng ) ShowFileType "$1"; ShowNG "$1";;
*.vcf ) ShowFileType "$1"; ShowVCard "$1";;
*.tif ) ShowFileType "$1"; ShowTIF "$1";;
*.TIF ) ShowFileType "$1"; ShowTIF "$1";;
*.doc ) ShowFileType "$1"; ShowMSWord "$1";;
*.DOC ) ShowFileType "$1"; ShowMSWord "$1";;
*.o ) ShowFileType "$1"; ShowObject "$1";;
*.rpm ) ShowFileType "$1"; ShowRPM "$1";;
*.deb ) ShowFileType "$1"; ShowDEB "$1";;
* ) ShowMISC "$1";;
esac
fi