MIME stuff - Am I missing something?

2001-05-22 Thread Barbie

Using the code below, and calling the routine with a *.jpg file. Why does
the mime_type return text/plain? I've also tried using MIME::Head-read
with a filehandle and it returns the same. I would investigate CPAN further
for clues (and the examples that ActivePerl decided not to include), but it
doesn't seem to want to respond to me today :(

Barbie.


sub parseMIME {
 $myfile = shift;

 use MIME::Head;

 ### Parse a new header from a filehandle:
$head = MIME::Head-from_file($myfile);

### The content type (e.g., text/html):
$mime_type = $head-mime_type;

 return split(/,$mime_type);
}






Re: MIME stuff - Am I missing something?

2001-05-22 Thread Jonathan Peterson

At 13:27 22/05/01 +0100, you wrote:

I don't know if you are parsing mail or something else, but in the past I've had luck 
with MIME::Parser using the effective_type() method to get the mime type out of emails.

If you are trying to figure it out magically based on just the file format or filename 
or something(e.g. just pointing it at a raw jpeg) I didn't think MIME:: would help. 
Could be wrong tho. Apache has some stuff that attempts to do this, but unless you 
fancy making your program a mod_perl handler that won't help you much.

use MIME::Parser;
my $parser = new MIME::Parser;
$parser-output_to_core(1);
$parser-decode_headers(1);

my $message;
my $errors;
### Parse input:
my $entity = $parser-parse(\*STDIN) or $errors .= parse failed $!\n;

$message-{head} = $entity-head();
$message-{body}-{attachments} = []; #put attachments (if any) in here
if($message-{body}-{text} = $entity-bodyhandle()) # if it's single part 
{
#if they've sent a message that _only_ contains non-text data as a 
 #single part
if ($entity-effective_type !~ /text/)

...



-- 
Jonathan Peterson
Technical Manager, Unified Ltd, 020 7383 6092
[EMAIL PROTECTED]




Re: MIME stuff - Am I missing something?

2001-05-22 Thread Barbie

From: Dominic Mitchell [EMAIL PROTECTED]

 Dunno about your MIME problem (sorry), but somebody on irc mentioned
 trying cpan2.org instead.

Ahh! Got it. Thanks.

Found the following:

Due to nonuniqueness of MIME encodings, there is a very good chance
that your output will not Iexactly resemble your input. 

So it seems it's taken a best guess, because it didn't understand the
encoding. Back to the drawing board.

Barbie.





Re: MIME stuff - Am I missing something?

2001-05-22 Thread Barbie

From: Jonathan Peterson [EMAIL PROTECTED]

 I don't know if you are parsing mail or something else,

Isolated file.

 If you are trying to figure it out magically based on just the file format
or filename or
 something (e.g. just pointing it at a raw jpeg) I didn't think MIME::
would help.
 Could be wrong tho. Apache has some stuff that attempts to do this, but
unless you
 fancy making your program a mod_perl handler that won't help you much.

Unfortunately I have to rely on the standard install of ActivePerl and
didn't want to make assumptions based on the extension type of the file.
Never mind, I will have to investigate further for future use. Thanks for
the help.

Barbie.





RE: MIME stuff - Am I missing something?

2001-05-22 Thread Robert Thompson

 
  I don't know if you are parsing mail or something else,
 
 Isolated file.
 
  If you are trying to figure it out magically based on just 
 the file format
 or filename or
  something (e.g. just pointing it at a raw jpeg) I didn't 
 think MIME::
 would help.

 Unfortunately I have to rely on the standard install of ActivePerl and
 didn't want to make assumptions based on the extension type 
 of the file.
 Never mind, I will have to investigate further for future 
 use. Thanks for
 the help.

Open up the file, read in the first few bytes and grab the magic number.
Most types of binary file have a marker of some kind to designate what they
are. Any half decent book on graphics programming should be able to tell you
what the magic numbers are for the main graphics types.

You can also use this technique to scan hdd's for for files where the file
extension has been changed to 'hide it'.

I had to look up the numbers a while ago for some software that performed
said scan. It's possible I've still got them somewhere... if I have, I'll
let you know (or point you in the right direction).

Rob


---
Any views expressed in this message are those of the individual sender,
except where the sender specifically states them to be the views of IBNet
Plc. 

This message contains confidential information and is intended only for the
individual named. If you are not the named addressee you should not
disseminate, distribute or copy this e-mail.  Please notify the sender
immediately by e-mail if you have received this e-mail by mistake and delete
this e-mail from your system. 

E-mail transmission cannot be guaranteed to be secure or error-free as
information could be intercepted, corrupted, lost, destroyed, arrive late or
incomplete, or contain viruses. The sender therefore does not accept
liability for any errors or omissions in the contents of this message which
arise as a result of e-mail transmission. If verification is required please
request a hard-copy version. 




Re: MIME stuff - Am I missing something?

2001-05-22 Thread Roger Burton West

On or about Tue, May 22, 2001 at 02:48:17PM +0100, Robert Thompson typed:

Open up the file, read in the first few bytes and grab the magic number.
Most types of binary file have a marker of some kind to designate what they
are. Any half decent book on graphics programming should be able to tell you
what the magic numbers are for the main graphics types.

man 1 file
man 5 magic
less /usr/share/misc/magic # on many systems

Roger



RE: MIME stuff - Am I missing something?

2001-05-22 Thread Robert Thompson

 From: Roger Burton West [mailto:[EMAIL PROTECTED]]
 
 man 1 file
 man 5 magic
 less /usr/share/misc/magic # on many systems
 

except anything written my MS of course...

Rob




---
Any views expressed in this message are those of the individual sender,
except where the sender specifically states them to be the views of IBNet
Plc. 

This message contains confidential information and is intended only for the
individual named. If you are not the named addressee you should not
disseminate, distribute or copy this e-mail.  Please notify the sender
immediately by e-mail if you have received this e-mail by mistake and delete
this e-mail from your system. 

E-mail transmission cannot be guaranteed to be secure or error-free as
information could be intercepted, corrupted, lost, destroyed, arrive late or
incomplete, or contain viruses. The sender therefore does not accept
liability for any errors or omissions in the contents of this message which
arise as a result of e-mail transmission. If verification is required please
request a hard-copy version. 




Re: MIME stuff - Am I missing something?

2001-05-22 Thread Barbie

From: Robert Thompson [EMAIL PROTECTED]
  From: Roger Burton West [mailto:[EMAIL PROTECTED]]
 
  man 1 file
  man 5 magic
  less /usr/share/misc/magic # on many systems
 

 except anything written my MS of course...

Which is precisely what this install of ActivePerl sits on. Luckily I have a
Linux box too :)

