diff options
Diffstat (limited to 'mail.el')
-rw-r--r-- | mail.el | 78 |
1 files changed, 77 insertions, 1 deletions
@@ -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)))) |