summaryrefslogtreecommitdiff
path: root/home/mail/default.nix
blob: febd75f2ff19913eb91e942bc404c8cdbf66eb33 (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
{ config, lib, pkgs, ... }:
with lib; {
  options.local.mail = with types; {
    address = mkOption {
      type = str;
    };

    realName = mkOption {
      type = str;
    };

    sieve.enable = mkEnableOption "sieve filter";
  };

  config = mkIf (!config.home.isolation.active) {
    accounts.email = {
      maildirBasePath = "mail";

      accounts = {
        google = {
          address = "alejandrosotochacon@gmail.com";
          userName = "alejandrosotochacon"; # Ver salida de: msmtp --configure alejandrosotochacon@gmail.com
          inherit (config.local.mail) realName;

          maildir = null;

          msmtp.enable = true;

          passwordCommand = "pass show `hostname -s`/psk/gmail";

          smtp = {
            host = "smtp.gmail.com";

            tls = {
              enable = true;
              useStartTls = true;
            };
          };
        };

        local = {
          address = "${config.local.mail.address}@34project.org";
          userName = "${config.local.mail.address}@34project.org";
          inherit (config.local.mail) realName;

          primary = true;

          # ${maildirBasePath}/${maildir.path}
          maildir.path = "";
          folders.inbox = "";

          msmtp.enable = true;
          neomutt.enable = true;

          imap = {
            host = "badhost";

            tls = {
              enable = false;
              useStartTls = false;
            };
          };

          smtp = {
            host = "smtp.34project.org";

            tls = {
              enable = true;
              useStartTls = true;
            };
          };
        };
      };
    };

    programs = {
      msmtp.enable = true;

      neomutt = {
        enable = true;
        vimKeys = true;

        settings = {
          record = "+.sent";
          postponed = "+.drafts";

          use_threads = "flat";
          index_format = "'%4C %Z %<[y?%<[m?%<[d?%[%H:%M ]&%[%a %d]>&%[%b %d]>&%[%m/%y ]> %-15.15L (%?l?%4l&%4c?) %s'";
        };

        extraConfig = ''
          auto_view text/html
          alternative_order text/plain text/enriched text/html

          reply-hook '~t ^alejandrosotochacon@gmail\.com$' 'my_hdr From: Alejandro Soto <alejandrosotochacon@gmail.com>'
          macro compose '\3' "<edit-from><kill-line>Alejandro Soto \<alejandro@34project.org\><enter>"
          macro compose '\g' "<edit-from><kill-line>Alejandro Soto \<alejandrosotochacon@gmail.com\><enter>"
        '';
      };
    };

    home = mkMerge
      [
        ({
          file.".mailcap".text = ''
            text/html; ${pkgs.luakit}/bin/luakit '%s' &; test=test -n "$DISPLAY"; needsterminal;
            text/html; ${pkgs.lynx}/bin/lynx -dump %s; nametemplate=%s.html; copiousoutput;
          '';
        })

        # .dovecot.sieve tiene que ser un symlink tal que el readlink -f de su
        # dirname (no del symlink en sí) sea la misma cadena que el readlink -f
        # de ~/sieve. Dovecot verifica eso y tira "Invalid/unknown path to
        # storage" si este check frágil falla. Ni siquiera
        # mkOutOfStoreSymlink funciona. Ver código fuente de Dovecot:
        # pigeonhole/src/lib-sieve/storage/file/sieve-file-storage-active.c
        (
          let
            sieve = pkgs.runCommandNoCCLocal "sieve" { src = ./sieve; } ''
              cp -r $src $out
              chmod -R u+w $out
              find $out -name '*.sieve' -exec ${pkgs.dovecot_pigeonhole}/bin/sievec -c /dev/null {} \;
            '';
          in
          mkIf config.local.mail.sieve.enable {
            file."sieve".source = sieve;

            activation.sieve = hm.dag.entryBetween [ "linkGeneration" ] [ "writeBoundary" ] ''
              $DRY_RUN_CMD ln -Tsf ${sieve}/mail.sieve .dovecot.sieve
              $DRY_RUN_CMD ln -Tsf ${sieve}/mail.svbin .dovecot.svbin
            '';
          }
        )
      ];
  };
}