summaryrefslogtreecommitdiff
path: root/mail.el
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 /mail.el
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
Diffstat (limited to 'mail.el')
-rw-r--r--mail.el78
1 files changed, 77 insertions, 1 deletions
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))))