{
  config,
  pkgs,
  inputs,
  ...
}: let
  unstable = inputs.nixpkgs-nixos-unstable.legacyPackages.${pkgs.system};
in {
  home-manager.users.cyryl = {
    accounts.email.accounts.cyplo = {
      primary = true;
      address = "cyplo@cyplo.dev";
      aliases = ["cyplo@cyplo.net"];
      realName = "Cyryl PÅ‚otnicki";
      userName = "cyplo@cyplo.dev";
      imap = {
        host = "127.0.0.1";
        port = 1143;
        tls = {
          enable = true;
          useStartTls = true;
          certificatesFile = "/home/cyryl/.config/protonmail/bridge/cert.pem";
        };
      };
      smtp = {
        host = "127.0.0.1";
        port = 1025;
        tls = {
          enable = true;
          useStartTls = true;
          certificatesFile = "/home/cyryl/.config/protonmail/bridge/cert.pem";
        };
      };
      mbsync = {
        enable = true;
        create = "maildir";
        expunge = "maildir";
        remove = "maildir";
      };
      msmtp = {
        enable = true;
        extraConfig = {
          from = "cyplo@cyplo.dev";
          auth = "plain";
        };
      };
      notmuch.enable = true;
      neomutt.enable = true;
      passwordCommand = "${pkgs.pass}/bin/pass proton-bridge";
      folders = {
        drafts = "Drafts";
        inbox = "INBOX";
        sent = "Sent";
        trash = "Trash";
      };
    };

    programs = {
      mbsync.enable = true;
      msmtp.enable = true;
      neomutt = {enable = true;};
      notmuch = {
        enable = true;
        hooks.preNew = "${pkgs.isync}/bin/mbsync -a";
      };
    };
    home.packages = [unstable.protonmail-bridge];

    services.mbsync.enable = true;

    home.file.".mailcap".text = ''
      text/html;  ${pkgs.w3m}/bin/w3m -dump -o document_charset=%{charset} '%s'; nametemplate=%s.html; copiousoutput
    '';

    systemd.user.services."proton-bridge" = {
      Unit.Description = "Bridge to ProtonMail";
      Install.WantedBy = ["default.target" "mbsync.service"];
      Service.ExecStart = "${unstable.protonmail-bridge}/bin/protonmail-bridge --noninteractive";
      Service.Environment = "PATH=${pkgs.pass}/bin:${pkgs.gnupg}/bin";
    };
  };
}