fix(mu4e): support mu 1.8

Thanks to some combination of ignorance and obstinance, mu4e has thrown
compatibility to the wind and completely ignored the exitance of
define-obsolete-function-alias. Coupled with the inconsistent/partial
function renaming, this has made the mu4e 1.6⟶1.8 change particularly
annoying to deal with.

By suffering the pain of doing the mu4e author's work for them, we can
use defalias to give backwards compatibility a good shot for about 60
functions. Some mu4e~x functions are now mu4e--x, others are unchanged,
and then you've got a few odd changes like mu4e~proc -> mu4e--server and
mu4e-search-rerun. The form of message :from entries has also changed,
and a new (mu4e) entrypoint added supplanting mu4e~start.

Fix: #6511
Close: #6549
Co-authored-by: Rahguzar <aikrahguzar@gmail.com>
This commit is contained in:
TEC 2022-07-11 00:47:43 +08:00 committed by Henrik Lissner
parent 33c5f3721a
commit b07614037f
3 changed files with 59 additions and 18 deletions

View file

@ -67,7 +67,7 @@ default/fallback account."
(setq +mu4e--old-wconf (current-window-configuration)) (setq +mu4e--old-wconf (current-window-configuration))
(delete-other-windows) (delete-other-windows)
(switch-to-buffer (doom-fallback-buffer))) (switch-to-buffer (doom-fallback-buffer)))
(mu4e~start 'mu4e~main-view) (mu4e)
;; (save-selected-window ;; (save-selected-window
;; (prolusion-mail-show)) ;; (prolusion-mail-show))
) )
@ -188,6 +188,8 @@ is tomorrow. With two prefixes, select the deadline."
(lev (org-outline-level)) (lev (org-outline-level))
(folded-p (invisible-p (point-at-eol))) (folded-p (invisible-p (point-at-eol)))
(from (plist-get msg :from))) (from (plist-get msg :from)))
(if (consp (car from)) ; Occurs when using mu4e 1.8+.
(setq from (car from)))
;; place the subheader ;; place the subheader
(when folded-p (show-branches)) ; unfold if necessary (when folded-p (show-branches)) ; unfold if necessary
(org-end-of-meta-data) ; skip property drawer (org-end-of-meta-data) ; skip property drawer

View file

