diff options
Diffstat (limited to 'home/profiles')
-rw-r--r-- | home/profiles/messaging/default.nix | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/home/profiles/messaging/default.nix b/home/profiles/messaging/default.nix index a5a52eb..54d6870 100644 --- a/home/profiles/messaging/default.nix +++ b/home/profiles/messaging/default.nix @@ -4,6 +4,7 @@ let poorObfuscation = y: x: "${x}@${y}"; mailPass = x: "${pkgs.pass}/bin/pass show emails/${x}"; + mbsyncCmd = "${config.programs.mbsync.package}/bin/mbsync"; in { imports = [ ../../modules/programs/nixpkgs ]; @@ -39,7 +40,7 @@ in enable = true; boxes = [ "Inbox" ]; onNotify = pkgs.writeShellScript "imap-on-notify" '' - mbsync zach + ${mbsyncCmd} zach NOTMUCH_CONFIG=${lib.escapeShellArg config.home.sessionVariables.NOTMUCH_CONFIG} NMBGIT=${lib.escapeShellArg config.home.sessionVariables.NMBGIT} ${pkgs.notmuch}/bin/notmuch new @@ -57,7 +58,7 @@ in programs.msmtp.enable = true; programs.notmuch = { enable = true; - hooks.preNew = "mbsync --all"; + hooks.preNew = "${mbsyncCmd} --all"; }; programs.neomutt = { @@ -176,7 +177,46 @@ in programs.notmuch.hooks.postNew = '' ${pkgs.libnotify}/bin/notify-send --icon=mail-unread --app-name=notmuch \ - "Email" "New email available in Inbox" + "Email" "Sync completed" + ''; + + services.imapnotify.enable = true; + + # Sync emails on initial login + systemd.user.services.mbsync-initial = { + Unit = { + Description = "mbsync initial synchronisation"; + After = "graphical-session.target"; + }; + Service = { + ExecStart = "${mbsyncCmd} --all"; + Restart = "on-failure"; + }; + Install.WantedBy = [ "default.target" ]; + }; + + home.file.".mailcap".text = let + setsid = "${pkgs.util-linux}/bin/setsid"; + openfile = "${pkgs.writeShellScript "openfile" '' + # Helps open a file with xdg-open from mutt in a external program without weird side effects. + tempdir="''${TMPDIR:-$(mktemp -d)}" + file="$tempdir/$(basename "$1")" + [ "$(uname)" = "Darwin" ] && opener="open" || opener="${setsid} -f ${pkgs.xdg_utils}/bin/xdg-open" + mkdir -p "$tempdir" + cp -f "$1" "$file" + $opener "$file" >/dev/null 2>&1 + find "''${tempdir:?}" -mtime +1 -type f -delete + ''}"; + in '' + ${lib.optionalString false "text/html; ${pkgs.w3m}/bin/w3m -dump -T text/html -I %{charset} -O utf-8 %s; copiousoutut; description=HTML Text; nametemplate=%s.html"} + + + text/plain; $EDITOR %s ; + ${lib.optionalString true "text/html; ${openfile} %s ; nametemplate=%s.html"} + text/html; ${pkgs.lynx}/bin/lynx -assume_charset=%{charset} -display_charset=utf-8 -dump %s; nametemplate=%s.html; copiousoutput; + image/*; ${openfile} %s ; + application/pdf; ${openfile} %s ; + # application/pgp-encrypted; gpg -d '%s'; copiousoutput; ''; home.packages = with pkgs; [ |