all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* html mail filter in gnus
@ 2002-09-17 19:02 Kin Cho
  2002-09-17 22:16 ` James Cozine
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Kin Cho @ 2002-09-17 19:02 UTC (permalink / raw)


Hi,

I'm getting html mail quite often now and it's getting annoying.
Does anyone has a gnus filter to filter out the html tags and
leave the plain text behind?

-kin

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

* Re: html mail filter in gnus
  2002-09-17 19:02 html mail filter in gnus Kin Cho
@ 2002-09-17 22:16 ` James Cozine
  2002-09-18  6:38   ` Ichimusai
  2002-09-18  8:38 ` Kai Großjohann
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 12+ messages in thread
From: James Cozine @ 2002-09-17 22:16 UTC (permalink / raw)


Kin Cho <kin@neoscale.com> writes:

> Hi,
> 
> I'm getting html mail quite often now and it's getting annoying.
> Does anyone has a gnus filter to filter out the html tags and
> leave the plain text behind?
> 
> -kin

,----[ C-h v mm-discouraged-alternatives RET ]
| mm-discouraged-alternatives's value is 
| ("text/html" "text/richtext")
| 
| 
| Documentation:
| List of MIME types that are discouraged when viewing multipart/alternative.
| Viewing agents are supposed to view the last possible part of a message,
| as that is supposed to be the richest.  However, users may prefer other
| types instead, and this list says what types are most unwanted.  If,
| for instance, text/html parts are very unwanted, and text/richtext are
| somewhat unwanted, then the value of this variable should be set
| to:
| 
|  ("text/html" "text/richtext")
| 
| You can customize this variable.
| 
| Defined in `mm-decode'.
`----

-jc
-- 
Debug is human, de-fix divine.

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

* Re: html mail filter in gnus
  2002-09-17 22:16 ` James Cozine
@ 2002-09-18  6:38   ` Ichimusai
  0 siblings, 0 replies; 12+ messages in thread
From: Ichimusai @ 2002-09-18  6:38 UTC (permalink / raw)


James Cozine <jmcozine@yahoo.com> writes:

> Kin Cho <kin@neoscale.com> writes:
> 
> > Hi,
> > 
> > I'm getting html mail quite often now and it's getting annoying.
> > Does anyone has a gnus filter to filter out the html tags and
> > leave the plain text behind?
> > 
> > -kin
> 
> ,----[ C-h v mm-discouraged-alternatives RET ]
> | mm-discouraged-alternatives's value is 
> | ("text/html" "text/richtext")

This works best if there is a plain text part to the message. However I
receive lots of mails which does not have a plain text message in them
at all and that is annoying.

W3 catches some of them, and renders them nicely enough, but if it is
MS Exchange who has converted the mail into HTML or if it is sent by
Outlook or Outlook Express, the HTML is so bad that W3 gives up and
the message is shown in HTML source instead. It's ugly. It got worse
since I upgraded W3.

If everything else fails I use this:

;; Remove HTML tags from a buffer
(defun wash-ugly-html ()
  "Remove ugly HTML tags"
  (interactive)
  (toggle-read-only -1)
  (save-excursion
    (beginning-of-buffer)
    (while (re-search-forward "<[^<@>]*>" nil t)
      (replace-match "" nil nil))
    (beginning-of-buffer)
    (while (re-search-forward "&gt;" nil t)
      (replace-match ">" nil nil))
    (beginning-of-buffer)
    (while (re-search-forward "&lt;" nil t)
      (replace-match "<" nil nil))
    (beginning-of-buffer)
    (while (re-search-forward "&.*;" nil t)
      (replace-match "" nil nil))))

Bind it to a key of your liking and use it when all else fails. Not
the most elegant solution, but it works. It leaves a few tags in
sometimes, it's made to leave the References: line in the header and
email addresses, but it makes things a lot more readable.

-- 
  // AA#769 ICQ: 1645566 http://www.ichimusai.org/
