complete-computing-environment/mbsync.org

5.4 KiB

mbsync for local mail storage

(provide 'cce/mbsync)
(add-hook #'after-cce-hook (lambda () (cce/async-forever "date && mbsync -a" "*mbsync*" 600)))

I have mixed feelings about using mbsync in my Email and News and Information Pipelines, I've had enough issues with mail integrity that it's useful to have a Python thing that I can muck around inside of with print statements to figure out what what the fuck my Maildir did to itself. I have negative feelings towards the way the project is operated, and the fact that the best documentation of the project is bunch of semi-hostile threads on a Sourceforge forum, and I'm not excited for Master/Slave terminology in a sync program…

But it's fast and works and so I'll try to use it again. I have a tiered architecture for my mail; because of the Universal Aggregator, on my laptops I want to always pull my mail from my central server, and so I have two configurations.

Here's the one for getting things from my server to my laptop. Most folks who set up a personal mail cache will configure Dovecot on the server to listen on a port, and set up authentication and firewalling and bla bla bla. Even if you have a VPN and manage to make sure your IMAP server is only on that VPN, you have to set up a password database or some other sort of authentication strategy, fucken sucks. Instead, I build my security on top of my SSH Configuration1, by establishing an SSH tunnel which executes the built-in imap library executable, which provides a locally-authenticated dovecot session over standard input/output.

{ config, pkgs, ... }:

{
  programs.mbsync.enable = true;
  accounts.email.maildirBasePath = "/home/rrix/Maildir";
  accounts.email.accounts.endpoint = {
    address = "ryan@whatthefuck.computer";
    realName = "Ryan Rix (rrix)";

    aliases = [ "ry@n.rix.si" "rrix@fastmail.com" ];
    userName = "rrix@fastmail.com";

    primary = false; # outbox goes through fastmail smtp

    passwordCommand = "pass show fastmail_email_app";

    imap.host = "fontkeming.fail";
    imap.tls.enable = false;

    mbsync = {
      enable = true;
      subFolders = "Verbatim";
      groups = {
        endpoint = {
          channels = {
            high-priority = {
              extraConfig.Create = "near";
              patterns = [
                "fastmail/INBOX"
                "fastmail/github"
                "fastmail/Sent\\ Mail"
                "fastmail/fedora/bugs"
              ];
            };
            low-priority = {
              extraConfig = {
                MaxMessages = 1000;
                MaxSize = "10m";
                Create = "near";
                ExpireUnread = "no";
              };
              patterns = [
                "fastmail/newsletters"
                "fastmail/social"
                "fastmail/emacsconf"
                "fastmail/phoenix-lug"
                "fastmail/RecruitingSpam"
                "fastmail/Junk Mail"
                "fastmail/1ml"
                "fastmail/1ml/bcz"
                "fastmail/1ml/friendsofsecurityplanner"
              ];
            };
            feeds = {
              patterns = [
                "feeds/Art"
                "feeds/Blogs"
                "feeds/Brain"
                "feeds/Motorsports"
                "feeds/News"
                "feeds/Self"
                "feeds/Software"
                "feeds/Tea"
                "feeds/Tech"
                "feeds/Videos"
                "feeds/Longreads"
              ];
              extraConfig = {
                MaxSize = "10m";
                Create = "near";
                ExpireUnread = "no";
              };
            };
            work = {
              patterns = [
                "crdigital/INBOX"
                "crdigital/[Gmail]/Sent Mail"
              ];
              extraConfig = {
                MaxMessages = 1000;
                MaxSize = "10m";
                Create = "near";
                ExpireUnread = "no";
              };
            };
          };
        };
      };
      extraConfig = {
        account = {
          Timeout = 120;
          Tunnel = "ssh -q fontkeming /usr/libexec/dovecot/imap";
        };
      };
    };
  };
}

The last time I used mbsync, I experienced issues with mail IDs in my newsrc.eld file, which Gnus uses to store which lists I am subscribed too, and also functions as a cache for message and folder states. The latter caching was what caused these issues, I believe, but it was really difficult to debug it. If this happens again, I may switch to offlineimap.


1

(admittedly, my SSH configuration should be refreshed)