]> diplodocus.org Git - nmh/blob - etc/mhn.defaults.sh
fgets() reserves space for the NUL itself.
[nmh] / etc / mhn.defaults.sh
1 #!/bin/sh
2 #
3 # mhn.defaults.sh -- create extra profile file for MIME handling
4 #
5 # USAGE: mhn.defaults.sh [ search-path [ search-prog ]]
6
7 # If a search path is passed to the script, we
8 # use that, else we use a default search path.
9 if [ -n "$1" ]; then
10 SEARCHPATH=$1
11 else
12 SEARCHPATH="$PATH"
13 fi
14
15 # If a search program is passed to the script, we
16 # use that, else we use a default search program.
17 if [ -n "$2" ]; then
18 SEARCHPROG=$2
19 else
20 SEARCHPROG="mhn.find.sh"
21 fi
22
23 # put output into a temporary file, so we
24 # can sort it before output.
25 TMP=/tmp/nmh_temp.$$
26 trap "rm -f $TMP" 0 1 2 3 13 15
27
28 if [ ! -z `$SEARCHPROG "$SEARCHPATH" par` ]; then
29 #### The widths here correspond to those for the text browsers below.
30 textfmt=' | par 64'
31 replfmt=" | sed 's/^\(.\)/> \1/; s/^$/>/;' | par 64"
32 elif [ ! -z `$SEARCHPROG "$SEARCHPATH" fmt` ]; then
33 textfmt=' | fmt'
34 replfmt=" | fmt | sed 's/^\(.\)/> \1/; s/^$/>/;'"
35 else
36 textfmt=
37 replfmt=
38 fi
39 [ ! -z `$SEARCHPROG "$SEARCHPATH" iconv` ] &&
40 charsetconv=' | iconv -f ${charset:-us-ascii} -t utf-8'"${textfmt}" ||
41 charsetconv=
42
43 cat >>"$TMP" <<'EOF'
44 mhstore-store-text: %m%P.txt
45 mhstore-store-text/calendar: %m%P.ics
46 mhstore-store-text/html: %m%P.html
47 mhstore-store-text/richtext: %m%P.rt
48 mhstore-store-video/mpeg: %m%P.mpg
49 mhstore-store-application/PostScript: %m%P.ps
50 EOF
51
52 PGM=`$SEARCHPROG "$SEARCHPATH" xwud`
53 if [ ! -z "$PGM" ]; then
54 XWUD="$PGM" X11DIR="`echo $PGM | awk -F/ '{ for(i=2;i<NF;i++)printf "/%s", $i;}'`"/
55 else
56 XWUD= X11DIR=
57 fi
58
59 PGM=`$SEARCHPROG "$SEARCHPATH" pnmtoxwd`
60 if [ ! -z "$PGM" ]; then
61 NETPBM="$PGM" NETPBMDIR="`echo $PGM | awk -F/ '{ for(i=2;i<NF;i++)printf "/%s", $i;}'`"/
62 else
63 NETPBM= NETPBMDIR=
64 fi
65
66 PGM=`$SEARCHPROG "$SEARCHPATH" xv`
67 if [ ! -z "$PGM" ]; then
68 echo "mhshow-show-image: %l$PGM -geometry =-0+0 %f" >> $TMP
69 elif [ ! -z $"NETPBM" -a ! -z "$XWUD" ]; then
70 echo "mhshow-show-image/gif: %l${NETPBMDIR}giftopnm | ${NETPBMDIR}ppmtopgm | ${NETPBMDIR}pgmtopbm | ${NETPBMDIR}pnmtoxwd | $XWUD -geometry =-0+0" >> $TMP
71 echo "mhshow-show-image/x-pnm: %l${NETPBMDIR}pnmtoxwd | $XWUD -geometry =-0+0" >> $TMP
72 echo "mhshow-show-image/x-pgm: %l${NETPBMDIR}pgmtopbm | ${NETPBMDIR}pnmtoxwd | $XWUD -geometry =-0+0" >> $TMP
73 echo "mhshow-show-image/x-ppm: %l${NETPBMDIR}ppmtopgm | ${NETPBMDIR}pgmtopbm | ${NETPBMDIR}pnmtoxwd | $XWUD -geometry =-0+0" >> $TMP
74 echo "mhshow-show-image/x-xwd: %l$XWUD -geometry =-0+0" >> $TMP
75
76 PGM=`$SEARCHPROG "$SEARCHPATH" djpeg`
77 if [ ! -z "$PGM" ]; then
78 echo "mhshow-show-image/jpeg: %l$PGM -Pg | ${NETPBMDIR}ppmtopgm | ${NETPBMDIR}pgmtopbm | ${NETPBMDIR}pnmtoxwd | $XWUD -geometry =-0+0" >> $TMP
79 fi
80 fi
81
82 if [ -f "/dev/audioIU" ]; then
83 PGM=`$SEARCHPROG "$SEARCHPATH" recorder`
84 if [ ! -z "$PGM" ]; then
85 echo "mhstore-store-audio/basic: %m%P.au" >> $TMP
86 echo "mhbuild-compose-audio/basic: ${AUDIODIR}recorder %f -au -pause > /dev/tty" >> $TMP
87 echo "mhshow-show-audio/basic: %l${AUDIODIR}splayer -au" >> $TMP
88 fi
89 elif [ -f "/dev/audio" ]; then
90 PGM=`$SEARCHPROG "$SEARCHPATH" raw2audio`
91 if [ ! -z "$PGM" ]; then
92 AUDIODIR="`echo $PGM | awk -F/ '{ for(i=2;i<NF;i++)printf "/%s", $i;}'`"/
93 echo "mhstore-store-audio/basic: | ${AUDIODIR}raw2audio -e ulaw -s 8000 -c 1 > %m%P.au" >> $TMP
94 echo "mhstore-store-audio/x-next: %m%P.au" >> $TMP
95 AUDIOTOOL=`$SEARCHPROG "$SEARCHPATH" audiotool`
96 if [ ! -z "$AUDIOTOOL" ]; then
97 echo "mhbuild-compose-audio/basic: $AUDIOTOOL %f && ${AUDIODIR}raw2audio -F < %f" >> $TMP
98 else
99 echo "mhbuild-compose-audio/basic: trap \"exit 0\" 2 && ${AUDIODIR}record | ${AUDIODIR}raw2audio -F" >> $TMP
100 fi
101 echo "mhshow-show-audio/basic: %l${AUDIODIR}raw2audio 2>/dev/null | ${AUDIODIR}play" >> $TMP
102
103 PGM=`$SEARCHPROG "$SEARCHPATH" adpcm_enc`
104 if [ ! -z "$PGM" ]; then
105 DIR="`echo $PGM | awk -F/ '{ for(i=2;i<NF;i++)printf "/%s", $i;}'`"/
106 if [ ! -z "$AUDIOTOOL" ]; then
107 echo "mhbuild-compose-audio/x-next: $AUDIOTOOL %f && ${DIR}adpcm_enc < %f" >> $TMP
108 else
109 echo "mhbuild-compose-audio/x-next: ${AUDIODIR}record | ${DIR}adpcm_enc" >> $TMP
110 fi
111 echo "mhshow-show-audio/x-next: %l${DIR}adpcm_dec | ${AUDIODIR}play" >> $TMP
112 else
113 if [ ! -z "$AUDIOTOOL" ]; then
114 echo "mhbuild-compose-audio/x-next: $AUDIOTOOL %f" >> $TMP
115 else
116 echo "mhbuild-compose-audio/x-next: ${AUDIODIR}record" >> $TMP
117 fi
118 echo "mhshow-show-audio/x-next: %l${AUDIODIR}play" >> $TMP
119 fi
120 else
121 echo "mhbuild-compose-audio/basic: cat < /dev/audio" >> $TMP
122 echo "mhshow-show-audio/basic: %lcat > /dev/audio" >> $TMP
123 fi
124 fi
125
126 ####
127 #### mhbuild-disposition-<type>[/<subtype>] entries are used by the
128 #### WhatNow attach for deciding whether the Content-Disposition
129 #### should be 'attachment' or 'inline'. Only those values are
130 #### supported. mhbuild-convert-text/html is defined below.
131 ####
132 cat <<EOF >>${TMP}
133 mhbuild-convert-text/calendar: mhical -infile %F -contenttype
134 mhbuild-convert-text: charset=%{charset}; iconv -f \${charset:-us-ascii} -t utf-8 %F${replfmt}
135 mhbuild-disposition-text/calendar: inline
136 mhbuild-disposition-message/rfc822: inline
137 EOF
138
139 PGM=`$SEARCHPROG "$SEARCHPATH" mpeg_play`
140 if [ ! -z "$PGM" ]; then
141 echo "mhshow-show-video/mpeg: %l$PGM %f" >> $TMP
142 fi
143
144 PGM=`$SEARCHPROG "$SEARCHPATH" okular`
145 if [ ! -z "$PGM" ]; then
146 echo "mhshow-show-application/PostScript: %l$PGM %F" >> $TMP
147 else
148 PGM=`$SEARCHPROG "$SEARCHPATH" evince`
149 if [ ! -z "$PGM" ]; then
150 echo "mhshow-show-application/PostScript: %l$PGM %F" >> $TMP
151 else
152 PGM=`$SEARCHPROG "$SEARCHPATH" gv`
153 if [ ! -z "$PGM" ]; then
154 echo "mhshow-show-application/PostScript: %l$PGM %F" >> $TMP
155 fi
156 fi
157 fi
158
159 PGM=`$SEARCHPROG "$SEARCHPATH" acroread`
160 if [ ! -z "$PGM" ]; then
161 echo "mhshow-show-application/pdf: %l$PGM %F" >> $TMP
162 else
163 PGM=`$SEARCHPROG "$SEARCHPATH" okular`
164 if [ ! -z "$PGM" ]; then
165 echo "mhshow-show-application/pdf: %l$PGM %F" >> $TMP
166 else
167 PGM=`$SEARCHPROG "$SEARCHPATH" evince`
168 if [ ! -z "$PGM" ]; then
169 echo "mhshow-show-application/pdf: %l$PGM %F" >> $TMP
170 else
171 PGM=`$SEARCHPROG "$SEARCHPATH" xpdf`
172 if [ ! -z "$PGM" ]; then
173 echo "mhshow-show-application/pdf: %l$PGM %F" >> $TMP
174 else
175 PGM=`$SEARCHPROG "$SEARCHPATH" gv`
176 if [ ! -z "$PGM" ]; then
177 echo "mhshow-show-application/pdf: %l$PGM %F" >> $TMP
178 fi
179 fi
180 fi
181 fi
182 fi
183
184 echo "mhshow-show-text/calendar: mhical -infile %F" >> $TMP
185 echo "mhfixmsg-format-text/calendar: mhical -infile %F" >> $TMP
186
187 PGM=`$SEARCHPROG "$SEARCHPATH" ivs_replay`
188 if [ ! -z "$PGM" ]; then
189 echo "mhshow-show-application/x-ivs: %l$PGM -o %F" >> $TMP
190 fi
191
192 # The application/vnd.openxmlformats-officedocument.wordprocessingml.document
193 # through application/onenote associations are from
194 # http://technet.microsoft.com/en-us/library/cc179224.aspx
195
196 cat <<EOF >> ${TMP}
197 mhshow-suffix-application/msword: .doc
198 mhshow-suffix-application/ogg: .ogg
199 mhshow-suffix-application/pdf: .pdf
200 mhshow-suffix-application/postscript: .ps
201 mhshow-suffix-application/rtf: .rtf
202 mhshow-suffix-application/vnd.ms-excel: .xla
203 mhshow-suffix-application/vnd.ms-excel: .xlc
204 mhshow-suffix-application/vnd.ms-excel: .xld
205 mhshow-suffix-application/vnd.ms-excel: .xll
206 mhshow-suffix-application/vnd.ms-excel: .xlm
207 mhshow-suffix-application/vnd.ms-excel: .xls
208 mhshow-suffix-application/vnd.ms-excel: .xlt
209 mhshow-suffix-application/vnd.ms-excel: .xlw
210 mhshow-suffix-application/vnd.ms-powerpoint: .pot
211 mhshow-suffix-application/vnd.ms-powerpoint: .pps
212 mhshow-suffix-application/vnd.ms-powerpoint: .ppt
213 mhshow-suffix-application/vnd.ms-powerpoint: .ppz
214 mhshow-suffix-application/vnd.openxmlformats-officedocument.wordprocessingml.document: .docx
215 mhshow-suffix-application/vnd.ms-word.document.macroEnabled.12: .docm
216 mhshow-suffix-application/vnd.openxmlformats-officedocument.wordprocessingml.template: .dotx
217 mhshow-suffix-application/vnd.ms-word.template.macroEnabled.12: .dotm
218 mhshow-suffix-application/vnd.openxmlformats-officedocument.spreadsheetml.sheet: .xlsx
219 mhshow-suffix-application/vnd.ms-excel.sheet.macroEnabled.12: .xlsm
220 mhshow-suffix-application/vnd.openxmlformats-officedocument.spreadsheetml.template: .xltx
221 mhshow-suffix-application/vnd.ms-excel.template.macroEnabled.12: .xltm
222 mhshow-suffix-application/vnd.ms-excel.sheet.binary.macroEnabled.12: .xlsb
223 mhshow-suffix-application/vnd.ms-excel.addin.macroEnabled.12: .xlam
224 mhshow-suffix-application/vnd.openxmlformats-officedocument.presentationml.presentation: .pptx
225 mhshow-suffix-application/vnd.ms-powerpoint.presentation.macroEnabled.12: .pptm
226 mhshow-suffix-application/vnd.openxmlformats-officedocument.presentationml.slideshow: .ppsx
227 mhshow-suffix-application/vnd.ms-powerpoint.slideshow.macroEnabled.12: .ppsm
228 mhshow-suffix-application/vnd.openxmlformats-officedocument.presentationml.template: .potx
229 mhshow-suffix-application/vnd.ms-powerpoint.template.macroEnabled.12: .potm
230 mhshow-suffix-application/vnd.ms-powerpoint.addin.macroEnabled.12: .ppam
231 mhshow-suffix-application/vnd.openxmlformats-officedocument.presentationml.slide: .sldx
232 mhshow-suffix-application/vnd.ms-powerpoint.slide.macroEnabled.12: .sldm
233 mhshow-suffix-application/onenote: .onetoc
234 mhshow-suffix-application/onenote: .onetoc2
235 mhshow-suffix-application/onenote: .onetmp
236 mhshow-suffix-application/onenote: .onepkg
237 mhshow-suffix-application/x-bzip2: .bz2
238 mhshow-suffix-application/x-cpio: .cpio
239 mhshow-suffix-application/x-dvi: .dvi
240 mhshow-suffix-application/x-gzip: .gz
241 mhshow-suffix-application/x-java-archive: .jar
242 mhshow-suffix-application/x-javascript: .js
243 mhshow-suffix-application/x-latex: .latex
244 mhshow-suffix-application/x-sh: .sh
245 mhshow-suffix-application/x-tar: .tar
246 mhshow-suffix-application/x-texinfo: .texinfo
247 mhshow-suffix-application/x-tex: .tex
248 mhshow-suffix-application/x-troff-man: .man
249 mhshow-suffix-application/x-troff-me: .me
250 mhshow-suffix-application/x-troff-ms: .ms
251 mhshow-suffix-application/x-troff: .t
252 mhshow-suffix-application/zip: .zip
253 mhshow-suffix-audio/basic: .au
254 mhshow-suffix-audio/midi: .midi
255 mhshow-suffix-audio/mpeg: .mp3
256 mhshow-suffix-audio/mpeg: .mpg
257 mhshow-suffix-audio/x-ms-wma: .wma
258 mhshow-suffix-audio/x-wav: .wav
259 mhshow-suffix-image/gif: .gif
260 mhshow-suffix-image/jpeg: .jpeg
261 mhshow-suffix-image/jpeg: .jpg
262 mhshow-suffix-image/png: .png
263 mhshow-suffix-image/tiff: .tif
264 mhshow-suffix-image/tiff: .tiff
265 mhshow-suffix-text/calendar: .ics
266 mhshow-suffix-text/css: .css
267 mhshow-suffix-text/html: .html
268 mhshow-suffix-text/rtf: .rtf
269 mhshow-suffix-text/sgml: .sgml
270 mhshow-suffix-text/xml: .xml
271 mhshow-suffix-video/mpeg: .mpeg
272 mhshow-suffix-video/mpeg: .mpg
273 mhshow-suffix-video/quicktime: .moov
274 mhshow-suffix-video/quicktime: .mov
275 mhshow-suffix-video/quicktime: .qt
276 mhshow-suffix-video/quicktime: .qtvr
277 mhshow-suffix-video/x-msvideo: .avi
278 mhshow-suffix-video/x-ms-wmv: .wmv
279 EOF
280
281 # I'd like to check if netscape is available and use it preferentially to lynx,
282 # but only once I've added a new %-escape that makes more permanent temp files,
283 # so netscape -remote can be used (without -remote you get a complaint dialog
284 # that another netscape is already running and certain things can't be done).
285 PGM=`$SEARCHPROG "$SEARCHPATH" w3m`
286 if [ ! -z "$PGM" ]; then
287 echo 'mhshow-show-text/html: charset=%{charset}; '"\
288 %l$PGM"' -dump ${charset:+-I} ${charset:+"$charset"} -T text/html %F' >> $TMP
289 echo 'mhfixmsg-format-text/html: charset=%{charset}; '"\
290 $PGM "'-dump ${charset:+-I} ${charset:+"$charset"} -O utf-8 -T text/html %F' \
291 >> $TMP
292 echo 'mhbuild-convert-text/html: charset=%{charset}; '"\
293 $PGM "'-dump ${charset:+-I} ${charset:+"$charset"} -O utf-8 -T text/html %F '"\
294 ${replfmt}" >> $TMP
295 else
296 PGM=`$SEARCHPROG "$SEARCHPATH" lynx`
297 if [ ! -z "$PGM" ]; then
298 echo 'mhshow-show-text/html: charset=%{charset}; '"\
299 %l$PGM"' -child -dump -force-html ${charset:+--assume_charset} ${charset:+"$charset"} %F' >> $TMP
300 #### lynx indents with 3 spaces, remove them and any trailing spaces.
301 echo 'mhfixmsg-format-text/html: charset=%{charset}; '"\
302 $PGM "'-child -dump -force_html ${charset:+--assume_charset} ${charset:+"$charset"} %F | '"\
303 expand | sed -e 's/^ //' -e 's/ *$//'" >> $TMP
304 echo 'mhbuild-convert-text/html: charset=%{charset}; '"\
305 $PGM "'-child -dump -force_html ${charset:+--assume_charset} ${charset:+"$charset"} '"\
306 %F${replfmt}" >> $TMP
307 else
308 PGM=`$SEARCHPROG "$SEARCHPATH" elinks`
309 if [ ! -z "$PGM" ]; then
310 echo "mhshow-show-text/html: %l$PGM -dump -force-html \
311 -eval 'set document.browse.margin_width = 0' %F" >> $TMP
312 echo "mhfixmsg-format-text/html: $PGM -dump -force-html \
313 -no-numbering -eval 'set document.browse.margin_width = 0' %F" >> $TMP
314 echo "mhbuild-convert-text/html: $PGM -dump -force-html \
315 -no-numbering -eval 'set document.browse.margin_width = 0' %F${replfmt}" >> $TMP
316 else
317 echo 'mhbuild-convert-text/html: cat %F' >> $TMP
318 fi
319 fi
320 fi
321
322 PGM=`$SEARCHPROG "$SEARCHPATH" richtext`
323 if [ ! -z "$PGM" ]; then
324 echo "mhshow-show-text/richtext: %l$PGM -p %F" >> $TMP
325 else
326 PGM=`$SEARCHPROG "$SEARCHPATH" rt2raw`
327 if [ ! -z "$PGM" ]; then
328 echo "mhshow-show-text/richtext: %l$PGM < %f | fmt -78 | more" >> $TMP
329 fi
330 fi
331
332 # staroffice to read .doc files
333 PGM=`$SEARCHPROG "$SEARCHPATH" soffice`
334 if [ ! -z "$PGM" ]; then
335 echo "mhshow-show-application/msword: %l$PGM %F" >> $TMP
336 fi
337
338 # This entry is used to retrieve external-body types that use a "url"
339 # access-type.
340 case "`uname`" in
341 FreeBSD)
342 echo "nmh-access-url: fetch -o -" >> $TMP
343 ;;
344 *)
345 PGM=`$SEARCHPROG "$SEARCHPATH" curl`
346 if [ ! -z "$PGM" ]; then
347 echo "nmh-access-url: $PGM -L" >> $TMP
348 fi
349 ;;
350 esac
351
352 # output a sorted version of the file
353 sort < $TMP
354
355 exit 0
356
357
358 ###############################################################################
359 ###############################################################################
360 ####
361 #### Note the exit 0 above; everything below is unused.
362 ####
363 ###############################################################################
364 ###############################################################################
365
366 : have to experiment more with this
367
368 PGM=`$SEARCHPROG "$SEARCHPATH" ivs_record`
369 if [ ! -z "$PGM" ]; then
370 echo "mhbuild-compose-application/x-ivs: $PGM -u localhost %F" >> $TMP
371 fi