Commit d0520489b106

Vincent Demeester <vincent@sbr.pm>
2026-01-28 15:51:59
feat(mail): add mbsync timer to sync local changes
Run mbsync every 15 minutes to push local changes (sent mail, moved messages, drafts) to the server. This complements goimapnotify which only triggers on incoming mail via IMAP IDLE. Updates mu index after sync, using emacsclient if mu4e is running to avoid lock conflicts. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 35101c4
Changed files (1)
home
common
desktop
home/common/desktop/mails.nix
@@ -96,6 +96,22 @@
 
   programs.mbsync.enable = true;
   programs.msmtp.enable = true;
+
+  # Run mbsync periodically to push local changes (sent mail, moved messages)
+  # This complements goimapnotify which only triggers on incoming mail
+  services.mbsync = {
+    enable = true;
+    frequency = "*:0/15"; # Every 15 minutes
+    postExec = ''
+      # Update mu index after sync
+      # Use emacsclient if mu4e is running to avoid lock conflicts
+      if ${pkgs.procps}/bin/pgrep -u $UID mu >/dev/null 2>&1; then
+        ${pkgs.emacs}/bin/emacsclient --eval '(mu4e-update-index)' 2>/dev/null || true
+      else
+        ${pkgs.mu}/bin/mu index --quiet
+      fi
+    '';
+  };
   programs.mu = {
     enable = true;
     # Use XDG_DATA_HOME instead of XDG_CACHE_HOME to persist the mu database