@ -76,7 +76,7 @@ Else, write to this process' PID to the lock file"
"Handle another process requesting the Mu4e lock." "Handle another process requesting the Mu4e lock."
(when (equal (nth 1 event) 'created) (when (equal (nth 1 event) 'created)
(when +mu4e-lock-relaxed (when +mu4e-lock-relaxed
(mu4e~stop) (mu4e--stop)
(file-notify-rm-watch +mu4e-lock--file-watcher) (file-notify-rm-watch +mu4e-lock--file-watcher)
(message "Someone else wants to use Mu4e, releasing lock") (message "Someone else wants to use Mu4e, releasing lock")
(delete-file +mu4e-lock-file) (delete-file +mu4e-lock-file)
@ -90,4 +90,4 @@ Else, write to this process' PID to the lock file"
(setq +mu4e-lock--file-just-deleted t) (setq +mu4e-lock--file-just-deleted t)
(when (and +mu4e-lock-greedy (+mu4e-lock-available t)) (when (and +mu4e-lock-greedy (+mu4e-lock-available t))
(message "Noticed Mu4e lock was available, grabbed it") (message "Noticed Mu4e lock was available, grabbed it")
(run-at-time 0.2 nil #'mu4e~start))))) (run-at-time 0.2 nil #'mu4e)))))

View file

@ -14,7 +14,8 @@
:commands mu4e mu4e-compose-new :commands mu4e mu4e-compose-new
:init :init
(provide 'html2text) ; disable obsolete package (provide 'html2text) ; disable obsolete package
(when (or (not (require 'mu4e-meta nil t)) (when (or (not (or (require 'mu4e-config nil t)
(require 'mu4e-meta nil t)))
(version< mu4e-mu-version "1.4")) (version< mu4e-mu-version "1.4"))
(setq mu4e-maildir "~/.mail" (setq mu4e-maildir "~/.mail"
mu4e-user-mail-address-list nil)) mu4e-user-mail-address-list nil))
@ -22,6 +23,49 @@
(lambda (&rest _) (lambda (&rest _)
(expand-file-name ".attachments" (mu4e-root-maildir)))) (expand-file-name ".attachments" (mu4e-root-maildir))))
:config :config
(when (version< mu4e-mu-version "1.8")
;; Evidently the mu4e author has never heard of `define-obsolete-function-alias'.
;; List of suffixes obtained by comparing mu4e~ and mu4e-- functions in `obarray'.
(dolist (transferable-suffix
'("check-requirements" "contains-line-matching" "context-ask-user"
"context-autoswitch" "default-handler" "get-folder" "get-log-buffer"
"get-mail-process-filter" "guess-maildir" "key-val"
"longest-of-maildirs-and-bookmarks" "maildirs-with-query"
"main-action-str" "main-bookmarks" "main-maildirs" "main-menu"
"main-queue-size" "main-redraw-buffer"
"main-toggle-mail-sending-mode" "main-view" "main-view-queue"
"main-view-real" "main-view-real-1" "mark-ask-target"
"mark-check-target" "mark-clear" "mark-find-headers-buffer"
"mark-get-dyn-target" "mark-get-markpair" "mark-get-move-target"
"mark-in-context" "mark-initialize" "org-store-link-message"
"org-store-link-query" "pong-handler" "read-char-choice"
"read-patch-directory" "replace-first-line-matching"
"request-contacts-maybe" "rfc822-phrase-type" "start" "stop"
"temp-window" "update-contacts" "update-mail-and-index-real"
"update-mail-mode" "update-sentinel-func"))
(defalias (intern (concat "mu4e--" transferable-suffix))
(intern (concat "mu4e~" transferable-suffix))
"Alias to provide the API of mu4e 1.8 (mu4e~ ⟶ mu4e--).")
(dolist (transferable-proc-suffixes
'("add" "compose" "contacts" "eat-sexp-from-buf" "filter"
"find" "index" "kill" "mkdir" "move" "ping" "remove"
"sent" "sentinel" "start" "view"))
(defalias (intern (concat "mu4e--server-" transferable-proc-suffixes))
(intern (concat "mu4e~proc-" transferable-proc-suffixes))
"Alias to provide the API of mu4e 1.8 (mu4e~proc ⟶ mu4e--server)."))
(defalias 'mu4e-search-rerun #'mu4e-headers-rerun-search
"Alias to provide the API of mu4e 1.8.")
(defun mu4e (&optional background)
"If mu4e is not running yet, start it.
Then, show the main window, unless BACKGROUND (prefix-argument)
is non-nil."
(interactive "P")
(mu4e--start (and (not background) #'mu4e--main-view))))
(setq mu4e-view-show-addresses t
mu4e-view-show-images t
mu4e-view-image-max-width 800
mu4e-view-use-gnus t))
(pcase +mu4e-backend (pcase +mu4e-backend
(`mbsync (`mbsync
(setq mu4e-get-mail-command "mbsync -a" (setq mu4e-get-mail-command "mbsync -a"
@ -30,13 +74,8 @@
(setq mu4e-get-mail-command "offlineimap -o -q"))) (setq mu4e-get-mail-command "offlineimap -o -q")))
(setq mu4e-update-interval nil (setq mu4e-update-interval nil
mu4e-view-show-addresses t
mu4e-sent-messages-behavior 'sent mu4e-sent-messages-behavior 'sent
mu4e-hide-index-messages t mu4e-hide-index-messages t
;; try to show images
mu4e-view-show-images t
mu4e-view-image-max-width 800
mu4e-view-use-gnus t ; the way of the future: https://github.com/djcb/mu/pull/1442#issuecomment-591695814
;; configuration for sending mail ;; configuration for sending mail
message-send-mail-function #'smtpmail-send-it message-send-mail-function #'smtpmail-send-it
smtpmail-stream-type 'starttls smtpmail-stream-type 'starttls
@ -175,7 +214,7 @@
;; Marks usually affect the current view ;; Marks usually affect the current view
(defadvice! +mu4e--refresh-current-view-a (&rest _) (defadvice! +mu4e--refresh-current-view-a (&rest _)
:after #'mu4e-mark-execute-all (mu4e-headers-rerun-search)) :after #'mu4e-mark-execute-all (mu4e-search-rerun))
;; Wrap text in messages ;; Wrap text in messages
(setq-hook! 'mu4e-view-mode-hook truncate-lines nil) (setq-hook! 'mu4e-view-mode-hook truncate-lines nil)
@ -183,7 +222,7 @@
;; Html mails might be better rendered in a browser ;; Html mails might be better rendered in a browser
(add-to-list 'mu4e-view-actions '("View in browser" . mu4e-action-view-in-browser)) (add-to-list 'mu4e-view-actions '("View in browser" . mu4e-action-view-in-browser))
(when (fboundp 'make-xwidget) (when (fboundp 'make-xwidget)
(add-to-list 'mu4e-view-actions '("xwidgets view" . mu4e-action-view-with-xwidget))) (add-to-list 'mu4e-view-actions '("xwidgets view" . mu4e-action-view-in-xwidget)))
;; Detect empty subjects, and give users an opotunity to fill something in ;; Detect empty subjects, and give users an opotunity to fill something in
(defun +mu4e-check-for-subject () (defun +mu4e-check-for-subject ()
@ -321,8 +360,8 @@ This should already be the case yet it does not always seem to be."
This is enacted by `+mu4e~main-action-str-prettier-a' and This is enacted by `+mu4e~main-action-str-prettier-a' and
`+mu4e~main-keyval-str-prettier-a'.") `+mu4e~main-keyval-str-prettier-a'.")
(advice-add #'mu4e~key-val :filter-return #'+mu4e~main-keyval-str-prettier-a) (advice-add #'mu4e--key-val :filter-return #'+mu4e~main-keyval-str-prettier-a)
(advice-add #'mu4e~main-action-str :override #'+mu4e~main-action-str-prettier-a) (advice-add #'mu4e--main-action-str :override #'+mu4e~main-action-str-prettier-a)
(when (featurep! :editor evil) (when (featurep! :editor evil)
;; As +mu4e~main-action-str-prettier replaces [k]ey with key q]uit should become quit ;; As +mu4e~main-action-str-prettier replaces [k]ey with key q]uit should become quit
(setq evil-collection-mu4e-end-region-misc "quit")) (setq evil-collection-mu4e-end-region-misc "quit"))
@ -334,7 +373,7 @@ This is enacted by `+mu4e~main-action-str-prettier-a' and
+mu4e-lock-request-file (expand-file-name "~/AppData/Local/Temp/mu4e_lock_request"))) +mu4e-lock-request-file (expand-file-name "~/AppData/Local/Temp/mu4e_lock_request")))
(add-hook 'kill-emacs-hook #'+mu4e-lock-file-delete-maybe) (add-hook 'kill-emacs-hook #'+mu4e-lock-file-delete-maybe)
(advice-add 'mu4e~start :around #'+mu4e-lock-start) (advice-add 'mu4e--start :around #'+mu4e-lock-start)
(advice-add 'mu4e-quit :after #'+mu4e-lock-file-delete-maybe)) (advice-add 'mu4e-quit :after #'+mu4e-lock-file-delete-maybe))
(unless (featurep! +org) (unless (featurep! +org)
@ -575,7 +614,7 @@ See `+mu4e-msg-gmail-p' and `mu4e-sent-messages-behavior'.")
;; ;;
;; Gmail will handle the rest. ;; Gmail will handle the rest.
(defun +mu4e--mark-seen (docid _msg target) (defun +mu4e--mark-seen (docid _msg target)
(mu4e~proc-move docid (mu4e~mark-check-target target) "+S-u-N")) (mu4e--server-move docid (mu4e--mark-check-target target) "+S-u-N"))
(defvar +mu4e--last-invalid-gmail-action 0) (defvar +mu4e--last-invalid-gmail-action 0)
@ -592,7 +631,7 @@ See `+mu4e-msg-gmail-p' and `mu4e-sent-messages-behavior'.")
(when (< 2 (- (float-time) +mu4e--last-invalid-gmail-action)) (when (< 2 (- (float-time) +mu4e--last-invalid-gmail-action))
(sit-for 1)) (sit-for 1))
(setq +mu4e--last-invalid-gmail-action (float-time))) (setq +mu4e--last-invalid-gmail-action (float-time)))
(mu4e~proc-remove docid)))) (mu4e--server-remove docid))))
(alist-get 'trash mu4e-marks) (alist-get 'trash mu4e-marks)
(list :char '("d" . "") (list :char '("d" . "")
:prompt "dtrash" :prompt "dtrash"
@ -600,7 +639,7 @@ See `+mu4e-msg-gmail-p' and `mu4e-sent-messages-behavior'.")
:action (lambda (docid msg target) :action (lambda (docid msg target)
(if (+mu4e-msg-gmail-p msg) (if (+mu4e-msg-gmail-p msg)
(+mu4e--mark-seen docid msg target) (+mu4e--mark-seen docid msg target)
(mu4e~proc-move docid (mu4e~mark-check-target target) "+T-N")))) (mu4e--server-move docid (mu4e--mark-check-target target) "+T-N"))))
;; Refile will be my "archive" function. ;; Refile will be my "archive" function.
(alist-get 'refile mu4e-marks) (alist-get 'refile mu4e-marks)
(list :char '("r" . "") (list :char '("r" . "")
@ -609,7 +648,7 @@ See `+mu4e-msg-gmail-p' and `mu4e-sent-messages-behavior'.")
:action (lambda (docid msg target) :action (lambda (docid msg target)
(if (+mu4e-msg-gmail-p msg) (if (+mu4e-msg-gmail-p msg)
(+mu4e--mark-seen docid msg target) (+mu4e--mark-seen docid msg target)
(mu4e~proc-move docid (mu4e~mark-check-target target) "-N"))) (mu4e--server-move docid (mu4e--mark-check-target target) "-N")))
#'+mu4e--mark-seen)) #'+mu4e--mark-seen))
;; This hook correctly modifies gmail flags on emails when they are marked. ;; This hook correctly modifies gmail flags on emails when they are marked.