{"id":9856,"date":"2021-07-25T12:33:33","date_gmt":"2021-07-25T16:33:33","guid":{"rendered":"https:\/\/irreal.org\/blog\/?p=9856"},"modified":"2021-07-25T12:33:33","modified_gmt":"2021-07-25T16:33:33","slug":"logging-mbsync-errors","status":"publish","type":"post","link":"https:\/\/irreal.org\/blog\/?p=9856","title":{"rendered":"Logging <code>mbsync<\/code> Errors"},"content":{"rendered":"<p>I\u2019ve been <a href=\"https:\/\/irreal.org\/blog\/?p=6115\">using mu4e and mbsync<\/a> for the last four years and love it. One of the things you discover early in your use of <code>mbsync<\/code> is that it loves spew messages into the minibuffer. That would be okay except that sometimes it overwrites something that you\u2019re looking at.<\/p>\n<p>A first hack at fixing this is to simply redirect those messages to <code>\/dev\/null<\/code> 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 <code>mbsync<\/code> doesn\u2019t know about so I get the error \u201cIMAP warning: unknown system flag Junk\u201d. That happens every time <code>mbsync<\/code> downloads new email messages so it would quickly fill up the log file.<\/p>\n<p>A third iteration in fixing this is to send the messages to a filter that deletes any messages that you\u2019re not interested in. My simple filter for this is<\/p>\n<div class=\"org-src-container\">\n<pre class=\"src src-shell\"><span style=\"color: #b22222;\">#<\/span><span style=\"color: #b22222;\">! \/bin\/<\/span><span style=\"color: #a020f0;\">zsh<\/span>\n<span style=\"color: #483d8b;\">read<\/span> LINE\n<span style=\"color: #a020f0;\">if<\/span> [ $<span style=\"color: #a0522d;\">LINE<\/span> != <span style=\"color: #8b2252;\">'IMAP warning: unknown system flag Junk'<\/span> ]\n<span style=\"color: #a020f0;\">then<\/span>\n    <span style=\"color: #483d8b;\">echo<\/span>  $(date): <span style=\"color: #8b2252;\">\\\\<\/span>c\n    <span style=\"color: #483d8b;\">echo<\/span> $<span style=\"color: #a0522d;\">LINE<\/span>\n<span style=\"color: #a020f0;\">fi<\/span>\n<\/pre>\n<\/div>\n<p>Obviously you can easily add additional messages to ignore.<\/p>\n<p>The next problem is that <code>mbsync<\/code> sends these messages to STDERR instead of STDOUT so you have to figure out someway of piping STDERR to the next process\u2019s STDIN. That turns out to be a bit fussy but the TD;DR is<\/p>\n<ol class=\"org-ol\">\n<li>Redirect STDERR to STDOUT<\/li>\n<li>Disappear STDOUT<\/li>\n<\/ol>\n<p>Here\u2019s what this looks like for <code>mu4e<\/code>.<\/p>\n<div class=\"org-src-container\">\n<pre class=\"src src-elisp\">(<span style=\"color: #a020f0;\">setq<\/span> mu4e-get-mail-command <span style=\"color: #8b2252;\">\"mbsync -q icloud 2&gt;&amp;1 &gt; \/dev\/null | (~\/bin\/mbsyncfilter) &gt;&gt; ~\/.mbsync.log\"<\/span>)\n<\/pre>\n<\/div>\n<p>Something similar, I\u2019m sure, would work for <code>notmuch<\/code> or whatever else you\u2019re using <code>mbsync<\/code> with.<\/p>\n<p>I get about five to ten error messages a week. They\u2019re mostly things like the system couldn\u2019t 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\u2019s never a huge number of messages to deal with.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I\u2019ve 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 &hellip; <a href=\"https:\/\/irreal.org\/blog\/?p=9856\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[18,166],"class_list":["post-9856","post","type-post","status-publish","format-standard","hentry","category-general","tag-emacs","tag-mu4e"],"_links":{"self":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/9856","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9856"}],"version-history":[{"count":1,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/9856\/revisions"}],"predecessor-version":[{"id":9857,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/9856\/revisions\/9857"}],"wp:attachment":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9856"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9856"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9856"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}