From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/60541 Path: news.gmane.org!not-for-mail From: Alan Shutko Newsgroups: gmane.emacs.gnus.general Subject: "Mailcap" parsing for Freedesktop .desktop files Date: Thu, 07 Jul 2005 16:49:40 -0500 Message-ID: <87acky9thn.fsf@vera.springies.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1120773372 21111 80.91.229.2 (7 Jul 2005 21:56:12 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 7 Jul 2005 21:56:12 +0000 (UTC) Original-X-From: ding-owner+M9069@lists.math.uh.edu Thu Jul 07 23:56:10 2005 Return-path: Original-Received: from malifon.math.uh.edu ([129.7.128.13]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DqeLM-0002r2-8G for ding-account@gmane.org; Thu, 07 Jul 2005 23:55:40 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu ident=lists) by malifon.math.uh.edu with smtp (Exim 3.20 #1) id 1DqeIa-0008RA-00; Thu, 07 Jul 2005 16:52:48 -0500 Original-Received: from util2.math.uh.edu ([129.7.128.23]) by malifon.math.uh.edu with esmtp (Exim 3.20 #1) id 1DqeIU-0008R5-00 for ding@lists.math.uh.edu; Thu, 07 Jul 2005 16:52:42 -0500 Original-Received: from quimby.gnus.org ([80.91.224.244]) by util2.math.uh.edu with esmtp (Exim 4.30) id 1DqeIT-0002W9-VZ for ding@lists.math.uh.edu; Thu, 07 Jul 2005 16:52:42 -0500 Original-Received: from 209-74-153-106.brick.net ([209.74.153.106] helo=simon.springies.com) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1DqeIQ-0000MI-00 for ; Thu, 07 Jul 2005 23:52:38 +0200 Original-Received: from localhost.localdomain (unknown [192.168.2.2]) by simon.springies.com (Postfix) with ESMTP id 339E743BC for ; Thu, 7 Jul 2005 16:52:37 -0500 (CDT) Original-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by localhost.localdomain (8.13.4/8.13.1) with ESMTP id j67LqPwH030034 for ; Thu, 7 Jul 2005 16:52:28 -0500 Original-Received: (from ats@localhost) by localhost.localdomain (8.13.4/8.13.4/Submit) id j67LqNZh030032; Thu, 7 Jul 2005 16:52:23 -0500 Original-To: ding@gnus.org User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux) X-Spam-Score: -4.9 (----) Precedence: bulk Original-Sender: ding-owner@lists.math.uh.edu Xref: news.gmane.org gmane.emacs.gnus.general:60541 X-Report-Spam: http://spam.gmane.org/gmane.emacs.gnus.general:60541 --=-=-= I noticed on my Fedora Core 4 system that the mailcap files were never updated with all the various Gnome applications. Instead, they put the information about what mime types they handle in .desktop applications in /usr/share/applications. Here's a first cut at parsing these files. Right now, I'm using (desktop-entry-add-entries "/usr/share/applications") to add mailcap-mime-data entries for everything in there. I think something like this should make its way into Gnus, so I'm interested in how people think I should integrate it. I also think that the Freedesktop .keys and .mime files should also be parsed for their mime-type info, but I haven't had a need for that yet. An alternative would be to create a mailcap from these files, but mailcap seems to be an endangered species. -- Alan Shutko - I am the rocks. Every human heart is human. Henry Wadsworth Longfellow --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=desktop-entry.el Content-Transfer-Encoding: quoted-printable ;;; desktop-entry.el --- Parse .desktop files for MIME information ;; Copyright (C) 2005 Alan Shutko ;; Author: Alan Shutko ;; Keywords: news, mail, multimedia ;; This file is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; This file is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;;=20 ;;; Code: (defun desktop-entry-parse-desktop (file) "Parse a .desktop file, returning a list of mailcap-mime-data entry." (save-excursion=20 (with-temp-buffer (let ((mime-types) (viewer)) (insert-file-contents file) (goto-char (point-min)) (while (re-search-forward "^\\(Exec\\|MimeType\\)=3D\\(.*\\)$" nil t) (let ((key (match-string 1)) (value (match-string 2))) (cond ((equal key "Exec") (setf viewer (desktop-entry-translate-parameters value))) ((equal key "MimeType") (setf mime-types (desktop-entry-parse-mimetypes value)))))) (mapc (lambda (type) (if (not (string=3D "" type)) (mailcap-add type viewer '(getenv "DISPLAY")))) mime-types))))) (defun desktop-entry-translate-parameters (exec-string) (replace-regexp-in-string "[%]." "%s" exec-string t)) (defun desktop-entry-parse-mimetypes (mime-string) "Parse a ;-delimited list of mime-types" (split-string mime-string ";")) (defun desktop-entry-add-entries (directory) "Add mailcap entries for all .desktop files in a directory" (mapc 'desktop-entry-parse-desktop (directory-files directory t "\\.desktop\\'"))) (provide 'desktop-entry) ;;; desktop-entry.el ends here --=-=-=--