michaelrsweet / lprint

A Label Printer Application
https://www.msweet.org/lprint
Apache License 2.0
243 stars 31 forks source link

[discussion] observation after printing .zpl without explicitly setting the MIME type #127

Closed zougloub closed 6 months ago

zougloub commented 9 months ago

I recently discovered the existence of lprint, I had been using my label printer using raw .zpl and Linux usblp. I find it pretty cool that it's possible to expose the network printing services (eg. so as to print labels quickly from a smart phone), and as well be able to ingest and forward native printer data when needed.

I noticed that unless specifying the MIME type of a ZPL job (-o document-format=application/vnd.zebra-zpl), the job failed as the MIME type was resolved to octet-stream. Now I don't mind at all specifying the option, but it got me wondering what is used to perform MIME type guessing, and perhaps supply a patch so I don't need to pass the extra arguments.

After briefly scanning the source code of lprint/pappl/libcups/cups, I guess that the MIME type guessing of a document is performed using CUPS (using a mimes.type rules file in $(DATADIR)/mime/ ; https://www.cups.org/doc/man-mime.types.html). I didn't know CUPS had its own MIME type guessing code, I was wondering @michaelrsweet if you knew why CUPS wasn't relying on a dependency (such as libmagic, BSD-2) to do it.

michaelrsweet commented 9 months ago

@zougloub WRT the CUPS MIME typing code, it was necessary because the old magic/"file" utility code was never particularly good across the platforms the CUPS supported and it was relatively hard to extend (i.e. classic "file" used a single configuration file that was updated/overwritten by OS updates). Also, the reported format isn't a MIME media type.

LPrint provides a MIME typing callback for identifying ZPL files. If you want to print through CUPS then you also need to provide a "zpl.types" file that does the same checking since CUPS will otherwise try to convert the file for printing (and likely would treat ZPL as plain text...)