Logging mbsync Errors

I’ve been using mu4e and mbsync for the last four years and love it. One of the things you discover early in your use of mbsync is that it loves spew messages into the minibuffer. That would be okay except that sometimes it overwrites something that you’re looking at.

A first hack at fixing this is to simply redirect those messages to /dev/null but then you might miss something that requires action so the second try at a fix is to redirect the output to a file. But then you discover that mbsync can emit the same error message on every invocation. For me that began with a message about an illegal message number. I fixed that but now Apple mail, I guess, is sending some flag that mbsync doesn’t know about so I get the error “IMAP warning: unknown system flag Junk”. That happens every time mbsync downloads new email messages so it would quickly fill up the log file.

A third iteration in fixing this is to send the messages to a filter that deletes any messages that you’re not interested in. My simple filter for this is

#! /bin/zsh
read LINE
if [ $LINE != 'IMAP warning: unknown system flag Junk' ]
then
    echo  $(date): \\c
    echo $LINE
fi

Obviously you can easily add additional messages to ignore.

The next problem is that mbsync sends these messages to STDERR instead of STDOUT so you have to figure out someway of piping STDERR to the next process’s STDIN. That turns out to be a bit fussy but the TD;DR is

  1. Redirect STDERR to STDOUT
  2. Disappear STDOUT

Here’s what this looks like for mu4e.

(setq mu4e-get-mail-command "mbsync -q icloud 2>&1 > /dev/null | (~/bin/mbsyncfilter) >> ~/.mbsync.log")

Something similar, I’m sure, would work for notmuch or whatever else you’re using mbsync with.

I get about five to ten error messages a week. They’re mostly things like the system couldn’t resolve the IP address of the Apple mail server or that the server had some problem or another. This solution works really well for me. I check the log file once a week to make sure no action on my part is required. I clear the log at that time so there’s never a huge number of messages to deal with.

This entry was posted in General and tagged , . Bookmark the permalink.