Jump to content

Mime type for Outlook msg file


NotionCommotion

Recommended Posts

Could someone please execute the following script.  The test.msg file needs to be an MS Outlook file.  To create one, open an email using Outlook and save as a msg file.  I'm not sure if OpenOffice will work as well.

<?php
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$filetype=finfo_file($finfo, 'test.msg');
echo($filetype);
?>

What output did you get?  I get application/CDFV2-corrupt.  Is that correct?  Shouldn't it be application/vnd.ms-outlook?  I am running Centos 6.  What operating system are you using?

 

Thank you

Link to comment
Share on other sites

It may very well appear to be a "application/CDFV2-corrupt" file too, whatever that is.

 

If it's not giving you the answer you want then you can do the MIME magic yourself pretty easily.

$h = fopen('test.msg', 'rb');
$magic = "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1\x00";
$bytes = fread($h, strlen($magic));
fclose($h);

if ($bytes == $magic) {
    $filetype = 'application/CDFV2-corrupt';
} else {
    // use finfo
}
Link to comment
Share on other sites

Thanks Requinix,

 

Don't know if I understand the purpose.  When using your script on the file in question, $bytes==$magic, so I shouldn't use finfo?  But finfo provides the same results (i.e. application/CDFV2-corrupt).  My question is what is a application/CDFV2-corrupt mime in the first place?  It shouldn't be as far as I know.

 

On a side note, what does the following script do?

$bytes = fread($h, strlen("\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1\x00"));
Link to comment
Share on other sites

Silly typo. That line should be

$filetype = 'application/vnd.ms-outlook';

On a side note, what does the following script do?

$bytes = fread($h, strlen("\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1\x00"));

 

That's the basic premise of MIME type detection: read a few bytes from the beginning of the file and look them up in a database. With that code, the "database" is simply "do the first 9 bytes match this known string", and if that's true then the detection result is application/vnd.ms-outlook. finfo is using a more comprehensive database, naturally. It apparently has those same 9 bytes (maybe fewer) except it maps those to be the application/CDFV2-corrupt type.

 

So the idea is to check your own "database" first, since you know that to be accurate, and if there's no match then use the general purpose, 99%-accurate finfo.

Link to comment
Share on other sites

Ah, that makes sense now.  So, it appears that finfo is not always accurate.  Odd that an Outlook msg file would be in that list.  How did you come up with "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1\x00" as the magic string?  Guess if there were several file types that finfo doesn't get right (this is the first I found, however), I could check each of them before using finfo easily enough.

 

Also, did you have a chance to use finfo on a Outlook msg file?  Wondering if is just my distribution/library.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.