Page 1 of 1
Finding MIME Types?
Posted: Wed Jun 11, 2003 10:54 pm
by Kale
Anybody know whats the best way to find a MIME type for a given file with regard to email? I know the MIME type for a *.jpg file is 'image/jpeg' but how would any email app find these out? Is there a WinAPI command to access whats locally stored?
Re: Finding MIME Types?
Posted: Wed Jun 11, 2003 11:15 pm
by traumatic
Hmm... I don't understand the 'locally stored' bit of your question.
MIME-Types aren't a matter of APIs or OS-Installations.
They're defined in RFCs. RFC 2046 might be the right one for you.
Just have a search with your favourite searchengine using "mime + types" and I bet you'll find what you're looking for.
And don't trust in things people from Redmond might tell you!

Posted: Wed Jun 11, 2003 11:39 pm
by Kale
I understand about the RFC docs, i've already been through a few 8O
I just wondered if there was something like a locally stored 'extension map file' within windows. something like this:
http://archive.ncsa.uiuc.edu/SDG/Softwa ... n-map.html i could parse to match extensions with MIME types. Where does Outlook Express, etc... find these type out from?
Posted: Wed Jun 11, 2003 11:59 pm
by traumatic
Kale wrote:Where does Outlook Express, etc... find these type out from?
I (only) guess it's defined. Did you try some extraordinary types?
Does Outlook really identify them or is there a "application/octet-stream" in the header?
Posted: Thu Jun 12, 2003 12:24 am
by tinman
If you go to the View menu in a Windows Explorer window, then Options, then file types and click on a type, you get a content type. So I think it would be stored somewhere, rather than every application having it's own table of things.
Running redegit then searching for "image/png" gives me a list of mime types stored in the registry.
HKEY_CLASSES_ROOT\MIME\Database\Content Type\image/png
In there it also lists the extension. I'm guessing there is also a reverse method (extension to MIME type).
Posted: Thu Jun 12, 2003 2:50 pm
by Kale
Yeah, thanks guys its all in the 'HKEY_CLASSES_ROOT' folder, look for the extension in there then open the node and look for 'content type'. Some don't have registered mime types so i guess i could use a generic one for them.

Posted: Thu Jun 12, 2003 4:33 pm
by tinman
Kale wrote:could use a generic one for them. ;)
As traumatic mentioned "application/octet-stream" is a general binary 8-bits-per-symbol MIME type. Which is always better than defaulting to "text/plain" and having your browser trying to save binary files either with an extension (IE) or corrupting the data (NS4.7).
Gagh!
;)
Posted: Thu Jun 12, 2003 4:47 pm
by Kale
This seems to work
Code: Select all
Procedure.s GetMIMEType(Extension.s)
Extension = "." + Extension
hKey.l = 0
KeyValue.s = Space(255)
datasize.l = 255
If RegOpenKeyEx_(#HKEY_CLASSES_ROOT, Extension, 0, #KEY_READ, @hKey)
KeyValue = "application/octet-stream"
Else
If RegQueryValueEx_(hKey, "Content Type", 0, 0, @KeyValue, @datasize)
KeyValue = "application/octet-stream"
Else
KeyValue = Left(KeyValue, datasize-1)
EndIf
RegCloseKey_(hKey)
EndIf
ProcedureReturn KeyValue
EndProcedure
key.s=GetMIMEType("gif")
MessageRequester("ReadLocalKey",key,0)