Gnus development mailing list
 help / color / mirror / Atom feed
* How to do something a bit complicated with inline decoding?
@ 2001-10-18  1:38 Lloyd Zusman
  2001-10-18  7:17 ` Kai Großjohann
  0 siblings, 1 reply; 10+ messages in thread
From: Lloyd Zusman @ 2001-10-18  1:38 UTC (permalink / raw)


I'd like to do something a bit complicated with inline decoding of
message parts, and I'm wondering if Oort might already have some or
all of my desired functionality:

I sometimes receive messages, each of whose parts are mime encoded,
with the first part being the text/html version of the person's
message (yes, this comes from some Micro$oft mail client).

I have the following in my .gnus.el file to force text/html to never
be automatically displayed or encoded:

  (setq mm-discouraged-alternatives
        '("text/html"
          "text/richtext"))
  (setq mm-inline-override-types mm-discouraged-alternatives)
  (setq mm-automatic-display (remove "text/html" mm-automatic-display))

With this setup, I can type `1 b' in message buffers like I described
above in order to get a prompt asking me where I'd like to save the
html.  In most cases, this is exactly what I want.

However, in one particular groups, I want to be able to hit a key
sequence that will pipe this message part through a command which will
do a non-graphic formatting of the message.

I know how to do this:  I enter the following command ...

  1 K | w3m -T text/html

The "w3m" command does what I want, and the screen now shows the
non-graphic-formatted version of the html part.

However, if immediately thereafter, I type 'r' to reply to the
message, the formatted text goes away, and the resulting buffer is
empty.

What I'd like to be able to do is this:

Create a special way to "treat" an article that does the following
when I invoke the key sequence bound to this special treatment
command:

1. For all parts for which there is a known decoding mechansim
   EXCEPT text/html, just invoke that decoding mechanism.

2. For all text/html parts numbered <n> do this ...

     <n> K | w3m -T text/html

   ... and make sure that the resultant text appears in the buffer.

After this treatment, if I reply to the message, the text resulting
from the non-graphic-formatted html will appear quoted in the buffer,
so I can write a reply to it.

I could use the "hammer and tongs" approach and pound out the elisp
code I need, but before I do, does anyone know of any existing Oort
functionality that might be able to help me?

Thanks in advance.

-- 
 Lloyd Zusman
 ljz@asfast.com



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to do something a bit complicated with inline decoding?
  2001-10-18  1:38 How to do something a bit complicated with inline decoding? Lloyd Zusman
@ 2001-10-18  7:17 ` Kai Großjohann
  2001-10-18 11:00   ` Lloyd Zusman
  0 siblings, 1 reply; 10+ messages in thread
From: Kai Großjohann @ 2001-10-18  7:17 UTC (permalink / raw)
  Cc: ding

Lloyd Zusman <ljz@asfast.com> writes:

> I know how to do this:  I enter the following command ...
> 
>   1 K | w3m -T text/html
> 
> The "w3m" command does what I want, and the screen now shows the
> non-graphic-formatted version of the html part.

There is w3m.el and I think it's got hooks to allow you to use it as
an HTML formatter in Gnus, instead of W3.  Maybe that's good enough?

kai
-- 
GNU/Linux provides a nice `poweroff' command, but where is `poweron'?



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to do something a bit complicated with inline decoding?
  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
  0 siblings, 2 replies; 10+ messages in thread
From: Lloyd Zusman @ 2001-10-18 11:00 UTC (permalink / raw)


Kai.Grossjohann@CS.Uni-Dortmund.DE (Kai Großjohann) writes:

> Lloyd Zusman <ljz@asfast.com> writes:
>
>> I know how to do this:  I enter the following command ...
>> 
>>   1 K | w3m -T text/html
>> 
>> The "w3m" command does what I want, and the screen now shows the
>> non-graphic-formatted version of the html part.
>
> There is w3m.el and I think it's got hooks to allow you to use it as
> an HTML formatter in Gnus, instead of W3.  Maybe that's good enough?

