This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

mailserver: sync notmuch tags to Maildir flags after muchsync

muchsync writes tags directly to the xapian database, bypassing
notmuch's synchronize_flags. This means read/unread status from
mutt never gets reflected in Maildir filenames, so Dovecot (IMAP)
still shows messages as unread.

Add a systemd path unit that watches the notmuch xapian directory
and renames files to add/remove the S (Seen) flag based on the
notmuch unread tag.

+44
+44
2configs/mailserver.nix
··· 290 290 pkgs.muchsync 291 291 pkgs.msmtp 292 292 ]; 293 + 294 + # After muchsync writes tags to notmuch DB, the Maildir filenames don't get updated 295 + # (muchsync bypasses notmuch's flag sync). This watches the xapian DB for changes and 296 + # renames files to add/remove the S (Seen) flag based on the notmuch unread tag. 297 + systemd.paths.notmuch-flag-sync = { 298 + wantedBy = [ "multi-user.target" ]; 299 + pathConfig.PathChanged = "/var/vmail/lassul.us/lass/mail/.notmuch/xapian"; 300 + }; 301 + systemd.services.notmuch-flag-sync = { 302 + description = "Sync notmuch tags to Maildir flags after muchsync"; 303 + serviceConfig = { 304 + Type = "oneshot"; 305 + User = "lass"; 306 + Group = "virtualMail"; 307 + ExecStart = pkgs.writeShellScript "notmuch-flag-sync" '' 308 + export NOTMUCH_CONFIG="${ 309 + self.packages.${pkgs.system}.notmuch.passthru.configuration.configFile.path 310 + }" 311 + # Add S flag to files notmuch considers read but that lack it 312 + ${pkgs.notmuch}/bin/notmuch search --output=files 'NOT tag:unread' \ 313 + | ${pkgs.gnugrep}/bin/grep -v ',.*S' \ 314 + | ${pkgs.gnugrep}/bin/grep '/cur/' \ 315 + | while IFS= read -r f; do 316 + [ -f "$f" ] || continue 317 + base="''${f%:2,*}" 318 + flags="''${f##*:2,}" 319 + mv "$f" "''${base}:2,''${flags}S" 320 + done 321 + # Remove S flag from files notmuch considers unread but that have it 322 + ${pkgs.notmuch}/bin/notmuch search --output=files 'tag:unread' \ 323 + | ${pkgs.gnugrep}/bin/grep ',.*S' \ 324 + | ${pkgs.gnugrep}/bin/grep '/cur/' \ 325 + | while IFS= read -r f; do 326 + [ -f "$f" ] || continue 327 + base="''${f%:2,*}" 328 + flags="''${f##*:2,}" 329 + newflags="$(echo "$flags" | ${pkgs.gnused}/bin/sed 's/S//g')" 330 + mv "$f" "''${base}:2,''${newflags}" 331 + done 332 + # Update notmuch DB with the renames 333 + ${pkgs.notmuch}/bin/notmuch new --quiet 2>/dev/null || true 334 + ''; 335 + }; 336 + }; 293 337 }