mimetype for files with a wrong extension?

Boudewijn Rempt boud at valdyas.org
Mon Apr 9 11:41:52 BST 2012

I'm trying to figure out why kmimetype returns image/jpeg for a png file that was renamed to have a jpg extension (which apparently happens a lot for real users).

In the dox for KMimeType::findByUrl it's said that if only the filename is used to determine the mimetype, accuracy is set to 80 -- but it's not, it's set to 100.

diff --git a/kdecore/services/kmimetype.cpp b/kdecore/services/kmimetype.cpp
index 955bf62..74f371d 100644
--- a/kdecore/services/kmimetype.cpp
+++ b/kdecore/services/kmimetype.cpp
@@ -211,6 +211,7 @@ KMimeType::Ptr KMimeType::findByUrlHelper( const KUrl& _url, mode_t mode,
                     kWarning() << "Glob file refers to" << selectedMime << "but this mimetype does not exist!";
                 } else {
+                    accuracy = 80;
                     return mime;
lines 1-12/12 (END)

When doing this I can at least see that only the filename was used. But I'm wondering why checking the magic numbers for jpg, png and so on from the content isn't given a higher accuracy, since if do a findByContent, I get an accuracy of 50 for my file, but the magic numbers for image files are pretty much completely reliable.

Boudewijn Rempt
http://www.valdyas.org, http://www.krita.org, http://www.boudewijnrempt.nl

More information about the kde-core-devel mailing list