{ config, pkgs, lib, ... }: { options.mail.aerc.enable = lib.mkEnableOption "Aerc email."; config = lib.mkIf config.mail.aerc.enable { home-manager.users.${config.user} = { home.packages = with pkgs; [ w3m # Render HTML dante # Socksify for rendering HTML ]; programs.aerc = { enable = true; extraBinds = { # Binds are of the form = # To use '=' in a key sequence, substitute it with "Eq": "" # If you wish to bind #, you can wrap the key sequence in quotes: "#" = quit global = { "" = ":prev-tab"; "" = ":next-tab "; "" = ":term"; "?" = ":help keys"; }; messages = { q = ":quit"; j = ":next "; "" = ":next"; "" = ":next 50%"; "" = ":next 100%"; "" = ":next 100%"; k = ":prev "; "" = ":prev"; "" = ":prev 50%"; "" = ":prev 100%"; "" = ":prev 100%"; g = ":select 0 "; G = ":select -1"; J = ":next-folder "; K = ":prev-folder"; H = ":collapse-folder"; L = ":expand-folder"; v = ":mark -t"; V = ":mark -v"; T = ":toggle-threads"; "" = ":view"; d = ":prompt 'Really delete this message?' 'delete-message'"; D = ":move Trash"; A = ":archive flat"; C = ":compose"; rr = ":reply -a"; rq = ":reply -aq"; Rr = ":reply"; Rq = ":reply -q"; c = ":cf"; "$" = ":term"; "!" = ":term"; "|" = ":pipe"; "/" = ":search-a"; "\\" = ":filter "; n = ":next-result"; N = ":prev-result"; "" = ":clear"; }; "messages:folder=Drafts" = { "" = ":recall"; }; view = { "/" = ":toggle-key-passthrough /"; q = ":close"; O = ":open"; S = ":save"; "|" = ":pipe"; D = ":move Trash"; A = ":archive flat"; "" = ":open-link "; f = ":forward "; rr = ":reply -a"; rq = ":reply -aq"; Rr = ":reply"; Rq = ":reply -q"; H = ":toggle-headers"; "" = ":prev-part"; "" = ":next-part"; J = ":next "; K = ":prev"; }; "view::passthrough" = { "$noinherit" = "true"; "$ex" = ""; "" = ":toggle-key-passthrough"; }; compose = { # Keybindings used when the embedded terminal is not selected in the compose # view "$noinherit" = "true"; "$ex" = ""; "" = ":prev-field"; "" = ":next-field"; "" = ":switch-account -p"; "" = ":switch-account -n"; "" = ":next-field"; "" = ":prev-tab"; "" = ":next-tab"; }; "compose::editor" = { # Keybindings used when the embedded terminal is selected in the compose view "$noinherit" = "true"; "$ex" = ""; "" = ":prev-field"; "" = ":next-field"; "" = ":prev-tab"; "" = ":next-tab"; }; "compose::review" = { # Keybindings used when reviewing a message to be sent y = ":send "; n = ":abort"; p = ":postpone"; q = ":choose -o d discard abort -o p postpone postpone"; e = ":edit"; a = ":attach"; d = ":detach"; }; terminal = { "$noinherit" = "true"; "$ex" = ""; "" = ":prev-tab"; "" = ":next-tab"; }; }; extraConfig = { general = { unsafe-accounts-conf = true; # log-file = "~/.cache/aerc.log"; # log-level = "debug"; }; viewer = { pager = "${pkgs.less}/bin/less -R"; }; filters = { "text/plain" = "${pkgs.aerc}/libexec/aerc/filters/colorize"; "text/calendar" = "${pkgs.gawk}/bin/awk -f ${pkgs.aerc}/libexec/aerc/filters/calendar"; "text/html" = "${pkgs.aerc}/libexec/aerc/filters/html | ${pkgs.aerc}/libexec/aerc/filters/colorize"; # Requires w3m, dante # "text/*" = # ''${pkgs.bat}/bin/bat -fP --file-name="$AERC_FILENAME "''; "message/delivery-status" = "${pkgs.aerc}/libexec/aerc/filters/colorize"; "message/rfc822" = "${pkgs.aerc}/libexec/aerc/filters/colorize"; "application/x-sh" = "${pkgs.bat}/bin/bat -fP -l sh"; "application/pdf" = "${pkgs.zathura}/bin/zathura -"; "audio/*" = "${pkgs.mpv}/bin/mpv -"; "image/*" = "${pkgs.feh}/bin/feh -"; }; }; }; accounts.email.accounts.home.aerc = { enable = true; extraAccounts = { check-mail = "5m"; check-mail-cmd = "${pkgs.isync}/bin/mbsync -a"; check-mail-timeout = "15s"; }; }; xdg.desktopEntries.aerc = lib.mkIf (pkgs.stdenv.isLinux && config.gui.enable) { name = "aerc"; exec = "${config.terminalLaunchCommand} aerc %u"; }; xsession.windowManager.i3.config.keybindings = lib.mkIf pkgs.stdenv.isLinux { "${config.home-manager.users.${config.user}.xsession.windowManager.i3.config.modifier}+Shift+e" = "exec ${ # Don't name the script `aerc` or it will affect grep builtins.toString ( pkgs.writeShellScript "focus-mail.sh" '' count=$(ps aux | grep -c aerc) if [ "$count" -eq 1 ]; then i3-msg "exec --no-startup-id ${config.terminal} start --class aerc -- aerc" sleep 0.25 fi i3-msg "[class=aerc] focus" '' ) }"; }; programs.fish.shellAbbrs = { ae = "aerc"; }; }; }; }