\X/  ASCII ribbon campaign - No HTML, RTF or MS Word in mail
Morality is doing what is right, no matter what you're told.  
Religion is doing what you're told, not matter what is right.
    -- Jerry Sturdivant, alt.atheism

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

* Re: html mail filter in gnus
  2002-09-17 19:02 html mail filter in gnus Kin Cho
  2002-09-17 22:16 ` James Cozine
@ 2002-09-18  8:38 ` Kai Großjohann
  2002-09-18  8:57 ` Jonas Steverud
  2002-09-18 20:07 ` D. Goel
  3 siblings, 0 replies; 12+ messages in thread
From: Kai Großjohann @ 2002-09-18  8:38 UTC (permalink / raw)


Kin Cho <kin@neoscale.com> writes:

> I'm getting html mail quite often now and it's getting annoying.
> Does anyone has a gnus filter to filter out the html tags and
> leave the plain text behind?

I use w3m together with emacs-w3m or w3m_el or whatever this package
is called.  That seems to do a decent job if displaying the HTML in
an unobtrusive way.

kai
-- 
~/.signature is: umop 3p!sdn    (Frank Nobis)

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

* Re: html mail filter in gnus
  2002-09-17 19:02 html mail filter in gnus Kin Cho
  2002-09-17 22:16 ` James Cozine
  2002-09-18  8:38 ` Kai Großjohann
@ 2002-09-18  8:57 ` Jonas Steverud
  2002-09-18 20:07 ` D. Goel
  3 siblings, 0 replies; 12+ messages in thread
From: Jonas Steverud @ 2002-09-18  8:57 UTC (permalink / raw)


Kin Cho <kin@neoscale.com> writes:

> Hi,
>
> I'm getting html mail quite often now and it's getting annoying.
> Does anyone has a gnus filter to filter out the html tags and
> leave the plain text behind?

I've added the following during the pGnus days:

(add-to-list 'mm-inline-media-tests '("text/html" nil (lambda (h) nil)))
(add-to-list 'mm-discouraged-alternatives "text/html")
(add-to-list 'mm-discouraged-alternatives "text/richtext")
(add-to-list 'mm-discouraged-alternatives "text/enriched")
(setq mm-automatic-display (remove "text/html" mm-automatic-display))
(setq mm-automatic-display (remove "text/richtext" mm-automatic-display))
(setq mm-automatic-display (remove "text/enriched" mm-automatic-display))

It doesn't handle all possible, broken ways HTML can get to you but it
helps a bit.

(Improvements that doesn't involve W3 or similar are welcome.)

-- 
(          www.dtek.chalmers.se/~d4jonas/         !     Wei Wu Wei     )
(        Meaning of U2 Lyrics, Roleplaying        !  To Do Without Do  )

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

* Re: html mail filter in gnus
  2002-09-17 19:02 html mail filter in gnus Kin Cho
                   ` (2 preceding siblings ...)
  2002-09-18  8:57 ` Jonas Steverud
@ 2002-09-18 20:07 ` D. Goel
  2002-09-19 20:28   ` Kin Cho
  3 siblings, 1 reply; 12+ messages in thread
From: D. Goel @ 2002-09-18 20:07 UTC (permalink / raw)



> Hi,
> 
> I'm getting html mail quite often now and it's getting annoying.
> Does anyone has a gnus filter to filter out the html tags and
> leave the plain text behind?


this shows you the lynxed mail.. this got into my .gnus from an
earlier post in g.e.gnus --->


;; function to call to handle text/html attachments
(defun my:gnus-html2text (handle)
  (let (text)
    (with-temp-buffer
      (mm-insert-part handle)
      (save-window-excursion
  	(my:html2text-region (point-min) (point-max))
  	(setq text (buffer-string))))
    (mm-insert-inline handle text)))

(defun my:html2text-region (min max)
  "Replace the HTML region from MIN to MAX with lynx --dump."
  (interactive "r")
  (let ((file "~/tmp/email.html"))
    (unwind-protect
        (progn
          (write-region min max file)
          (delete-region min max)
          (insert (shell-command-to-string
                   (concat "lynx "
                           "lynx -dump "
                           (shell-quote-argument
                            (expand-file-name file))))))
      ;;(delete-file file)
      )))



(And of course, after that, to see the actual html mail in lynx
itself, you can always type "lynx ~/tmp/email.html" on a term once
gnus has put it there.. in fact

alias browseemail='lynx ~/tmp/email.html'
or
alias browseemail='w3m ~/tmp/email.html'
)

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

* Re: html mail filter in gnus
  2002-09-18 20:07 ` D. Goel
@ 2002-09-19 20:28   ` Kin Cho
  2002-09-19 20:58     ` D. Goel
  0 siblings, 1 reply; 12+ messages in thread
From: Kin Cho @ 2002-09-19 20:28 UTC (permalink / raw)


D. Goel <deego@glue.umd.edu> writes:

> > Hi,
> > 
> > I'm getting html mail quite often now and it's getting annoying.
> > Does anyone has a gnus filter to filter out the html tags and
> > leave the plain text behind?
> 
> 
> this shows you the lynxed mail.. this got into my .gnus from an
> earlier post in g.e.gnus --->
> 
> 
> ;; function to call to handle text/html attachments
> (defun my:gnus-html2text (handle)
>   (let (text)
>     (with-temp-buffer
>       (mm-insert-part handle)
>       (save-window-excursion
>   	(my:html2text-region (point-min) (point-max))
>   	(setq text (buffer-string))))
>     (mm-insert-inline handle text)))
> 
> (defun my:html2text-region (min max)
>   "Replace the HTML region from MIN to MAX with lynx --dump."
>   (interactive "r")
>   (let ((file "~/tmp/email.html"))
>     (unwind-protect
>         (progn
>           (write-region min max file)
>           (delete-region min max)
>           (insert (shell-command-to-string
>                    (concat "lynx "
>                            "lynx -dump "
>                            (shell-quote-argument
>                             (expand-file-name file))))))
>       ;;(delete-file file)
>       )))

Hi,

This approach seems to best fit my need.  How do you hook
my:gnus-html2text into gnus so that it is run automatically on
html mail?

Thanks.

-kin

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

* Re: html mail filter in gnus
  2002-09-19 20:28   ` Kin Cho
@ 2002-09-19 20:58     ` D. Goel
  2002-09-19 21:00       ` D. Goel
  0 siblings, 1 reply; 12+ messages in thread
From: D. Goel @ 2002-09-19 20:58 UTC (permalink / raw)


Kin Cho <kin@neoscale.com> writes:

> This approach seems to best fit my need.  How do you hook
> my:gnus-html2text into gnus so that it is run automatically on
> html mail?

oh, forgot to paste that part.. wow, never realized my .gnus has
become so bizarre by now--->

I guess this (dotgnus-remassoc) removes any previous text/html
bindings that mm-inline-media-tests may have.  Dunno if this step is
needed.  Wasn't there a simpler function for this dotgnus-remassoc?
remove* perhaps?


(setq ;; use lynx -dump to view inline HTML mm-inline-media-tests
(cons '("text/html" my:gnus-html2text (lambda (handle) (fboundp
'my:gnus-html2text))) (dotgnus-remassoc "text/html"
mm-inline-media-tests)) )



(defun dotgnus-remassoc (elt list)
  (let ((result '()))
    (mapcar (lambda (e) (unless (and (consp e)
				     (equal elt (car e)))
			  (setq result (cons e result))))
	    list)
    (nreverse result)))






DG                                 http://24.197.159.102/~deego/
--

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

* Re: html mail filter in gnus
  2002-09-19 20:58     ` D. Goel
@ 2002-09-19 21:00       ` D. Goel
  2002-09-20 15:17         ` Nils Goesche
  0 siblings, 1 reply; 12+ messages in thread
From: D. Goel @ 2002-09-19 21:00 UTC (permalink / raw)


D. Goel <deego@glue.umd.edu> writes:
> 
> (setq ;; use lynx -dump to view inline HTML mm-inline-media-tests
> (cons '("text/html" my:gnus-html2text (lambda (handle) (fboundp
> 'my:gnus-html2text))) (dotgnus-remassoc "text/html"
> mm-inline-media-tests)) )
> 
> 

Sorry for the ugly formatting --->

(setq
 mm-inline-media-tests (cons '("text/html"
			       (lambda (handle)
				 (fboundp 'my:gnus-html2text)))
			     (dotgnus-remassoc "text/html"
					       mm-inline-media-tests))
 )

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

* Re: html mail filter in gnus
  2002-09-19 21:00       ` D. Goel
@ 2002-09-20 15:17         ` Nils Goesche
  2002-09-20 16:45           ` D. Goel
  0 siblings, 1 reply; 12+ messages in thread
From: Nils Goesche @ 2002-09-20 15:17 UTC (permalink / raw)


D. Goel <deego@glue.umd.edu> writes:

[howto use lynx for HTML MIME parts]

And after a few changes, it works fine for me, too.  Thanks!

Here everything together:


(defun my:gnus-html2text (handle)
  (let (text)
    (with-temp-buffer
      (mm-with-unibyte-buffer
	(mm-insert-part handle)
	(save-window-excursion
	  (my:html2text-region (point-min) (point-max))
	  (setq text (buffer-string)))))
    (mm-insert-inline handle text)))

(defun my:html2text-region (min max)
  "Replace the HTML region from MIN to MAX with lynx --dump."
  (interactive "r")
  (let ((file "/tmp/email.html"))
    (unwind-protect
	 (progn
	   (write-region min max file)
	   (delete-region min max)
	   (insert (shell-command-to-string
		    (concat "lynx "
			    "lynx -dump "
			    (shell-quote-argument
			     (expand-file-name file))))))
      (delete-file file))))

(setq mm-inline-media-tests
      (cons '("text/html" my:gnus-html2text
	      (lambda (handle)
		(fboundp 'my:gnus-html2text)))
	    (let ((old (assoc "text/html" mm-inline-media-tests)))
	      (if old
		  (delete old mm-inline-media-tests)
		  mm-inline-media-tests))))

Regards,
-- 
Nils Goesche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x0655CFA0

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

* Re: html mail filter in gnus
  2002-09-20 15:17         ` Nils Goesche
@ 2002-09-20 16:45           ` D. Goel
  2002-09-20 17:59             ` Nils Goesche
  0 siblings, 1 reply; 12+ messages in thread
From: D. Goel @ 2002-09-20 16:45 UTC (permalink / raw)





>   (let ((file "/tmp/email.html"))

Wanna write out your personal email to /tmp? :) 


DG                                 http://24.197.159.102/~deego/
--

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

* Re: html mail filter in gnus
  2002-09-20 16:45           ` D. Goel
@ 2002-09-20 17:59             ` Nils Goesche
  0 siblings, 0 replies; 12+ messages in thread
From: Nils Goesche @ 2002-09-20 17:59 UTC (permalink / raw)


D. Goel <deego@glue.umd.edu> writes:

> >   (let ((file "/tmp/email.html"))
> 
> Wanna write out your personal email to /tmp? :) 

Actually, it was /tmp/nils/email.html, with nils set to 700, but I
thought I'd better remove the ``nils'' part before posting :-)

Regards,
-- 
Nils Goesche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x0655CFA0

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

end of thread, other threads:[~2002-09-20 17:59 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-09-17 19:02 html mail filter in gnus Kin Cho
2002-09-17 22:16 ` James Cozine
2002-09-18  6:38   ` Ichimusai
2002-09-18  8:38 ` Kai Großjohann
2002-09-18  8:57 ` Jonas Steverud
2002-09-18 20:07 ` D. Goel
2002-09-19 20:28   ` Kin Cho
2002-09-19 20:58     ` D. Goel
2002-09-19 21:00       ` D. Goel
2002-09-20 15:17         ` Nils Goesche
2002-09-20 16:45           ` D. Goel
2002-09-20 17:59             ` Nils Goesche

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.