I'll check w3m.el.  Where is the official "home" of that module, by
the way?

The problem I'm trying to solve, however, has more to do with mime
part encoding, not with non-graphic html reformatting itself.  What
I'm trying to do is to decode a mime part and then have the decoded
text appear in the buffer a way that replaces the original mime part,
so I can then do a reply or a followup and have the quoted text in the
message buffer be the decoded text from the mime part.  Right now,
after decoding, a subsequent reply or followup doesn't show the
decoded text at all.

And I'm wondering how to do that in the general case, not just for
non-graphic html decoding.

Any ideas?

Thanks again in advance.


> kai
> -- 
> GNU/Linux provides a nice `poweroff' command, but where is `poweron'?

-- 
 Lloyd Zusman
 ljz@asfast.com



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to do something a bit complicated with inline decoding?
  2001-10-18 11:00   ` Lloyd Zusman
@ 2001-10-18 12:30     ` Colin Marquardt
  2001-10-18 15:54     ` Kai Großjohann
  1 sibling, 0 replies; 10+ messages in thread
From: Colin Marquardt @ 2001-10-18 12:30 UTC (permalink / raw)


Lloyd Zusman <ljz@asfast.com> writes:

> I'll check w3m.el.  Where is the official "home" of that module, by
> the way?

http://cvs.namazu.org/emacs-w3m/
http://emacs-w3m.namazu.org/ (Japanese)

HTH,
  Colin



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to do something a bit complicated with inline decoding?
  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
  1 sibling, 1 reply; 10+ messages in thread
From: Kai Großjohann @ 2001-10-18 15:54 UTC (permalink / raw)
  Cc: ding

Lloyd Zusman <ljz@asfast.com> writes:

> The problem I'm trying to solve, however, has more to do with mime
> part encoding, not with non-graphic html reformatting itself.  What
> I'm trying to do is to decode a mime part and then have the decoded
> text appear in the buffer a way that replaces the original mime part,
> so I can then do a reply or a followup and have the quoted text in the
> message buffer be the decoded text from the mime part.

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.

kai
-- 
GNU/Linux provides a nice `poweroff' command, but where is `poweron'?



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to do something a bit complicated with inline decoding?
  2001-10-18 15:54     ` Kai Großjohann
@ 2001-10-18 23:53       ` Lloyd Zusman
  2001-10-19 10:44         ` Lloyd Zusman
  0 siblings, 1 reply; 10+ messages in thread
From: Lloyd Zusman @ 2001-10-18 23:53 UTC (permalink / raw)


Kai.Grossjohann@CS.Uni-Dortmund.DE (Kai Großjohann) writes:

> Lloyd Zusman <ljz@asfast.com> writes:
>
>> The problem I'm trying to solve, however, has more to do with mime
>> part encoding, not with non-graphic html reformatting itself.  What
>> I'm trying to do is to decode a mime part and then have the decoded
>> text appear in the buffer a way that replaces the original mime part,
>> so I can then do a reply or a followup and have the quoted text in the
>> message buffer be the decoded text from the mime part.
>
> 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?)



-- 
 Lloyd Zusman
 ljz@asfast.com



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to do something a bit complicated with inline decoding?
  2001-10-18 23:53       ` Lloyd Zusman
@ 2001-10-19 10:44         ` Lloyd Zusman
  2001-10-19 13:07           ` Kai Großjohann
  0 siblings, 1 reply; 10+ messages in thread
From: Lloyd Zusman @ 2001-10-19 10:44 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to do something a bit complicated with inline decoding?
  2001-10-19 10:44         ` Lloyd Zusman
@ 2001-10-19 13:07           ` Kai Großjohann
  2001-10-19 23:51             ` Lloyd Zusman
  2001-10-20 10:34             ` Raymond Scholz
  0 siblings, 2 replies; 10+ messages in thread
