Re: pdf vs. octet-stream
Rick Baartman <[email protected]>
| Newsgroups | gmane.mail.exmh.user |
|---|---|
| Message-ID | <[email protected]> |
OK, I know it's been two years, but all that time it's been bugging me that
Mime_Magic seems to work for most people, but not for me. It really bugs me
because admin people here use Outlook and pdf attachments are listed as type
application/octet-stream, and I have to edit them by hand, changing it to
application/pdf. I was just writing a sed procedure when I couldn't stand it
any more and just had to figure out why exmh couldn't do the substitution for
me, like Mime_Magic was intended to do.
I found the problem, and now I don't understand why Brent and others were not
affected by it.
To refresh memory, here is the out-of-the-box Mime_Magic in 2.7.2:
1proc Mime_Magic { fileName } {
2 global exmh env
3 Exmh_Debug Mime_Magic $fileName
4
5 foreach m [list $exmh(userLibrary)/.magic \
6 $exmh(library)/local.magic" "" ] {
7 # Avoid eval in this command to tolerate spaces in file names
8 set cmd {exec file}
9 if {[string length $m]} {
10 lappend cmd -m $m
11 }
12 lappend cmd $fileName
13 if [catch $cmd result] {
14 continue
15 }
16
17 set result [string trim [lindex [split $result :] 1]]
18
19 foreach res { magic_u magic_l magic_ } {
20 set contentType [option get . $res$result {}]
21 if [string length $contentType] {
22 return $contentType
23 }
24 }
25 }
26
27 return
28}
First, note there is an extraneous double quote on line 6. But that's not the
real problem.
I tested $res$result of line 20 when looking at a pdf file specified as
octet-stream, and it properly gave:
magic_uPDF document, version 1.4
magic_lPDF document, version 1.4
magic_PDF document, version 1.4
I made sure I had the exact same string in my exmh-defaults (I even copied it
with my mouse buffer to be sure):
*magic_lPDF document, version 1.4: application/pdf
and yet, 'option get' turned up no match. GRRR. Thinking maybe it did not like
periods, I split on the comma inserting
set result [string trim [lindex [split $result ,] 0]]
after line 17 and shortened the magic line to
*magic_lPDF document: application/pdf
BINGO!
I don't know whether matching periods is a general problem; in fact I don't
know anything about tcl.
Then I tried this on a png file; one for which the file command gives
PNG image data, 1600 x 1200, 8-bit/color RGB, non-interlaced
This works without modifying Mime_Magic (no periods). But I'm thinking: do we
really want to add all the possible permutations in the magic variables? That
seems retarded. So I propose splitting all on commas. For example for PDF's, we
need only the single line
*magic_lPDF document: application/pdf
instead of all the different versions and not to mention having to add new
versions as they occur.
--
rick baartman