nix-config/modules/home-manager/mail/default.nix

509 lines
15 KiB
Nix

{ config, pkgs, ... }:
let
mailsync = pkgs.callPackage ./mailsync.nix { inherit config pkgs; };
gpgKey = "B51D4548A4846E3C8D115C808333CFB0B9D3244D";
personalSignature = ''
Ricard Illa
https://monotremata.xyz
public key fingerprint: 2E0A7CADFF84D08BA94273AA101F79336E07C850
'';
accountSignature = { showSignature ? "append", text ? "" }: {
showSignature = showSignature;
text = text;
};
pwCmd = x: "${pkgs.pass}/bin/pass ${x}";
defaultAccountSettings =
{ accountEmail
, mailboxes ? ''"=Inbox" "=Archive" "=Drafts" "=Junk" "=Sent" "=Trash"''
, smtpHost ? "mail.monotremata.xyz"
, imapHost ? "mail.monotremata.xyz"
}: {
primary = false;
realName = "Ricard Illa";
aliases = [ ];
address = accountEmail;
userName = accountEmail;
neomutt = {
enable = true;
extraConfig = ''
unmailboxes *
mailboxes ${mailboxes}
set status_format = "[ ${accountEmail} ] [ %f ] [%r%m messages%?n? (%n new)?%?d? (%d to delete)?%?t? (%t tagged)? ]%>%?p?( %p postponed )?"
'';
sendMailCommand = "msmtp -a ${accountEmail}";
};
signature = accountSignature { text = personalSignature; };
mbsync = {
enable = true;
create = "both";
expunge = "both";
flatten = ".";
patterns = [ "*" ];
remove = "both";
};
gpg = {
encryptByDefault = false;
signByDefault = true;
key = gpgKey;
};
msmtp.enable = true;
smtp = {
host = smtpHost;
tls = {
enable = true;
useStartTls = true;
};
port = 587;
};
imap = {
host = imapHost;
tls.enable = true;
port = 993;
};
notmuch.enable = true;
};
switchAccountMacro = i: x: {
map = [ "index" "pager" ];
key = "i${i}";
action =
"<enter-command>source ${config.xdg.configHome}/neomutt/${x}<enter><change-folder>!<enter><check-stats>";
};
in
{
home.packages = [ mailsync pkgs.urlscan pkgs.abook ];
accounts.email.accounts = {
"rilla@monotremata.xyz" =
defaultAccountSettings { accountEmail = "rilla@monotremata.xyz"; } // {
primary = true;
passwordCommand = pwCmd "mail.monotremata.xyz/rilla@monotremata.xyz";
};
"r.illa.pujagut@gmail.com" = defaultAccountSettings
{
accountEmail = "r.illa.pujagut@gmail.com";
mailboxes = ''
"=INBOX" "=[Gmail].Drafts" "=[Gmail].Sent Mail" "=[Gmail].Trash" "=[Gmail].Spam" "=[Gmail].All Mail"'';
smtpHost = "smtp.gmail.com";
imapHost = "imap.gmail.com";
} // {
passwordCommand = pwCmd "google.com/mutt/r.illa.pujagut@gmail.com";
};
"accounts@monotremata.xyz" =
defaultAccountSettings { accountEmail = "accounts@monotremata.xyz"; } // {
realName = "monotremata.xyz";
signature = accountSignature { showSignature = "none"; };
passwordCommand = pwCmd "mail.monotremata.xyz/accounts@monotremata.xyz";
};
"admin@monotremata.xyz" =
defaultAccountSettings { accountEmail = "admin@monotremata.xyz"; } // {
aliases = [
"postmaster@monotremata.xyz"
"hostmaster@monotremata.xyz"
"webmaster@monotremata.xyz"
"abuse@monotremata.xyz"
];
realName = "monotremata.xyz";
signature = accountSignature { text = "admin@monotremata.xyz"; };
passwordCommand = pwCmd "mail.monotremata.xyz/admin@monotremata.xyz";
};
};
programs.neomutt = {
enable = true;
editor = "nvim";
sort = "threads";
# vimKeys = true;
sidebar = {
enable = true;
shortPath = true;
width = 20;
format = "%D%?F? [%F]?%* %?N?%N/? %?S?%S?";
};
extraConfig = ''
alternative_order text/html text/plain text/enriched text/*
auto_view text/html application/gpg-encrypted text/calendar application/ics
# Default index colors:
color index yellow default '.*'
color index_author red default '.*'
color index_number blue default
color index_subject cyan default '.*'
# New mail is boldened:
color index brightyellow black "~N"
color index_author brightred black "~N"
color index_subject brightcyan black "~N"
# Tagged mail is highlighted:
color index brightyellow blue "~T"
color index_author brightred blue "~T"
color index_subject brightcyan blue "~T"
# Other colors and aesthetic settings:
mono bold bold
mono underline underline
mono indicator reverse
mono error bold
color normal default default
color indicator brightblack white
color sidebar_highlight red default
color sidebar_divider brightblack black
color sidebar_flagged red black
color sidebar_new green black
color normal brightyellow default
color error red default
color tilde black default
color message cyan default
color markers red white
color attachment white default
color search brightmagenta default
color status brightyellow black
color hdrdefault brightgreen default
color quoted green default
color quoted1 blue default
color quoted2 cyan default
color quoted3 yellow default
color quoted4 red default
color quoted5 brightred default
color signature brightgreen default
color bold black default
color underline black default
color normal default default
# Regex highlighting:
color header blue default ".*"
color header brightmagenta default "^(From)"
color header brightcyan default "^(Subject)"
color header brightwhite default "^(CC|BCC)"
color body brightred default "[\-\.+_a-zA-Z0-9]+@[\-\.a-zA-Z0-9]+" # Email addresses
color body brightblue default "(https?|ftp)://[\-\.,/%~_:?&=\#a-zA-Z0-9]+" # URL
color body green default "\`[^\`]*\`" # Green text between ` and `
color body brightblue default "^# \.*" # Headings as bold blue
color body brightcyan default "^## \.*" # Subheadings as bold cyan
color body brightgreen default "^### \.*" # Subsubheadings as bold green
color body yellow default "^(\t| )*(-|\\*) \.*" # List items as yellow
color body brightcyan default "[;:][-o][)/(|]" # emoticons
color body brightcyan default "[;:][)(|]" # emoticons
color body brightcyan default "[ ][*][^*]*[*][ ]?" # more emoticon?
color body brightcyan default "[ ]?[*][^*]*[*][ ]" # more emoticon?
color body red default "(BAD signature)"
color body cyan default "(Good signature)"
color body brightblack default "^gpg: Good signature .*"
color body brightyellow default "^gpg: "
color body brightyellow red "^gpg: BAD signature from.*"
mono body bold "^gpg: Good signature"
mono body bold "^gpg: BAD signature from.*"
color body red default "([a-z][a-z0-9+-]*://(((([a-z0-9_.!~*'();:&=+$,-]|%[0-9a-f][0-9a-f])*@)?((([a-z0-9]([a-z0-9-]*[a-z0-9])?)\\.)*([a-z]([a-z0-9-]*[a-z0-9])?)\\.?|[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+)(:[0-9]+)?)|([a-z0-9_.!~*'()$,;:@&=+-]|%[0-9a-f][0-9a-f])+)(/([a-z0-9_.!~*'():@&=+$,-]|%[0-9a-f][0-9a-f])*(;([a-z0-9_.!~*'():@&=+$,-]|%[0-9a-f][0-9a-f])*)*(/([a-z0-9_.!~*'():@&=+$,-]|%[0-9a-f][0-9a-f])*(;([a-z0-9_.!~*'():@&=+$,-]|%[0-9a-f][0-9a-f])*)*)*)?(\\?([a-z0-9_.!~*'();/?:@&=+$,-]|%[0-9a-f][0-9a-f])*)?(#([a-z0-9_.!~*'();/?:@&=+$,-]|%[0-9a-f][0-9a-f])*)?|(www|ftp)\\.(([a-z0-9]([a-z0-9-]*[a-z0-9])?)\\.)*([a-z]([a-z0-9-]*[a-z0-9])?)\\.?(:[0-9]+)?(/([-a-z0-9_.!~*'():@&=+$,]|%[0-9a-f][0-9a-f])*(;([-a-z0-9_.!~*'():@&=+$,]|%[0-9a-f][0-9a-f])*)*(/([-a-z0-9_.!~*'():@&=+$,]|%[0-9a-f][0-9a-f])*(;([-a-z0-9_.!~*'():@&=+$,]|%[0-9a-f][0-9a-f])*)*)*)?(\\?([-a-z0-9_.!~*'();/?:@&=+$,]|%[0-9a-f][0-9a-f])*)?(#([-a-z0-9_.!~*'();/?:@&=+$,]|%[0-9a-f][0-9a-f])*)?)[^].,:;!)? \t\r\n<>\"]"
set fast_reply # skip to compose when replying
set fcc_attach # save attachments with the body
set forward_quote # include message in forwards
set reverse_name # reply as whomever it was to
set include # include message in replies
set uncollapse_jump
set sort_re
set quit
set beep_new
'';
settings = {
# set mailcap_path = /usr/local/share/mutt-wizard/mailcap:$mailcap_path # todo
mime_type_query_command = ''"${pkgs.file}/bin/file --mime-type -b %s"'';
date_format = ''"%d.%m.%Y %H:%M"'';
index_format = ''"%2C %Z %?X?A& ? %D %-15.15F %s (%-4.4c)"'';
rfc2047_parameters = "yes";
sleep_time = "0"; # Pause 0 seconds for informational messages
markers = "no"; # Disables the `+` displayed at line wraps
mark_old = "no"; # Unread mail stay unread until read
mime_forward = "yes"; # attachments are forwarded with mail
wait_key = "no"; # mutt won't ask "press key to continue"
forward_format = ''"Fwd: %s"''; # format of subject when forwarding
status_chars = ''" *%A"'';
sort_aux = "reverse-last-date-received";
reply_regexp = ''"^(([Rr][Ee]?(\[[0-9]+\])?: *)?(\[[^]]+\] *)?)*"'';
quote_regexp = ''"^( {0,4}[>|:#%]| {0,4}[a-z0-9]+[>|]+)+"'';
send_charset = "utf-8:iso-8859-1:us-ascii";
charset = "utf-8";
arrow_cursor = "no"; # Change `color indicator` depending
query_command = ''"${pkgs.abook}/bin/abook --mutt-query '%s'"'';
};
binds = [
{
map = [ "index" ];
key = "h";
action = "noop";
}
{
map = [ "index" ];
key = "\\Cf";
action = "noop";
}
{
map = [ "pager" ];
key = "r";
action = "noop";
}
{
map = [ "editor" ];
key = "<space>";
action = "noop";
}
{
map = [ "index" "pager" ];
key = "i";
action = "noop";
}
{
map = [ "index" "pager" ];
key = "g";
action = "noop";
}
# general rebindings
{
map = [ "index" ];
key = "j";
action = "next-entry";
}
{
map = [ "index" ];
key = "k";
action = "previous-entry";
}
{
map = [ "index" ];
key = "G";
action = "last-entry";
}
{
map = [ "index" ];
key = "gg";
action = "first-entry";
}
{
map = [ "index" ];
key = "D";
action = "delete-message";
}
{
map = [ "index" ];
key = "U";
action = "undelete-message";
}
{
map = [ "index" ];
key = "L";
action = "limit";
}
{
map = [ "index" ];
key = "l";
action = "display-message";
}
{
map = [ "index" ];
key = "\\031";
action = "previous-undeleted";
} # Mouse wheel
{
map = [ "index" ];
key = "\\005";
action = "next-undeleted";
} # Mouse wheel
{
map = [ "attach" ];
key = "<return>";
action = "view-mailcap";
}
{
map = [ "attach" ];
key = "l";
action = "view-mailcap";
}
{
map = [ "pager" ];
key = "j";
action = "next-line";
}
{
map = [ "pager" ];
key = "k";
action = "previous-line";
}
{
map = [ "pager" ];
key = "l";
action = "view-attachments";
}
{
map = [ "pager" ];
key = "\\031";
action = "previous-line";
} # Mouse wheel
{
map = [ "pager" ];
key = "\\005";
action = "next-line";
} # Mouse wheel
{
map = [ "editor" ];
key = "<Tab>";
action = "complete-query";
}
{
map = [ "browser" ];
key = "l";
action = "select-entry";
}
{
map = [ "index" "pager" ];
key = "H";
action = "view-raw-message";
}
{
map = [ "index" "pager" ];
key = "S";
action = "sync-mailbox";
}
{
map = [ "index" "pager" ];
key = "R";
action = "group-reply";
}
{
map = [ "index" "pager" ];
key = "rg";
action = "group-reply";
}
{
map = [ "index" "pager" ];
key = "rr";
action = "reply";
}
{
map = [ "index" "query" ];
key = "<space>";
action = "tag-entry";
}
{
map = [ "pager" "browser" ];
key = "gg";
action = "top-page";
}
{
map = [ "pager" "browser" ];
key = "G";
action = "bottom-page";
}
{
map = [ "pager" "attach" ];
key = "h";
action = "exit";
}
{
map = [ "index" "pager" "browser" ];
key = "d";
action = "half-down";
}
{
map = [ "index" "pager" "browser" ];
key = "u";
action = "half-up";
}
# sidebar mappings
{
map = [ "index" "pager" ];
key = "\\Ck";
action = "sidebar-prev";
}
{
map = [ "index" "pager" ];
key = "\\Cj";
action = "sidebar-next";
}
{
map = [ "index" "pager" ];
key = "\\Co";
action = "sidebar-open";
}
{
map = [ "index" "pager" ];
key = "\\Cp";
action = "sidebar-prev-new";
}
{
map = [ "index" "pager" ];
key = "\\Cn";
action = "sidebar-next-new";
}
{
map = [ "index" "pager" ];
key = "B";
action = "sidebar-toggle-visible";
}
];
macros = [
{
map = [ "browser" ];
key = "h";
action = "<change-dir><kill-line>..<enter>";
} # go to parent folder
{
map = [ "index" ];
key = "\\Cr";
action = "T~U<enter><tag-prefix><clear-flag>N<untag-pattern>.<enter>";
} # mark all messages as read
{
map = [ "index" ];
key = "A";
action = "<limit>all\\n";
} # show all messages (undo limit)
{
map = [ "index" "pager" ];
key = "\\cb";
action = "<pipe-message> ${pkgs.urlscan}/bin/urlscan<Enter>";
} # call urlscan to extract URLs out of a message"
{
map = [ "attach" "compose" ];
key = "\\cb";
action = "<pipe-entry> ${pkgs.urlscan}/bin/urlscan<Enter>";
} # call urlscan to extract URLs out of a message
{
map = [ "index" "pager" ];
key = "A";
action = "<pipe-message>${pkgs.khard}/bin/khard add-email<return>";
} # add the sender email address to khard
] ++ [
(switchAccountMacro "1" "rilla@monotremata.xyz")
(switchAccountMacro "2" "r.illa.pujagut@gmail.com")
(switchAccountMacro "4" "accounts@monotremata.xyz")
(switchAccountMacro "5" "admin@monotremata.xyz")
];
};
programs.notmuch = {
enable = true;
new = { tags = [ "unread" "inbox" ]; };
};
programs.mbsync.enable = true;
programs.msmtp.enable = true;
programs.alot.enable = true;
}