You wrote:
> Is there a way to configure VM to run this function only when I click mouse-2 
> on an HTML button?

The below isn't an answer to your question. However, it is how I make HTML 
messages visible in a browser. (The "Seems really hacky" comment sums up the 
whole thing, really, but it has worked for me for years. I am on 8.2.0b.)

----

(defun my-vm-view-html-in-browser ()
  "In VM, view HTML message in external browser.

TODO: Better handle message with HTML within attached message."
  (interactive)
  (when (vm-current-message)
    ;; Does message have HTML?
    (let ((result)
          (vm-current-message-layout (prin1-to-string (vm-mm-layout 
(vm-current-message)))))
                                        ; Seems really hacky
      (if (string-match-p "text/html" vm-current-message-layout)
          (progn ; Yes, HTML is present.
                                        ; Store window arrangement
            (vm-save-window-configuration 'my-vm-view-html-in-browser)
            (when (boundp 'vm-mime-decoded)
              (unless (string-equal "buttons" vm-mime-decoded)
                (vm-decode-mime-message 'buttons)
                (unless (string-equal "buttons" vm-mime-decoded)
                  (vm-decode-mime-message 'buttons)))) ; Second time
                                                       ; guarantees
                                                       ; button
                                                       ; display from
                                                       ; undecoded
                                                       ; message
            (vm-beginning-of-message)
            (if (re-search-forward "^HTML (" nil 0)
                (progn
                  (setq result "Showing HTML message in external browser...")
                  (vm-inform 5 result)
                  (vm-mime-reader-map-display-using-external-viewer)
                  (setq result "Showing HTML message in external browser... 
done."))
                                        ; Seach for HTML attachment failed.
              (setq result "No HTML found in message")
                                        ; Attached message present
                                        ; (might be the only fail
                                        ; case)
              (when (string-match-p "message/" vm-current-message-layout)
                (setq result (concat result ". Check attached message"))))
            (vm-decode-mime-message 'undecoded) ; Why is this necessary?
            (vm-decode-mime-message 'decoded)
                                        ; Restore window arrangement
            (vm-apply-window-configuration 'my-vm-view-html-in-browser))
        (setq result "No HTML found in message")) ; No HTML.

      (if (string-prefix-p "No HTML found" result)
          (error (vm-inform 5 result))
        ;; Below hopefully no longer needed with
        ;; vm-mime-delete-viewer-processes nil
      ;;        (vm-inform 5 result))
      ;; (when (string-equal "Showing HTML message in external browser." result)
      ;;        (sleep-for .25))))) ; Force wait to ensure openremote isn't 
interrupted
        (vm-inform 5 result)))))

; Bound to "H" key
(define-key vm-mode-map [remap vm-folders-summarize] 
'my-vm-view-html-in-browser)

Reply via email to