Gnus development mailing list
 help / color / mirror / Atom feed
From: Lloyd Zusman <ljz@asfast.com>
Subject: Re: How to do something a bit complicated with inline decoding?
Date: Fri, 19 Oct 2001 06:44:02 -0400	[thread overview]
Message-ID: <m2sncfewp9.fsf@asfast.com> (raw)
In-Reply-To: <m2669cijyh.fsf@asfast.com> (Lloyd Zusman's message of "Thu, 18 Oct 2001 19:53:26 -0400")

Lloyd Zusman <ljz@asfast.com> writes:

> Kai.Grossjohann@CS.Uni-Dortmund.DE (Kai Großjohann) writes:
>
>> Lloyd Zusman <ljz@asfast.com> 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



  reply	other threads:[~2001-10-19 10:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-18  1:38 Lloyd Zusman
2001-10-18  7:17 ` Kai Großjohann
2001-10-18 11:00   ` Lloyd Zusman
2001-10-18 12:30     ` Colin Marquardt
2001-10-18 15:54     ` Kai Großjohann
2001-10-18 23:53       ` Lloyd Zusman
2001-10-19 10:44         ` Lloyd Zusman [this message]
2001-10-19 13:07           ` Kai Großjohann
2001-10-19 23:51             ` Lloyd Zusman
2001-10-20 10:34             ` Raymond Scholz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2sncfewp9.fsf@asfast.com \
    --to=ljz@asfast.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).