Where parallels cross

Interesting bits of life

YASnippet list also my html email questions please!

In an old post I shared a little hack to highlight the questions to answer in an email. It is still something I use, so that code was indeed valuable.

Today I realized that html messages don't have a text body :body-txt but a :body-html, which broke my code.

Below the improvement which relies on the useful html2text function.

(defun my/pick-questions-in-mail ()
  (interactive)
  (-some--> mu4e-compose-parent-message
    (or (mu4e-message-field it :body-txt)
        (with-temp-buffer
          (insert (mu4e-message-field it :body-html))
          (html2text)
          ;; html2text drops any meaningful separator of the html
          (--> (buffer-string)
               (s-replace-all
                '(("." . ".\n")
                  ("?" . "?\n")
                  ("!" . "!\n"))
                it)
               (s-truncate
                (or
                 ;; trying to skip my referenced message that starts with On 2 Jun 2024 12:35,
                 (caar (s-matched-positions-all "On [0-9] ... [0-9]\\{4\\} [0-9]\\{2\\}:[0-9]\\{2\\}," it))
                 (length it))
                it))))
    (s-split "\n" it)
    (--remove (s-prefix-p "> " it) it)
    (s-join " \n " it)
    my/pick-questions-in-text))

Note the hacky adding of newlines and trimming of your own messages, because we want to respond only the sender questions not our own.

Happy emailing,

Andrea