summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2022-11-06 14:21:23 +0800
committerJSDurand <mmemmew@gmail.com>2022-11-06 14:21:23 +0800
commitb4c351611b4368cc3da0bc0f5bc825136829bba2 (patch)
tree3a1a240dfbbbb94ad4ea7397fbbb0cdde8a9295f
parenta8ac8d1ce90b681d90b58f0ad5f2d576f0511c34 (diff)
mail + gnus: Update mails without mu4e
This is the first and maybe the last step to remove the dependency on mu4e. I can now update mails without calling a mu4e function. That is virtually the only functionality I use of mu4e since a long time. I shall have done this a long time ago, but I was too lazy to do so. ;D
-rw-r--r--gnus-conf.el6
-rw-r--r--mail.el78
2 files changed, 80 insertions, 4 deletions
diff --git a/gnus-conf.el b/gnus-conf.el
index c57f7ff..f409b41 100644
--- a/gnus-conf.el
+++ b/gnus-conf.el
@@ -138,10 +138,10 @@
;;; Update by mu4e
-(autoload 'mu4e-update-mail-and-index "mu4e-utils")
+;; (autoload 'mu4e-update-mail-and-index "mu4e-utils")
(autoload 'load-config "init")
-(defalias 'durand-update-mail #'mu4e-update-mail-and-index)
+;; (defalias 'durand-update-mail #'mu4e-update-mail-and-index)
;; Let notmuch know about the changes automatically.
@@ -151,7 +151,7 @@
(add-hook 'mu4e-index-updated-hook #'notmuch-poll)
-(define-key gnus-group-mode-map (vector 117) #'durand-update-mail)
+(define-key gnus-group-mode-map (vector 117) #'durand-mail-update)
(define-key global-map (vector ?\C-c ?g) 'gnus)
;;; Use notmuch to search mails
diff --git a/mail.el b/mail.el
index e238fb2..dd35b4d 100644
--- a/mail.el
+++ b/mail.el
@@ -1,7 +1,7 @@
(use-package "/usr/local/share/emacs/site-lisp/mu/mu4e" 'mu4e
(setq mu4e-maildir-list (list "/Users/durand/mbsync"))
- (setq user-mail-address "mmemmew@gmail.com")
+ (setq user-mail-address "durand@jsdurand.xyz")
(setq mu4e-completing-read-function #'completing-read)
(setq message-confirm-send t)
(setq mu4e~update-buffer-height 5)
@@ -307,3 +307,79 @@ person."
(define-key message-mode-map (vector 3 ?f) #'durand-fix-quotation)
(define-key gnus-summary-mode-map (vector 3 ?f) #'durand-fix-quotation)
(define-key gnus-article-mode-map (vector 3 ?f) #'durand-fix-quotation)
+
+;;; update mails without mu4e
+
+(defun durand-mail-process-output (output)
+ "Normalize the OUTPUT emitted by mu4e."
+ (let ((splitted (split-string output (rx-to-string (list 'any ? ?\n ?\r) t) t)))
+ (or (car (last splitted)) "")))
+
+(defun durand-mail-update-filter (process string)
+ "Insert the ouput STRING into the buffer of PROCESS for updating \
+mails."
+ (let ((buffer (process-buffer process))
+ (output (durand-mail-process-output string)))
+ (cond
+ ((buffer-live-p buffer)
+ (display-buffer
+ buffer
+ (list (list #'display-buffer-in-side-window)
+ (cons 'side 'bottom)
+ (cons 'window-height
+ #'durand-fit-window-to-buffer-with-max)))
+ (with-current-buffer buffer
+ (cond
+ ((and (stringp output)
+ (not (string= output "")))
+ (delete-region (point-min) (point-max))
+ (insert output)
+ (set-marker
+ (process-mark process) (point-max) buffer))))))))
+
+(defun durand-mail-update-sentinel (process status)
+ "Handle STATUS changes of the PROCESS for updating mails."
+ (cond
+ ((string= status "finished\n")
+ (let ((buffer (process-buffer process)))
+ (cond
+ ((buffer-live-p buffer)
+ (quit-window nil (get-buffer-window buffer))))))))
+
+(defvar durand-mail-update-command
+ (list "mbsync" "mymail-inbox" "mymail-sent")
+ "Command to update mails.")
+
+(defvar durand-mail-update-buffer "*mail*"
+ "Buffer to display progess of updating mails.")
+
+(defun durand-mail-update (&optional foreground-p)
+ "Update mails.
+If FOREGROUND-P is non-nil, also display the progress in a
+separate buffer."
+ (interactive (list t))
+ (make-process
+ :name "durand-mail-update"
+ :command durand-mail-update-command
+ :filter (cond (foreground-p #'durand-mail-update-filter))
+ :sentinel (cond (foreground-p #'durand-mail-update-sentinel))
+ :buffer (cond
+ (foreground-p
+ (let ((buffer
+ (get-buffer-create durand-mail-update-buffer)))
+ (buffer-disable-undo buffer)
+ buffer)))))
+
+(defvar durand-mail-update-timer nil
+ "A timer to automatically update mail in the background.")
+
+(defun durand-mail-cancel-timer ()
+ "Cancel `durand-mail-update-timer'."
+ (cancel-timer durand-mail-update-timer))
+
+(cond
+ ((memq #'durand-mail-update
+ (mapcar #'timer--function timer-list)))
+ ((setq
+ durand-mail-update-timer
+ (run-with-timer 0 (* 60 30) #'durand-mail-update))))