nixos/programs/email.nix

309 lines
12 KiB
Nix
Raw Permalink Normal View History

2024-06-16 10:10:36 +00:00
{ config, lib, pkgs, ... }:
{
accounts.email = {
2024-07-14 09:32:29 +00:00
maildirBasePath = ".mail";
2024-06-16 10:10:36 +00:00
accounts = {
2024-07-14 09:32:29 +00:00
hackerncoder = rec {
2024-06-16 10:10:36 +00:00
primary = true;
2024-07-14 09:32:29 +00:00
address = "hackerncoder@encryptionin.space";
userName = "${address}";
realName = "HackerNCoder";
2024-06-16 10:10:36 +00:00
flavor = "plain";
passwordCommand = "${pkgs.pass}/bin/pass Email/hackerncoder";
smtp = {
2024-07-14 09:32:29 +00:00
host = "mail.encryptionin.space";
2024-06-16 10:10:36 +00:00
port = 465;
tls.enable = true;
};
2024-07-14 09:32:29 +00:00
imap = {
host = "${smtp.host}";
port = 993;
tls.enable = true;
};
2024-06-16 10:10:36 +00:00
mbsync = {
enable = true;
2024-07-14 09:32:29 +00:00
create = "maildir";
2024-06-16 10:10:36 +00:00
expunge = "both";
patterns = [ "*" "!Archive" "!Archives*" ];
2024-06-16 10:10:36 +00:00
};
msmtp.enable = true;
imapnotify = {
2024-07-14 09:32:29 +00:00
enable = true;
2024-06-16 10:10:36 +00:00
boxes = [ "Inbox" ];
2024-07-14 09:32:29 +00:00
onNotify = "${pkgs.libnotify}/bin/notify-send -u normal -i mail-unread -a 'imap-notify' 'New email'";
};
neomutt = {
enable = true;
2024-06-16 10:10:36 +00:00
};
};
};
};
programs = {
msmtp.enable = true;
mbsync.enable = true;
2024-07-14 09:32:29 +00:00
};
programs.neomutt = {
enable = true;
# vimKeys = true;
sidebar = {
enable = true;
width = 20;
format = "%D%?F? [%F]?%* %?N?%N/? %?S?%S?";
};
sort = "threads";
settings = {
mark_old = "no";
text_flowed = "yes";
mime_type_query_command = "\"file --mime-type -b %s\"";
date_format = ''"%y/%m/%d %I:%M%p"'';
index_format=''"%2C %Z %?X?A& ? %D %-15.15F %s (%-4.4c)"'';
mailcap_path = "$HOME/.config/neomutt/mailcap:$mailcap_path";
smtp_authenticators = "'login:plain'";
query_command = ''"abook --mutt-query '%s'"'';
rfc2047_parameters = "yes";
sleep_time = "0"; # Pause 0 seconds for informational messages
markers = "no"; # Disables the `+` displayed at line wraps
mime_forward = "no"; # mail body is forwarded as text
forward_attachments = "yes"; # attachments are forwarded with mail
wait_key = "no"; # mutt won't ask "press key to continue"
fast_reply = "yes"; # skip to compose when replying
fcc_attach = "yes"; # save attachments with the body
forward_format = ''"Fwd: %s"''; # format of subject when forwarding
forward_quote = "yes"; # include message in forwards
include = "yes"; # include message in replies
mail_check = "60"; # to avoid lags using IMAP with some email providers (yahoo for example)
edit_headers = "yes";
sort_aux = "reverse-last-date-received";
};
binds = [
{
map = ["index" "pager"];
key = "i";
action = "noop";
}
{
map = ["index" "pager"];
key = "g";
action = "noop";
}
{
map = ["index" "pager"];
key = "\Cf";
action = "noop";
}
{
map = ["index" "pager"];
key = "M";
action = "noop";
}
{
map = ["index" "pager"];
key = "C";
action = "noop";
}
];
extraConfig =
''
auto_view text/html # automatically show html (mailcap uses lynx)
auto_view application/pgp-encrypted
# General rebindings
bind index gg first-entry
bind index j next-entry
bind index k previous-entry
bind attach <return> view-mailcap
bind attach l view-mailcap
bind editor <space> noop
bind index G last-entry
bind pager,attach h exit
bind pager j next-line
bind pager k previous-line
bind pager l view-attachments
bind index D delete-message
bind index U undelete-message
bind index L limit
bind index h noop
bind index l display-message
bind index,query <space> tag-entry
#bind browser h goto-parent
macro browser h '<change-dir><kill-line>..<enter>' "Go to parent folder"
bind index,pager H view-raw-message
bind browser l select-entry
bind browser gg top-page
bind browser G bottom-page
bind pager gg top
bind pager G bottom
bind index,pager,browser d half-down
bind index,pager,browser u half-up
bind index,pager S sync-mailbox
bind index,pager R group-reply
bind index \031 previous-undeleted # Mouse wheel
bind index \005 next-undeleted # Mouse wheel
bind pager \031 previous-line # Mouse wheel
bind pager \005 next-line # Mouse wheel
bind editor <Tab> complete-query
macro index,pager gi "<change-folder>=INBOX<enter>" "go to inbox"
macro index,pager Mi ";<save-message>=INBOX<enter>" "move mail to inbox"
macro index,pager Ci ";<copy-message>=INBOX<enter>" "copy mail to inbox"
macro index,pager gd "<change-folder>=Drafts<enter>" "go to drafts"
macro index,pager Md ";<save-message>=Drafts<enter>" "move mail to drafts"
macro index,pager Cd ";<copy-message>=Drafts<enter>" "copy mail to drafts"
macro index,pager gj "<change-folder>=Junk<enter>" "go to junk"
macro index,pager Mj ";<save-message>=Junk<enter>" "move mail to junk"
macro index,pager Cj ";<copy-message>=Junk<enter>" "copy mail to junk"
macro index,pager gt "<change-folder>=Trash<enter>" "go to trash"
macro index,pager Mt ";<save-message>=Trash<enter>" "move mail to trash"
macro index,pager Ct ";<copy-message>=Trash<enter>" "copy mail to trash"
macro index,pager gs "<change-folder>=Sent<enter>" "go to sent"
macro index,pager Ms ";<save-message>=Sent<enter>" "move mail to sent"
macro index,pager Cs ";<copy-message>=Sent<enter>" "copy mail to sent"
macro index,pager ga "<change-folder>=Archive<enter>" "go to archive"
macro index,pager Ma ";<save-message>=Archive<enter>" "move mail to archive"
macro index,pager Ca ";<copy-message>=Archive<enter>" "copy mail to archive"
#set crypt_auto_sign = yes
#set crypt_opportunistic_encrypt = yes
#set pgp_self_encrypt = yes
#set pgp_default_key = 'your@gpgemailaddre.ss'
macro index \eg "<enter-command>unset wait_key<enter><shell-escape>gpg --list-secret-keys; printf 'Enter email ID of user to publish: '; read eID; printf 'Enter fingerprint of GPG key to publish: '; read eFGPT; $prefix/libexec/gpg-wks-client --create \\\$eFGPT \\\$eID | msmtp --read-envelope-from --read-recipients -a $fulladdr<enter>" "publish GPG key to WKS provider"
macro index \eh "<pipe-message>$prefix/libexec/gpg-wks-client --receive | msmtp --read-envelope-from --read-recipients -a $fulladdr<enter>" "confirm GPG publication"
macro index,pager a "<enter-command>set my_pipe_decode=\$pipe_decode pipe_decode<return><pipe-message>abook --add-email<return><enter-command>set pipe_decode=\$my_pipe_decode; unset my_pipe_decode<return>" "add the sender address to abook"
macro index \Cr "T~U<enter><tag-prefix><clear-flag>N<untag-pattern>.<enter>" "mark all messages as read"
macro index O "<shell-escape>mailsync<enter>" "run mailsync to sync all mail"
macro index \Cf "<enter-command>unset wait_key<enter><shell-escape>printf 'Enter a search term to find with notmuch: '; read x; echo \$x >~/.cache/mutt_terms<enter><limit>~i \"\`notmuch search --output=messages \$(cat ~/.cache/mutt_terms) | head -n 600 | perl -le '@a=<>;s/\^id:// for@a;$,=\"|\";print@a' | perl -le '@a=<>; chomp@a; s/\\+/\\\\+/ for@a;print@a' \`\"<enter>" "show only messages matching a notmuch pattern"
macro index A "<limit>all\n" "show all messages (undo limit)"
# Sidebar mappings
set mail_check_stats
bind index,pager \Ck sidebar-prev
bind index,pager \Cj sidebar-next
bind index,pager \Co sidebar-open
bind index,pager \Cp sidebar-prev-new
bind index,pager \Cn sidebar-next-new
bind index,pager B sidebar-toggle-visible
# 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"
# Flagged mail is highlighted:
color index brightgreen default "~F"
color index_subject brightgreen default "~F"
color index_author brightgreen default "~F"
# 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 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
# Regex highlighting:
color header brightmagenta default "^From"
color header brightcyan default "^Subject"
color header brightwhite default "^(CC|BCC)"
color header blue default ".*"
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<>\"]"
'';
2024-06-16 10:10:36 +00:00
};
services.mbsync = {
2024-06-19 11:28:03 +00:00
enable = false;
2024-06-16 10:10:36 +00:00
frequency = "0/3:00:00";
preExec = "${pkgs.libnotify}/bin/notify-send -u normal -i view-refresh -a 'mbsync timer' 'Syncing with mbsync'";
postExec = "${pkgs.mu}/bin/mu index";
};
2024-06-19 11:28:03 +00:00
services.imapnotify.enable = false;
2024-06-16 10:10:36 +00:00
2024-07-14 09:32:29 +00:00
xdg.configFile."neomutt/mailcap".text = ''
text/plain; $EDITOR %s ;
text/html; ''${XDG_DATA_HOME}/neomutt/openfile %s ; nametemplate=%s.html
text/html; lynx -assume_charset=%{charset} -display_charset=utf-8 -dump -width=1024 %s; nametemplate=%s.html; copiousoutput;
image/*; ''${XDG_DATA_HOME}/neomutt/openfile %s ;
video/*; setsid mpv --quiet %s &; copiousoutput
audio/*; mpv %s ;
application/pdf; ''${XDG_DATA_HOME}/neomutt/openfile %s ;
application/pgp-encrypted; gpg -d '%s'; copiousoutput;
application/pgp-keys; gpg --import '%s'; copiousoutput;
application/x-subrip; $EDITOR %s ;
'';
xdg.dataFile."neomutt/openfile".text = ''
#!/bin/sh
# Helps open a file with xdg-open from mutt in a external program without weird side effects.
tempdir="''${XDG_CACHE_HOME:-$HOME/.cache}/neomutt/files"
file="$tempdir/''${1##*/}"
[ "$(uname)" = "Darwin" ] && opener="open" || opener="setsid -f xdg-open"
mkdir -p "$tempdir"
cp -f "$1" "$file"
$opener "$file" >/dev/null 2>&1
find "''${tempdir:?}" -mtime +1 -type f -delete
'';
2024-06-16 10:10:36 +00:00
home.packages = with pkgs; [
pass
libnotify
2024-07-14 09:32:29 +00:00
lynx
file
2024-06-16 10:10:36 +00:00
];
}