一段用 EAF 阅读 mu4e html 邮件 的 elisp 代码

新手,纯属娱乐,基于 (eaf-open-mail-as-html) 改着玩,发现还有一些问题,但是不会解决了。 悲哀:(

(defun my-mu4e-html2text (msg)
  (when-let* ((file (concat (temporary-file-directory) (make-temp-name "eaf-mail-soul11201-") ".html")))

    ;;(with-temp-file file
    ;;(insert msg))
    (with-temp-file file (insert  (or (mu4e-message-field msg :body-html))))
    ;;(message file)
    ;;(switch-to-buffer-other-window file)
    (eaf-open file "browser" "temp_html_file")

    "Open in Eaf"))


(setq mu4e-html2text-command 'my-mu4e-html2text)

EAF不是默认支持邮件功能了吗?

(eaf-open-mail-as-html)

我不知道怎么给mu4e加个hook调用这个函数,所以找了个mu4e 的 这个配置变量 mu4e-html2text-command 抄了一把(eaf-open-mail-as-html) 的代码

还有个问题 (eaf-open-mail-as-html) 打开邮件预览的 buffer 我的按键没反应了,我需要切换到其他分屏的window 去杀掉它。不知道是不是我的配置问题,还是就是这样。

抄的代码也有这个问题。不知道该怎么调试了。。。

正常使用EAF浏览器会出现这问题吗?

没有这个问题

可以去github提个issue,多提供点信息,比如你的配置。

(setq package-archives '(("gnu"   . "http://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/")
                         ("melpa" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/")))
(package-initialize) ;; You might already have this line

(when (memq window-system '(mac ns x))
  (exec-path-from-shell-initialize))

(require 'use-package)

(use-package rime
  :custom
  (default-input-method "rime"))


(setq rime-user-data-dir "~/.config/fcitx/rime")
(setq rime-posframe-properties
      (list :background-color "#333333"
            :foreground-color "#dcdccc"
            :font "WenQuanYi Micro Hei Mono-14"
            :internal-border-width 10))

(setq default-input-method "rime"
      rime-show-candidate 'posframe)

(require 'yaml-mode)
(add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode))

(add-hook 'yaml-mode-hook
    '(lambda ()
       (define-key yaml-mode-map "\C-m" 'newline-and-indent)))


(require 'jq-mode)
(add-to-list 'auto-mode-alist '("\\.jq$" . jq-mode))
(with-eval-after-load "json-mode"
  (define-key json-mode-map (kbd "C-c C-j") #'jq-interactively))

(use-package jq-format
  :demand t
  :after json-mode)

(use-package valign
  :load-path "~/code/emacs/valign"
;;;  :ensure t
  :config
  (add-hook 'org-mode-hook #'valign-mode))

(use-package eaf
  :load-path "~/code/emacs/emacs-application-framework/"
  :custom
  (eaf-find-alternate-file-in-dired t)
  :config
  (eaf-bind-key scroll_up "C-n" eaf-pdf-viewer-keybinding)
  (eaf-bind-key scroll_down "C-p" eaf-pdf-viewer-keybinding)
  (eaf-bind-key take_photo "p" eaf-camera-keybinding))


(setq easy-jekyll-basedir "")
(setq easy-jekyll-image-directory "assets")



(add-to-list 'load-path "/usr/local/share/emacs/site-lisp/mu4e")
(require 'mu4e)

(setq mu4e-root-maildir "~/.mail/outlook")
(setq
 mu4e-sent-folder   "/已发送邮件"       ;; folder for sent messages
 mu4e-drafts-folder "/drafts"     ;; unfinished messages
 mu4e-trash-folder  "/已删除邮件"      ;; trashed messages
 mu4e-refile-folder "/Archive")   ;; saved messages

(setq
  mu4e-get-mail-command "offlineimap"   ;; or fetchmail, or ...
  mu4e-update-interval 300)             ;; update every 5 minutes

; SMTP setup
(setq message-send-mail-function 'smtpmail-send-it
      smtpmail-stream-type 'starttls
      starttls-use-gnutls t)
;; Personal info
(setq user-full-name "")
(setq user-mail-address "")
(setq smtpmail-smtp-server "")
(setq smtpmail-smtp-service 587)
(setq smtpmail-smtp-user "") ;

(setq mu4e-compose-signature "Sent from Emacs,Powered By offlineimap/mu/mu4e")

;; don't keep message buffers around
(setq message-kill-buffer-on-exit t)


;;; (setq mu4e-sent-messages-behavior 'delete) ;;;; just for Gmail read the variables doc `C-h v`
(setq mu4e-attachment-dir "~")




;; enable inline images
;;(setq mu4e-view-show-images t)
;; use imagemagick, if available
;;(when (fboundp 'imagemagick-register-types)
;;  (imagemagick-register-types))

(setq mu4e-view-show-images nil)

(defun my-mu4e-html2text (msg)
  "My html2text function; shows short message inline, show
long messages in some external browser (see `browse-url-generic-program')."
  (let ((html (or (mu4e-message-field msg :body-html) "")))
    (if (> (length html) 20000)
      (progn
	(mu4e-action-view-in-browser msg)
	"[Viewing message in external browser]")
      (mu4e-shr2text msg))))

(setq mu4e-html2text-command 'my-mu4e-html2text)


;;;(eaf-open-mail-as-html)

(defun my-mu4e-html2text- (msg)
  (when-let* ((file (concat (temporary-file-directory) (make-temp-name "eaf-mail-soul11201-") ".html")))
    ;;(with-temp-file file
    ;;(insert msg))
    (with-temp-file file (insert  (or (mu4e-message-field msg :body-html))))
    ;;(message file)
    ;;(switch-to-buffer-other-window file)
    (eaf-open file "browser" "temp_html_file")

    "Open in Eaf"))


;;(my-mu4e-html2text- "hello")

(setq mu4e-html2text-command 'my-mu4e-html2text-)


(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(mu4e-display-update-status-in-modeline t)
 '(mu4e-index-lazy-check nil)
 '(mu4e-speedbar-support nil)
 '(mu4e-use-fancy-chars nil)
 '(package-selected-packages
   '(company-statistics company dracula-theme markdown-mode exec-path-from-shell easy-jekyll helm deft magit-todos jq-mode jq-format counsel yaml-mode flycheck-yamllint vlf magit s rime use-package))
 '(recentf-max-menu-items 10000)
 '(recentf-max-saved-items 20000)
 '(recentf-mode t)
 '(smtpmail-debug-info t)
 '(smtpmail-debug-verb t))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )


;;(load-theme 'dracula t)
;; Don't change the font size for some headings and titles (default t)
;;(setq dracula-enlarge-headings nil)

;; Adjust font size of titles level 1 (default 1.3)
;;(setq dracula-height-title-1 1.25)

;; Adjust font size of titles level 2 (default 1.1)
;;(setq dracula-height-title-1 1.15)

;; Adjust font size of titles level 3 (default 1.0)
;;(setq dracula-height-title-1 1.05)

;; Adjust font size of document titles (default 1.44)
;;(setq dracula-height-doc-title 1.4)

;; Use less pink and bold on the mode-line and minibuffer (default nil)
;;(setq dracula-alternate-mode-line-and-minibuffer t)

(add-hook 'after-init-hook 'global-company-mode)
(add-hook 'after-init-hook 'company-statistics-mode)



(set-face-attribute 'cursor nil :background "red")
(set-face-attribute 'cursor nil :background "skyblue")


我碰到一个类似的问题,后面解决发现mu4e~view-msg mu4e~view-message这两个变量问题 mu (mail indexer/searcher) version 0.9.11 我发现/usr/share/emacs/site-lisp/mu4e/mu4e-vars.el (defvar mu4e~view-msg nil “The message being viewed in view mode.”)

eaf CommitDate: Wed Feb 3 12:07:05 2021 -0500 /.emacs.d/.cache/quelpa/build/eaf/eaf.el (defun eaf-mu4e-get-html () “Retrieve HTML part of a mu4e mail.” (let ((msg mu4e~view-message)) (mu4e-message-field msg :body-html)))