[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fake PDF


On Tuesday, February 24th, 2026 at 18:59, Lee <t.lee.davidson@xxxxxxxxx> wrote:
> 
> That method queries the system mime type file at "/usr/share/mime/globs2" basically using it as a look-up table. On my system,
> line 139 in that file is "50:application/pdf:*.pdf". So according to that file, all files with a ".pdf" extension are of type
> "application/pdf". It is really stupid as it relies on the file extension as opposed to the file contents.

Exactly, I'm glad you find it stupid as well. One of the first things I loved about coming to Linux was that file extensions didn't matter.
The DesktopMime class is not reliable to return the TRUE MIME type of a file, but the FAKE one (that is true most of the time bit not always).
The 'xdg-mime query file' equals the DesktopMine.FromFile output but on the command line level. Hence the screenshot to show the difference.

> Simplified, DesktopMime.FromFile() looks up the file extension in "/usr/share/mime/globs2", finds that it is of type
> "application/pdf", and returns that text. BTW, the Stat object created by the Stat() function will also falsely return
> "application/pdf" for that fake PDF file.
> 
> The `file` command, on the other hand, will actually look at the header content of the file to determine its actual type.

Yes, that is why I'm going back to my old function based on a simple EXEC of the file command, giving me the TRUE MIME type as demonstrated in my previous post screenshot.

Maybe the core Gambas should have a function to return the TRUE MIME type of a file instead of relying on the gb.desktop component
I wonder what Benoit has to say about this matter on 'TRUE' and 'FAKE' MIME type and a proper MIME type function?

gbWilly

GambOS
Gambas3 for Debian/Ubuntu

...there is always a Catch if things go wrong!


Follow-Ups:
Re: Fake PDFBenoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx>
References:
Fake PDFGianluigi <gradobag@xxxxxxxxxxx>
Re: Fake PDFLee <t.lee.davidson@xxxxxxxxx>
Re: Fake PDFGianluigi <gradobag@xxxxxxxxxxx>
Re: Fake PDFLee <t.lee.davidson@xxxxxxxxx>