[Mimedefang] Determine mime type
    Kelson Vibber 
    kelson at speed.net
       
    Fri Sep 12 18:28:02 EDT 2003
    
    
  
At 02:20 PM 9/12/2003, Lucas Albers wrote:
>How can you determine the mime type of a file in mimedefang?
Look into the File::MMagic Perl module.  It's similar in concept to the 
"file" command, and can use the magic.mime file.
I use it to check certain types of common documents (Word files, for 
instance) which sometimes trigger filter_bad_filename by virtue of having 
names like "New text for whatever.com.doc".  If a file triggers 
filter_bad_filename, and ends in one of these extensions, my filter calls 
File::MMagic and compares it to the declared MIME type.  So if the file 
claims to be application/msword, has ".com" in the middle of the filename, 
ends in ".doc", *and* File::MMagic determines it is a Word file, then I 
allow it through anyway.
Some of the drawbacks: Sometimes it returns a description instead of a MIME 
type (i.e. "PDF Document" instead of "application/pdf").  Also, its tests 
to identify Word documents sometimes trigger on other MS Office files, so 
sometimes an Excel or PowerPoint file will get identified as Word.
Kelson Vibber
SpeedGate Communications <www.speed.net> 
    
    
More information about the MIMEDefang
mailing list