Finding MIME Types?

For everything that's not in any way related to PureBasic. General chat etc...
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Finding MIME Types?

Post 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?
--Kale

Image
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Re: Finding MIME Types?

Post 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! :wink:
Good programmers don't comment their code. It was hard to write, should be hard to read.
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post 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?
--Kale

Image
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post 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?
Good programmers don't comment their code. It was hard to write, should be hard to read.
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post 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).
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post 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. ;)
--Kale

Image
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post 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!

;)
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post 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)
--Kale

Image
Post Reply