From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/39447 Path: main.gmane.org!not-for-mail From: Lloyd Zusman Newsgroups: gmane.emacs.gnus.general Subject: Re: How to do something a bit complicated with inline decoding? Date: Fri, 19 Oct 2001 06:44:02 -0400 Organization: FreeBSD/Linux Hippopotamus Preserve Sender: owner-ding@hpc.uh.edu Message-ID: References: NNTP-Posting-Host: coloc-standby.netfonds.no Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: main.gmane.org 1035175150 27910 80.91.224.250 (21 Oct 2002 04:39:10 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 21 Oct 2002 04:39:10 +0000 (UTC) Return-Path: Original-Received: (qmail 1617 invoked from network); 19 Oct 2001 10:45:29 -0000 Original-Received: from malifon.math.uh.edu (mail@129.7.128.13) by mastaler.com with SMTP; 19 Oct 2001 10:45:29 -0000 Original-Received: from sina.hpc.uh.edu ([129.7.128.10] ident=lists) by malifon.math.uh.edu with esmtp (Exim 3.20 #1) id 15uX8q-0002yJ-00; Fri, 19 Oct 2001 05:44:40 -0500 Original-Received: by sina.hpc.uh.edu (TLB v0.09a (1.20 tibbs 1996/10/09 22:03:07)); Fri, 19 Oct 2001 05:44:18 -0500 (CDT) Original-Received: from sclp3.sclp.com (qmailr@sclp3.sclp.com [209.196.61.66]) by sina.hpc.uh.edu (8.9.3/8.9.3) with SMTP id FAA12863 for ; Fri, 19 Oct 2001 05:44:04 -0500 (CDT) Original-Received: (qmail 1601 invoked by alias); 19 Oct 2001 10:44:20 -0000 Original-Received: (qmail 1596 invoked from network); 19 Oct 2001 10:44:20 -0000 Original-Received: from home.acholado.net (216.27.138.216) by gnus.org with SMTP; 19 Oct 2001 10:44:20 -0000 Original-Received: from localhost (localhost [127.0.0.1]) (uid 501) by home.acholado.net with local; Fri, 19 Oct 2001 06:44:02 -0400 Original-To: ding@gnus.org X-Face: "!ga1s|?LNLE3MeeeEYs(%LIl9q[xV9!j4#xf4!**BFW_ihlOb;:Slb>)vy>CJM (Lloyd Zusman's message of "Thu, 18 Oct 2001 19:53:26 -0400") Original-Lines: 104 User-Agent: Gnus/5.090004 (Oort Gnus v0.04) XEmacs/21.4 (Academic Rigor) Precedence: list X-Majordomo: 1.94.jlt7 Xref: main.gmane.org gmane.emacs.gnus.general:39447 X-Report-Spam: http://spam.gmane.org/gmane.emacs.gnus.general:39447 Lloyd Zusman writes: > Kai.Grossjohann@CS.Uni-Dortmund.DE (Kai Großjohann) writes: > >> Lloyd Zusman writes: >> >>> [ ... ] >> >> Well, w3m.el does what you want by invoking w3m. I'm sure you can >> learn something from looking at its code; you'll just need to do like >> w3m.el, except that you invoke your own program. > > Yes, indeed. > > It turns out that w3m seems to require mule, and I don't use that. > This leaves out w3m as an alternative for me. But as you pointed out, > I can of course always look at the w3m.el code to get examples of what > I want to do in terms of decoding message parts. > > So is there really no Gnus function that decodes a message part and > replaces the part with the decoded version? (as opposed to decoding > the part and simply displaying it without modifying the message > buffer?) Well, not only can I not use w3m because of its dependency on mule, but upon further investigation, I now can see that I can't even use it to get example code for what I'm trying to do. That's because it doesn't do anything involving the decoding of message parts. I should have realized that initially, since the "mm-*" routines are all gnus-specific. So anyway, I finally just invented my own way of doing this, using as examples the code within "gnus-art.el" and "mm-decode.el". Look at the `my-html-inline-part' function, below. I bind that to a key sequence in summary mode, and I'm done. Thanks to all. ---8<---8<---8<---8<---8<---8<-- cut here --8<---8<---8<---8<---8<---8<--- (defvar my-html-decode-command "/usr/local/bin/w3m -T text/html -dump" "*External command for decoding HTML into text.") (defun my-mime-html-inline-part (&optional handle arg) "Insert the MIME part under point into the current buffer, after having piped it through a command." (interactive (list nil current-prefix-arg)) (save-excursion (set-buffer gnus-article-buffer) (let* ((handle (or handle (get-text-property (point) 'gnus-data))) contents charset (b (point)) buffer-read-only) (when handle (if (and (not arg) (mm-handle-undisplayer handle)) (mm-remove-part handle) (setq contents (mm-get-part handle)) (cond ((not arg) (setq charset (or (mail-content-type-get (mm-handle-type handle) 'charset) gnus-newsgroup-charset))) ((numberp arg) (if (mm-handle-undisplayer handle) (mm-remove-part handle)) (setq charset (or (cdr (assq arg gnus-summary-show-article-charset-alist)) (mm-read-coding-system "Charset: "))))) (forward-line 2) (mm-with-unibyte-buffer (mm-insert-part handle) (let ((coding-system-for-write 'binary) (temp-buffer (generate-new-buffer "*w3m*"))) (save-excursion (set-buffer temp-buffer) (insert contents) (shell-command-on-region (point-min) (point-max) my-html-decode-command temp-buffer t) (widen temp-buffer) (setq contents (buffer-string temp-buffer)) (kill-buffer temp-buffer) ))) (mm-insert-inline handle (if (and charset (setq charset (mm-charset-to-coding-system charset)) (not (eq charset 'ascii))) (mm-decode-coding-string contents charset) contents)) (goto-char b)))))) (defun my-html-inline-part (n) "Inline MIME part N, which is the numerical prefix." (interactive "p") (gnus-article-part-wrapper n 'my-mime-html-inline-part)) -- Lloyd Zusman ljz@asfast.com