From 89e27d124124156a01a228f785aa240e531afc35 Mon Sep 17 00:00:00 2001 From: Ravi R Kiran Date: Sun, 22 Aug 2021 21:52:13 -0500 Subject: Save last fetch contexts diff --git a/lisp/ravi-init-mu.el b/lisp/ravi-init-mu.el index c16db6b..1b26582 100644 --- a/lisp/ravi-init-mu.el +++ b/lisp/ravi-init-mu.el @@ -96,22 +96,25 @@ ;; Poll accounts only as often as necessary (defvar ravi/mu4e-get-mail-attempts 0 "Number of attempts so far to get mail") + (defvar ravi/mu4e-last-fetched-contexts nil + "The contexts for the last fetch") (defun ravi/check-whether-to-get-mail-for-account (context) (let* ((account-interval (when (mu4e-context-vars context) (assq 'ravi/account-update-interval (mu4e-context-vars context)))) (account-update-interval (if account-interval (cdr account-interval) 1))) - (if (and (> account-update-interval 0) (= (% ravi/mu4e-get-mail-attempts account-update-interval) 0)) - (concat " " (cdr (assq 'ravi/account-name (mu4e-context-vars context)))) - ""))) + (and (> account-update-interval 0) (= (% ravi/mu4e-get-mail-attempts account-update-interval) 0)))) (defun ravi/get-mu4e-get-mail-command () "Figure out arguments to mbsync" - (let ((ravi/all-channels (mapconcat 'ravi/check-whether-to-get-mail-for-account - mu4e-contexts ""))) + (let* ((contexts-to-get (seq-filter #'ravi/check-whether-to-get-mail-for-account mu4e-contexts)) + (context-string (mapconcat (lambda (ctx) + (alist-get 'ravi/account-name + (mu4e-context-vars ctx))) + contexts-to-get " "))) (setq ravi/mu4e-get-mail-attempts (1+ ravi/mu4e-get-mail-attempts)) - (if (= (length ravi/all-channels) 0) - "true" ;; do nothing command - (concat "mbsync -q -q" ravi/all-channels) - ))) + (setq ravi/mu4e-last-fetched-contexts contexts-to-get) + (if contexts-to-get + (concat "mbsync -q -q " context-string) + "true"))) ;; do nothing command (add-hook 'mu4e-update-pre-hook (lambda () (setq mu4e-get-mail-command (ravi/get-mu4e-get-mail-command)) -- cgit v0.10.1