mutt, mbsync and imapnotify

mbsync

mbsync synchronizes a local maildir with the remote IMAP mail storage.

~/.mbsyncrc

IMAPAccount      gmail
Host             imap.gmail.com
User             someone@gmail.com
PassCmd          "pass show email/gmail.com | head -n1"
SSLType IMAPS

IMAPStore  gmail-remote
Account    gmail

MaildirStore  gmail-local
Path          ~/mail/gmail/
Inbox         ~/mail/gmail/INBOX

Channel   gmail-inbox
Master    :gmail-remote:
Slave     :gmail-local:
Patterns  INBOX

Channel   gmail-sent
Master    :gmail-remote:"[Google Mail]/Gesendet"
Slave     :gmail-local:"sent"
Create    Slave

Group gmail
Channel gmail-inbox
Channel gmail-sent

imapnotify

imapnotify monitors a remote mail storage via IMAP IDLE. If something gets pushed via IDLE, it calls mbsync to sync the local maildir.

~/.config/imapnotify.gmail.js

var child_process = require('child_process');

function getStdout(cmd) {
  var stdout = child_process.execSync(cmd);
  return stdout.toString().trim();
}

exports.host = "imap.gmail.com";
exports.port = 993;
exports.tls = true;
exports.tlsOptions = { "rejectUnauthorized": false };
exports.username = "someone@gmail.com";
exports.password = getStdout("pass show email/gmail.com | head -n1");
exports.onNewMail = "/usr/bin/mbsync gmail";
exports.onNewMailPost = "/usr/bin/notmuch new";
exports.boxes = [ "INBOX" ];

We want to start imapnotify with X.

.xprofile

imapnotify -c ~/.config/imapnotify.gmail.js