[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
dealing with html email programatically
- From: rrandresf@xxxxxxxxx (=?utf-8?q?Andr=C3=A9s_Ram=C3=ADrez?=)
- Date: Wed, 21 Aug 2019 15:17:41 +0000
- X-ml-name: emacs-w3m
- X-mail-count: 13535
Hi guys.
I am trying to show notifications about new email (my email client is wanderlust), the notification
should include the first line on the body. So I need to convert html to
plain text programatically (html string is a variable).
My function is this one:
--8<---------------cut here---------------start------------->8---
(defun my/get-body-according-to-content-type (content-type-text-param my-message-body-string-param)
"dealing with html email on wanderlust
my/chomp does trim (remove blank space)"
(let ((my-content-type-list (split-string content-type-text-param ";"))
my-content-type-value my-content-type-second-arg)
(setq my-content-type-value (my/chomp (car my-content-type-list)))
(cond ((string-equal "text/plain" my-content-type-value)
my-message-body-string-param
)
((string-equal "text/html" my-content-type-value)
(with-temp-buffer
(insert my-message-body-string-param)
(w3m-buffer)
(buffer-substring-no-properties (point-min) (point-max))
)
)
((string-equal "multipart/alternative" my-content-type-value)
(setq
my-content-type-second-arg (my/chomp (cadr my-content-type-list))
my-content-type-second-arg (cadr (split-string my-content-type-second-arg "\""))
)
(with-temp-buffer
(insert my-message-body-string-param)
(goto-char (point-min))
(search-forward my-content-type-second-arg nil nil 2)
(forward-char 1)
(let ((beg (point))) (search-forward my-content-type-second-arg)(beginning-of-line) (forward-char -1)(copy-region-as-kill beg (point)))
)
(with-temp-buffer
(insert (current-kill 0))
(w3m-buffer)
(buffer-substring-no-properties (point-min) (point-max))
)
)
((string-equal "multipart/mixed" my-content-type-value)
; dealing with this later
my-content-type-value
)
))
)
--8<---------------cut here---------------end--------------->8---
Is there a better function than w3m-buffer for my case?
BR