{ config, core, registries, store, user, ... } @ libs:
  let
    inherit(core) bool path set;
    accounts                            =   set.map registerAccount mailAccounts;
    mailAccounts                        =   path.import ./mailAccounts.nix libs;

    maildirBasePath                     =   "E-Mails";
    registerAccount
    =   name:
        attrs:
        {
          address                       =   attrs.address or name;
          aliases                       =   attrs.aliases or  [ ];
          folders
          =   {
                drafts                  =   "Drafts";
                inbox                   =   "INBOX";
                sent                    =   "Sent";
                trash                   =   "Trash";
              };
          gpg                           =   attrs.gpg or null;
          imap.host                     =   attrs.imapHost or attrs.host;
          mbsync
          =   {
                enable                  =   true;
                create                  =   "both";
                patterns                =   attrs.patterns or [ "*" ];
              };
          neomutt
          =   {
                enable                  =   true;
                extraConfig
                =   let
                      signature
                      =   bool.select
                            (attrs.signature or null != null)
                            (path.toFile "signature.txt" attrs.signature)
                            "\"fortune |\"";
                    in
                      ''
                        unmailboxes *
                        mailboxes   `find ${maildirBasePath}/${name} -maxdepth 1 -mindepth 1 -printf "=\"%P\" "`
                        set sidebar_sort_method = path
                        set signature = ${signature}
                      '';
              };
          passwordCommand
          =   let
                kinit                   =   attrs.kinit or "";
                passwordCommand
                =   store.write.shellScript "passwordCommand"
                    ''
                      if [ $# -gt 1 ]
                      then
                        ${registries.nix.pass}/bin/pass "Communication/E-Mail/$2" | ${registries.nix.krb5}/bin/kinit "$1"
                        shift 1
                      fi

                      ${registries.nix.pass}/bin/pass "Communication/E-Mail/$1"
                    '';
              in
                "sh ${passwordCommand} ${kinit} ${name}";
          primary                       =   attrs.primary   or  false;
          realName                      =   attrs.real      or  user.realName;
          smtp.host                     =   attrs.smtpHost  or  attrs.host;
          userName                      =   attrs.user      or  name;
        };
  in
  {
    inherit accounts maildirBasePath;
  }