Barbie.





RE: MIME stuff - Am I missing something?

2001-05-22 Thread Robert Thompson

This site contains info about the raw file formats of numerous graphic
types, including sig/header block formats. All useful for anyone wanting to
play with graphics.

http://www.dcs.ed.ac.uk/~mxr/gfx/


Rob


---
Any views expressed in this message are those of the individual sender,
except where the sender specifically states them to be the views of IBNet
Plc. 

This message contains confidential information and is intended only for the
individual named. If you are not the named addressee you should not
disseminate, distribute or copy this e-mail.  Please notify the sender
immediately by e-mail if you have received this e-mail by mistake and delete
this e-mail from your system. 

E-mail transmission cannot be guaranteed to be secure or error-free as
information could be intercepted, corrupted, lost, destroyed, arrive late or
incomplete, or contain viruses. The sender therefore does not accept
liability for any errors or omissions in the contents of this message which
arise as a result of e-mail transmission. If verification is required please
request a hard-copy version. 




Re: MIME stuff - Am I missing something?

2001-05-22 Thread Dominic Mitchell

On Tue, May 22, 2001 at 03:06:39PM +0100, Barbie wrote:
 From: Robert Thompson [EMAIL PROTECTED]
   From: Roger Burton West [mailto:[EMAIL PROTECTED]]
  
   man 1 file
   man 5 magic
   less /usr/share/misc/magic # on many systems
  
 
  except anything written my MS of course...
 
 Which is precisely what this install of ActivePerl sits on. Luckily I have a
 Linux box too :)

It's worth grabbing the master copy of the magic database.  I've found
that some Linux ones (and even more so on Solaris) tend to be a bit
incomplete.

ftp://ftp.astron.com/pub/file/

That's the master location for the file(1) command that the BSDs use and
it appears to be quite complete.  Only it appears to be down right now.
Bugger.

You could try to grab them from the FreeBSD server, but there's been
problems with that recently and it doesn't have an unpacked copy of the
source available.  Double bugger.

Let's try NetBSD:

ftp://ftp.netbsd.org/pub/NetBSD-current/src/file/Magdir/

-Dom



Re: MIME stuff - Am I missing something?

2001-05-22 Thread Philip Newton

Robert Thompson wrote:
 This site contains info about the raw file formats of numerous graphic
 types, including sig/header block formats.

And there's always http://www.wotsit.org/ The Programmer's File Format
Collection.

Cheers,
Philip
-- 
Philip Newton [EMAIL PROTECTED]
All opinions are my own, not my employer's.
If you're not part of the solution, you're part of the precipitate.



Re: MIME stuff - Am I missing something?

2001-05-22 Thread Gareth Harper


From: Dominic Mitchell [EMAIL PROTECTED]
 On Tue, May 22, 2001 at 03:06:39PM +0100, Barbie wrote:
  From: Robert Thompson [EMAIL PROTECTED]
From: Roger Burton West [mailto:[EMAIL PROTECTED]]
   
man 1 file
man 5 magic
less /usr/share/misc/magic # on many systems
   
  
   except anything written my MS of course...
 
  Which is precisely what this install of ActivePerl sits on. Luckily I
have a
  Linux box too :)

 It's worth grabbing the master copy of the magic database.  I've found
 that some Linux ones (and even more so on Solaris) tend to be a bit
 incomplete.

 ftp://ftp.astron.com/pub/file/

Also sites like http://www.wotsit.org contain lots of info on file formats.

Thanks
Gareth