From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/61729 Path: news.gmane.org!not-for-mail From: Hynek Schlawack Newsgroups: gmane.emacs.gnus.general Subject: Re: Viewing HTML-mails with external browsers - proposed code Date: Sun, 22 Jan 2006 13:40:26 +0100 Message-ID: <878xt8wi4l@ularx.de> References: <874q56xeh4@ularx.de> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1137934107 19889 80.91.229.2 (22 Jan 2006 12:48:27 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 22 Jan 2006 12:48:27 +0000 (UTC) Original-X-From: ding-owner+m10259@lists.math.uh.edu Sun Jan 22 13:48:25 2006 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from malifon.math.uh.edu ([129.7.128.13]) by ciao.gmane.org with esmtp (Exim 4.43) id 1F0edr-0005E8-AP for ding-account@gmane.org; Sun, 22 Jan 2006 13:48:23 +0100 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 1F0edl-0008QY-00; Sun, 22 Jan 2006 06:48:17 -0600 Original-Received: from nas01.math.uh.edu ([129.7.128.39]) by malifon.math.uh.edu with esmtp (Exim 3.20 #1) id 1F0eW9-0008QT-00 for ding@lists.math.uh.edu; Sun, 22 Jan 2006 06:40:25 -0600 Original-Received: from quimby.gnus.org ([80.91.224.244]) by nas01.math.uh.edu with esmtp (Exim 4.52) id 1F0eW6-0002Jy-Mr for ding@lists.math.uh.edu; Sun, 22 Jan 2006 06:40:25 -0600 Original-Received: from relay1.mail.vrmd.de ([81.28.232.18]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1F0eW1-0003lC-00 for ; Sun, 22 Jan 2006 13:40:17 +0100 Original-Received: from [84.189.124.39] (helo=squirrel.hn.org) by relay1.mail.vrmd.de with esmtpa (Exim 4.60) (envelope-from ) id 1F0eW0-0005o3-Te for ding@gnus.org; Sun, 22 Jan 2006 13:40:17 +0100 Original-To: ding@gnus.org In-Reply-To: (Reiner Steib's message of "Thu, 19 Jan 2006 20:35:13 +0100") User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux) X-Relay-User: mailout@ularx.de X-Spam-Score: -2.6 (--) Precedence: bulk Original-Sender: ding-owner@lists.math.uh.edu Xref: news.gmane.org gmane.emacs.gnus.general:61729 Archived-At: --=-=-= * Reiner Steib wrote: > JFTR: It failed with "Mail doesn't contain a HTML-part!" on the > following forwarded message: > > | <* mixed> Fwd: RE: Termine > | <1 text> > | <2 rfc822> > | <2.* alternative> RE: Termine > | <2.1 text> > | <2.2 html> Hm, would you mind to forward some look-a-like to me? > I think (when your assignment is completed), It's up to our patience right now. ;) > we should add both functions to `gnus-art.el' and add a key binding > (suggestions?) Well, _I_ use "v", but I guess I won't be able to push that. ;) > As requested, some comments/suggestions on the code: Thanks! >> (defun hs-show-html-list (LIST) > Rename to, say `gnus-article-browse-html-parts'. Other suggestions? > Instead of LIST, you should write list (in lowercase). *done* >> "View all HTML-parts from 'LIST'. > "View all \"text/html\" parts from LIST. *done* >> (let ((showed)) > Maybe "done" instead of "showed"? I'm not sure whether "done" exactly reflects the purpose of "showed". >> ;; Find and show the html-parts. >> (dolist (elt LIST) >> ;; If HTML, show it >> (cond ((and (listp elt) > Maybe rename "elt" to "handle"? *done* I've been lacking imagination in that point. [ Factoring out cond ] Yeah you're right. The routines grew a bit...evolutionary. >> (bufferp (car elt)) > Isn't (car elt) the same as (mm-handle-buffer elt)? Yes...but we don't know exactly whether it's a buffer (look at the second condition), so I guess car is more appropriate here. >> (string-match "text/html" (car (mm-handle-type elt)))) >> (let ((tmp (format "%s-%s.html" > Maybe "file" instead of "tmp"? I went for "tmp-file" if it's okay for you. >> (make-temp-name "/tmp/gnus-html-") >> (user-login-name)))) > > (mm-make-temp-file (expand-file-name "mm" mm-tmp-directory) nil ".html") > Maybe even (convert-standard-filename (mm-make-temp-file ...)) like > in `browse-url-of-buffer' is required? Uhm, so what's your final suggestion here? :) >> (mm-save-part-to-file elt tmp) >> (browse-url tmp) > It would be nice to remove the tmp file after proceeding to the next > article or leaving the summary buffer (maybe similar to > `mm-remove-part'). But it might depend on the browser and the user if > this is desired. Or it could be removed here: > (when (gnus-y-or-n-p "Remove temp file? ") (delete-file tmp)) Yes it would be nice and the only way would be this asking as we can't delete it, before it has been showed... >> (setq showed t))) >> ;; If multipart, recurse >> ((and (listp elt) >> (stringp (car elt)) >> (string-match "multipart/" (substring (car elt) 0 10)) > (string-match "^multipart/" (car elt)) *done* >> (setq showed (or showed (hs-show-html-list elt))))))) >> showed)) >> (defun hs-show-html-mail () > (defun gnus-article-browse-html-article *done* > Other suggestions? I'm fine with it. >> "View HTML-parts of the current Gnus-Article in a graphical browser." > > "View \"text/html\" parts of the current article with a WWW browser." > See `C-h f browse-url RET'. Ehm, for what exactly? >> (message "Mail doesn't contain a HTML-part!")) > Either (gnus-message 3 ...) or even (gnus-error ...) should be used > here, I think. Ok, I wasn't sure about what to use. -hs --=-=-= Content-Type: application/emacs-lisp Content-Disposition: inline; filename=hs-show-html-mail.el Content-Transfer-Encoding: quoted-printable ;;; hs-show-html-mail.el --- View HTML-parts in a graphical browser. ;; Copyright (C) 2005, 2006 Hynek Schlawack ;; Author: Hynek Schlawack ;; Version: $Id: hs-show-html-mail.el 13 2006-01-22 12:36:36Z hynek $ ;; Keywords: mail news ;; This file is NOT part of GNU Emacs. ;; 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: ;; Scans the actual article in Gnus for HTML-parts and shows them using ;; browse-url. ;;; Code: (defun gnus-article-browse-html-parts (list) "View all \"text/html\" parts from LIST. Recurse into multiparts." (let ((showed)) ;; Find and show the html-parts. (dolist (handle list) ;; If HTML, show it (when (listp handle) (cond ((and (bufferp (car handle)) (string-match "text/html" (car (mm-handle-type handle)))) (let ((tmp-file (format "%s-%s.html" (make-temp-name "/tmp/gnus-html-") (user-login-name)))) (mm-save-part-to-file handle tmp-file) (browse-url tmp-file) (setq showed t))) ;; If multipart, recurse ((and (stringp (car handle)) (string-match "^multipart/" (substring (car handle) 0 10)) (setq showed (or showed (hs-show-html-list handle)))))))) showed)) (defun gnus-article-browse-html-article () "View \"text/html\" parts of the current article with a WWW browser." (interactive) =20=20 (save-window-excursion ;; Open raw article and select the buffer (gnus-summary-show-article t) (gnus-summary-select-article-buffer) (let ((parts (mm-dissect-buffer t t))) ;; If singlepart, enforce a list. (when (and (bufferp (car parts)) (stringp (car (mm-handle-type parts)))) (setq parts (list parts))) ;; Process the list (unless (gnus-article-browse-html-parts parts) (gnus-error 3 "Mail doesn't contain a \"text/html\" part!")) (gnus-summary-show-article)))) =20=20=20=20 (provide 'hs-show-html-mail) ;;; hs-show-html-mail.el ends here --=-=-=--