From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/61716 Path: news.gmane.org!not-for-mail From: Reiner Steib Newsgroups: gmane.emacs.gnus.general Subject: Re: Viewing HTML-mails with external browsers - proposed code Date: Thu, 19 Jan 2006 20:35:13 +0100 Organization: Dept. of Theoretical Physics, University of Ulm Message-ID: References: <874q56xeh4@ularx.de> Reply-To: Reiner Steib NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1137699632 23686 80.91.229.2 (19 Jan 2006 19:40:32 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 19 Jan 2006 19:40:32 +0000 (UTC) Original-X-From: ding-owner+m10246@lists.math.uh.edu Thu Jan 19 20:40:24 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 1EzfcU-0005wf-ER for ding-account@gmane.org; Thu, 19 Jan 2006 20:38:56 +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 1EzfcN-0002gZ-00; Thu, 19 Jan 2006 13:38:47 -0600 Original-Received: from nas02.math.uh.edu ([129.7.128.40]) by malifon.math.uh.edu with esmtp (Exim 3.20 #1) id 1EzfZf-0002gU-00 for ding@lists.math.uh.edu; Thu, 19 Jan 2006 13:35:59 -0600 Original-Received: from quimby.gnus.org ([80.91.224.244]) by nas02.math.uh.edu with esmtp (Exim 4.52) id 1EzfZX-0003nz-Au for ding@lists.math.uh.edu; Thu, 19 Jan 2006 13:35:58 -0600 Original-Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1EzfZV-0002vD-00 for ; Thu, 19 Jan 2006 20:35:49 +0100 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1EzfZJ-0005Cq-Rk for ding@gnus.org; Thu, 19 Jan 2006 20:35:37 +0100 Original-Received: from bridgekeeper.physik.uni-ulm.de ([134.60.10.123]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 19 Jan 2006 20:35:37 +0100 Original-Received: from Reiner.Steib by bridgekeeper.physik.uni-ulm.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 19 Jan 2006 20:35:37 +0100 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: ding@gnus.org Original-To: ding@gnus.org Original-Lines: 147 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: bridgekeeper.physik.uni-ulm.de X-Face: P05mdcZT&lL[-s2=mw~RsllZ0zZAb?vdE}.s On Sun, Dec 18 2005, Hynek Schlawack wrote: > Anyway: As I started to get more and more Mails (mostly newsletters etc) > that make sense only if readen with an graphical browser like Firefox, I > was wondering whether there's some easy way to display them in Gnus? As > I haven't found anything, I wrote a little elisp to solve this. It's > kindof my first lisp ever, so please be tolerant. ;) Nevertheless it > actually works; even with recursevly hidden HTML-parts. 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> > I'm sending the code attached, maybe everyone has something like that in > his .gnus, then please nevermind. I'd be happy about some feedback or > even inclusion though. I think (when your assignment is completed), we should add both functions to `gnus-art.el' and add a key binding (suggestions?) and menu entries in `gnus-sum.el'. As requested, some comments/suggestions on the code: > (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). > "View all HTML-parts from 'LIST'. "View all \"text/html\" parts from LIST. (Only here in the doc string it must be uppercase.) > Recurse into multiparts." > > (let ((showed)) Maybe "done" instead of "showed"? > ;; Find and show the html-parts. > (dolist (elt LIST) > ;; If HTML, show it > (cond ((and (listp elt) Maybe rename "elt" to "handle"? Basically you have: (cond ((and a b c) (do-something)) ((and a s d (do-other-things)))) Maybe it would be more clear to write it as follows. But it could be just a matter of taste. (when a (cond ((and b c) (do-something)) ((and s d) (do-other-things)) > (bufferp (car elt)) Isn't (car elt) the same as (mm-handle-buffer elt)? > (string-match "text/html" (car (mm-handle-type elt)))) > (let ((tmp (format "%s-%s.html" Maybe "file" instead of "tmp"? > (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? > (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)) > (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)) > (setq showed (or showed (hs-show-html-list elt))))))) > showed)) > > (defun hs-show-html-mail () (defun gnus-article-browse-html-article Other suggestions? > "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'. > (interactive) > > (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 (hs-show-html-list parts) > (message "Mail doesn't contain a HTML-part!")) Either (gnus-message 3 ...) or even (gnus-error ...) should be used here, I think. > (gnus-summary-show-article)))) Bye, Reiner. -- ,,, (o o) ---ooO-(_)-Ooo--- | PGP key available | http://rsteib.home.pages.de/