From: Kai Großjohann @ 2001-10-19 13:07 UTC (permalink / raw)
  Cc: ding

Lloyd Zusman <ljz@asfast.com> writes:

> 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.

I thought there was integration of w3m.el with Gnus.  But now I see
that there is only integration with SEMI.  Sorry.

But I know that I've seen mention of using w3m.el with Gnus.  But where?

kai
-- 
GNU/Linux provides a nice `poweroff' command, but where is `poweron'?



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to do something a bit complicated with inline decoding?
  2001-10-19 13:07           ` Kai Großjohann
@ 2001-10-19 23:51             ` Lloyd Zusman
  2001-10-20 10:34             ` Raymond Scholz
  1 sibling, 0 replies; 10+ messages in thread
From: Lloyd Zusman @ 2001-10-19 23:51 UTC (permalink / raw)


Kai.Grossjohann@CS.Uni-Dortmund.DE (Kai Großjohann) writes:

> Lloyd Zusman <ljz@asfast.com> writes:
>
>> 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.
>
> I thought there was integration of w3m.el with Gnus.  But now I see
> that there is only integration with SEMI.  Sorry.

No problem.  I just ended up doing what I usually do in these
situations: invent the wheel (I just don't want to RE-invent the
wheel, which is why I post queries like this before I start in on
coding).


> [ ... ]
>
> kai
> -- 

-- 
 Lloyd Zusman
 ljz@asfast.com



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to do something a bit complicated with inline decoding?
  2001-10-19 13:07           ` Kai Großjohann
  2001-10-19 23:51             ` Lloyd Zusman
@ 2001-10-20 10:34             ` Raymond Scholz
  1 sibling, 0 replies; 10+ messages in thread
From: Raymond Scholz @ 2001-10-20 10:34 UTC (permalink / raw)


Kai.Grossjohann@CS.Uni-Dortmund.DE (Kai Großjohann) writes:
 
> But I know that I've seen mention of using w3m.el with Gnus.  But where?

;; Greg in <2fasnftcpt4.fsf@broadcom.com> on gnu.emacs.help
(defvar gnus-w3m-minor-mode nil)

(make-variable-buffer-local 'gnus-w3m-minor-mode)
(add-to-list 'minor-mode-alist '(gnus-w3m-minor-mode " w3m"))
(add-to-list 'minor-mode-map-alist (cons 'gnus-w3m-minor-mode w3m-mode-map))

(defadvice mm-inline-text (around use-w3m-instead (handle) activate)
  (let ((type (mm-handle-media-subtype handle)))
    (if (not (equal type "html"))
	ad-do-it
      (let ((text (mm-get-part handle))
	    (b (point)))
	(save-excursion
	  (insert text)
	  (save-restriction
	    (narrow-to-region b (point))
	    (goto-char (point-min))
	    (w3m-region (point-min) (point-max))
	    (setq gnus-w3m-minor-mode t))
	  (mm-handle-set-undisplayer
	   handle
	   `(lambda ()
	      (let (buffer-read-only)
		(setq gnus-w3m-minor-mode nil)
		(if (functionp 'remove-specifier)
		    (mapcar (lambda (prop)
			      (remove-specifier
			       (face-property 'default prop)
			       (current-buffer)))
			    '(background background-pixmap foreground)))
		(delete-region ,(point-min-marker)
			       ,(point-max-marker))))))))))

This code is also being mentioned in the file TIPS.ja (japanese)
coming with emacs-w3m.  It should do inline images with Emacs 21 too.
                               
Cheers, Ray
-- 
Hfr fgebat rapelcgvba!



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2001-10-20 10:34 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-18  1:38 How to do something a bit complicated with inline decoding? 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
2001-10-19 13:07           ` Kai Großjohann
2001-10-19 23:51             ` Lloyd Zusman
2001-10-20 10:34             ` Raymond Scholz

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).