summaryrefslogtreecommitdiff
path: root/nix_archive/nix/email.nix
blob: 8320d88ff4984d210bdce77616e02eeb3cd8852f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
{ config, pkgs, ... }: {
  environment.systemPackages = with pkgs; [ lynx urlscan ];
  home-manager.users.andrew = let
    homeDir = "${config.users.users.andrew.home}";
  in {
    accounts.email.maildirBasePath = "mail";
    accounts.email.accounts."andrew" = {
      address = "andrew@akon.city";
      realName = "Andrew Opalach";
      userName = "andrew@akon.city";
      maildir.path = "";
      primary = true;
      passwordCommand = "${pkgs.pass}/bin/pass andrew@akon.city";
      folders.inbox = "INBOX";
      imap = {
        host = "mail.akon.city";
        port = 993;
        tls.enable = true;
      };
      smtp = {
        host = "mail.akon.city";
        port = 465;
        tls.enable = true;
      };
      mbsync = {
        enable = true;
        create = "maildir";
      };
      msmtp.enable = true;
      imapnotify = {
        enable = true;
        boxes = [ "INBOX" ];
        onNotify = "${pkgs.notmuch}/bin/notmuch new";
        onNotifyPost = "${pkgs.libnotify}/bin/notify-send '📥 New Mail!'";
      };
      notmuch = {
        enable = true;
        neomutt = {
          enable = true;
          virtualMailboxes = [
            { name = "INBOX"; query = "folder:INBOX"; }
            { name = "Sent"; query = "folder:Sent"; }
            { name = "Archive"; query = "folder:Archive"; }
            { name = "Drafts"; query = "folder:Drafts"; }
            { name = "Trash"; query = "folder:Trash"; }
            { name = "Junk"; query = "folder:Junk"; }
          ];
        };
      };
      neomutt.enable = true;
    };
    programs.mbsync.enable = true;
    services.mbsync.enable = true;
    programs.msmtp.enable = true;
    services.imapnotify.enable = true;
    programs.notmuch = {
      enable = true;
      hooks = {
        preNew = "${pkgs.notmuch}/bin/notmuch search --output=files --format=text0 tag:deleted | xargs -0 rm -f; ${pkgs.isync}/bin/mbsync --all -ngfuX";
      };
    };
    programs.neomutt = {
      enable = true;
      vimKeys = false;
      sidebar = {
        enable = true;
        width = 18;
        shortPath = true;
      };
      sort = "reverse-date";
      binds = [
        { key = "i"; action = "noop"; map = [ "index" "pager" ]; }
        { key = "g"; action = "noop"; map = [ "index" "pager" ]; }
        { key = "gg"; action = "first-entry"; map = [ "index" ]; }
        { key = "j"; action = "next-entry"; map = [ "index" ]; }
        { key = "k"; action = "previous-entry"; map = [ "index" ]; }
        { key = "G"; action = "last-entry"; map = [ "index" ]; }
        { key = "<Return>"; action = "view-mailcap"; map = [ "attach" ]; }
        { key = "l"; action = "view-mailcap"; map = [ "attach" ]; }
        { key = "<space>"; action = "noop"; map = [ "editor" ]; }
        { key = "j"; action = "next-line"; map = [ "pager" ]; }
        { key = "k"; action = "previous-line"; map = [ "pager" ]; }
        { key = "gg"; action = "top"; map = [ "pager" ]; }
        { key = "G"; action = "bottom"; map = [ "pager" ]; }
        { key = "l"; action = "view-attachments"; map = [ "pager" ]; }
        { key = "h"; action = "noop"; map = [ "index" ]; }
        { key = "h"; action = "exit"; map = [ "pager" "attach" ]; }
        { 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 = "<Tab>"; action = "complete-query"; map = [ "editor" ]; }
        { key = "l"; action = "select-entry"; map = [ "browser" ]; }
        { key = "gg"; action = "top-page"; map = [ "browser" ]; }
        { key = "G"; action = "bottom-page"; map = [ "browser" ]; }
        { key = "H"; action = "view-raw-message"; map = [ "index" "pager" ]; }
      ];
      macros = let
        delete-macro = "<modify-labels>+deleted<enter>";
        undelete-macro = "<modify-labels>-deleted<enter>";
      in [
        { key = "\\Cb"; action = "<pipe-message>${pkgs.urlscan}/bin/urlscan -cW<enter>"; map = [ "index" "pager" ]; }
        { key = "\\Cb"; action = "<pipe-entry>${pkgs.urlscan}/bin/urlscan -cW<enter>"; map = [ "attach" "compose" ]; }
        { key = "h"; action = "<change-dir><kill-line>..<enter>"; map = [ "browser" ]; }
        { key = "o"; action = "<shell-escape>${pkgs.notmuch}/bin/notmuch new<enter><sync-mailbox>"; map = [ "index" ]; }
        { key = "\\Cd"; action = delete-macro; map = [ "index" ]; }
        { key = "\\Cu"; action = undelete-macro; map = [ "index" ]; }
      ];
      extraConfig = ''
        unmailboxes ${homeDir}/mail/INBOX
        set mail_check_stats = yes
        set delete = ask-yes

        # https://github.com/LukeSmithxyz/mutt-wizard/blob/10a16e0ee6442425e7ca1634b1d3356e6d4d04f6/share/mutt-wizard.muttrc#L14
        set rfc2047_parameters = yes
        set sleep_time = 0
        set markers = no
        set wait_key = no
        set reverse_name
        set fast_reply
        set fcc_attach
        set mime_forward = no
        set forward_attachments = yes
        set forward_format = "Fwd: %s"
        set forward_quote

        set index_format="%2C (%Z) %[%D %I:%M %p] %-15.15F %s (%c, %g)"

        auto_view text/html
        auto_view application/pgp-encrypted
        alternative_order text/plain text/enriched text/html

        color normal blue black
        color attachment brightyellow black
        color hdrdefault blue black
        color indicator black blue
        color markers brightred black
        color quoted green black
        color signature blue black
        color status black red
        color tilde blue black
        color tree red black

        color index red black ~D
        color index magenta black ~T

        color header brightgreen black ^From:
        color header brightblue black ^To:
        color header brightblue black ^Reply-To:
        color header brightblue black ^Cc:
        color header brightblue black ^Subject:

        color body brightred black [\-\.+_a-zA-Z0-9]+@[\-\.a-zA-Z0-9]+
        color body brightblue black (https?|ftp)://[\-\.,/%~_:?&=\#a-zA-Z0-9]+
      '';
    };
    home.file.".mailcap".source = ../../files/mailcap;
  };
}