Collection of interesting articles related to emacs and email. * [[https://www.chrislockard.net/posts/o365-mail-emacs-mbsync-mu4e/][Manage o365 mail with emacs, mbsync, and mu4e | Unl0ckd]] :website: [2021-12-05 Sun 21:45] ** Article One of these days, this blog will be used for more than just notes to myself again. *** Why? For the past year, I have been enraptured with Emacs. I've embraced the idea of extending it into as many facets of my workflow as possible. This post details how I was able to get my work email setup in mu4e for easy task creation via org-mode. For several years, I've been using my inbox as a todo list, filing email into a complex folder hierarchy. Once I discovered [[https://orgmode.org/][org-mode]], I realized that I should use email as an interface for correspondence only. If a message came in that I should act on at some future point, it should be captured in my org todo and then discarded. I believe this follows in the principles of [[https://gettingthingsdone.com/what-is-gtd/][GTD]]. I'm using: - [[http://isync.sourceforge.net/mbsync.html][mbsync]] - mailbox synchronizer - [[https://www.djcbsoftware.nl/code/mu/mu4e.html][mu4e]] - mail client - [[https://github.com/hlissner/doom-emacs][Doom Emacs]] - Text editor and org-mode host **** mbsync =mbsync= is a mailbox synchronizer that retrieves messages via IMAP from a remote mailstore and saves them as flat files locally. ***** mbsync Configuration mbsync configuration is performed in =~/.mbsyncrc= (and in fact requires this file to run). Here's my =~/.mbsyncrc=: #+begin_example IMAPAccount work Host outlook.office365.com User [email protected] PassCmd "security find-generic-password -s NoMAD -w" SSLType IMAPS SSLVersion TLSv1.2 AuthMechs PLAIN # Increase timeout to avoid o365 IMAP hiccups Timeout 120 PipelineDepth 50 IMAPStore work-remote Account work MaildirStore work-local # Note the trailing slash on the Path statement! Path ~/.mail/work/ Inbox ~/.mail/work/Inbox SubFolders Legacy Channel work Master :work-remote: Slave :work-local: #Include everything Patterns * # Sync changes (creations/deletions) with the server Create Both Expunge Both Sync All #+end_example Verify mbsync is working correctly with =$ mbsync work=. This will pull down work mail to =~/.mail/work/= with a folder layout mimicking Exchange's mail folder structure. Some items to note: - =Create Both= and =Expunge Both= means mbsync can *delete* messages on your mailserver. If you want to try this configuration out in read-only mode, set these values to =Create Slave= and =Expunge Slave= instead. - The trailing slash on the local =MaildirStore= =path= statement is critical! - My experience with Exchange 365 has been chaotic. I've set a =Timeout 120= value to try to ensure there are no sync hiccups. This value has proved useful to me, but you can change it or remove it as you see fit. - mbsync will /not/ delete mail folders on the server. Before you use this tool, it might be wise to ensure your Exchange folder hierarchy is as flat as possible. This can be done using the Outlook or OWA client. - =PassCmd= allows you to retrieve credentials from a CLI password manager tool Now email can be synced and retrieved from the mailserver. **** mu4e =mu= is a command-line mail client that provides superior mail search capabilities. Installing this package will automatically pull down mu4e (mu 4 Emacs) as well. ***** mu4e Prerequisites On macOS, install =mu= (which includes mu4e) and =mbsync=. Note that =mbsync= is part of the /isync/ homebrew collection. These are both installed in the terminal using homebrew: #+begin_example brew install mu brew install isync #+end_example Installing from homebrew should place the required files in =/usr/local/share/emacs/site-lisp/mu/mu4e= that will be loaded in the configuration below. ***** Run mu Before using =mu4e= it's a good idea to verify that =mu= works as expected, after all, =mu4e= uses =mu= as its engine. To validate, =mu= must first create a mail index. Run: =$ mu index --maildir=~/.mail/work= Once this completes, give =mu= a spin: =$ mu find timecard= =$ mu find from:myboss= At this point, mail is synced, indexed, and searchable from Exchange. **** Doom Emacs I am thoroughly impresed with [[https://github.com/hlissner/doom-emacs][Doom Emacs]], and use it as my base. Configuring this distribution is slightly different from configuring =mu4e= in vanilla Emacs. First, security: ***** Securely Store SMTP Credentials SMTP is used to transfer outbound messages. I store my o365 creds in a gpg-encrypted file, =~/.emacs.d/.authinfo.gpg= ****** Create authinfo file Enter the credentials for the SMTP server in =~/.authinfo= using the format: =machine mail.example.com login myusername port 587 password mypassword= *Use quotes to contain the password*, for instance: =machine smtp.office365.com login [email protected] password "mypassword" port 587= ****** Encrypt authinfo file Use gpg to encrypt the authinfo file. (macOS users, install [[https://gpgtools.org/]]. This will place a symlink to the =gpg= CLI tool in your =/usr/local/bin= so make sure that's in your shell's =$PATH=. I won't cover the process of creating a keypair in this article, but you can find more information [[https://www.gnupg.org/gph/en/manual/c14.html][here]] and [[https://help.runbox.com/creating-key-pair-on-os-x/][here.]] Find the gpg key you want to encrypt this file with using =$ gpg --list-keys=: #+begin_example ---------------------------------- ... pub rsa4096 2019-01-22 [SC] [expires: 2023-01-22] 315998993D8B8B1BA4AD5D209332E13A9A79C3D5 uid [ultimate] Chris Lockard < [email protected]> sub rsa4096 2019-01-22 [E] [expires: 2023-01-22] sub rsa4096 2019-09-09 [S] [expires: 2023-09-08] sub rsa4096 2019-09-09 [E] [expires: 2023-09-08] sub rsa4096 2019-09-09 [A] [expires: 2023-09-08] #+end_example Now encrypt =~/.authinfo= using the following: =$ gpg -se ~/.authinfo= This prompts for the key to use, so either enter = [email protected]= or the key signature - =A9A79C3D5=. The output of this program is an encrypted file, =~/.authinfo.gpg=. For added security, set the permissions on this file to =chmod 600 ~/.authinfo.gpg=. Finally, move this file with =mv .authinfo.gpg ~/.emacs.d= and cleanup the file containing cleartext credentials with =rm .authinfo=. Emacs will automatically know to look for =~/.emacs.d/authinfo.gpg= which will help later when configuring SMTP. ***** Doom Emacs Configuration I store my Doom configuration files in my github and link them thusly: =ln -s ~/Documents/dotfiles/Emacs/.doom.d ~/.doom.d= Doom defines packages in =~/.doom.d/init.el= with user configuration in =~/.doom.d/config.el= (or =config.org= for literate config-ers like me :)) ***** ~/.doom.d/init.el As =mu4e= is a package only available on the local filesystem, Doom needs to know from where to load it. The following line is added at the top of the file: #+begin_example ;; enabled and in what order they will be loaded. Remember to run 'doom refresh' ;; after modifying it. ;; ;; More information about these modules (and what flags they support) can be ;; found in modules/README.org. ;; This is needed because emacs won't pick up mu4e otherwise: (add-to-list 'load-path "/usr/local/share/emacs/site-lisp/mu/mu4e/") (doom! :input :completion ... #+end_example This mu4e path is where Homebrew installed mu4e (from the =mu= package) by default on macOS Mojave. Further down =init.el=, uncomment mu4e from the =:email= block: #+begin_example ... :email mu4e ; WIP ... #+end_example ***** ~/.doom.d/config.org{el} mu4e configuration is placed in =config.org= or =config.el=. Mine looks like this: #+begin_example (after! mu4e (setq! mu4e-maildir (expand-file-name "~/.mail/work") ; the rest of the mu4e folders are RELATIVE to this one mu4e-get-mail-command "mbsync -a" mu4e-index-update-in-background t mu4e-compose-signature-auto-include t mu4e-use-fancy-chars t mu4e-view-show-addresses t mu4e-view-show-images t mu4e-compose-format-flowed t ;mu4e-compose-in-new-frame t mu4e-change-filenames-when-moving t ;; http://pragmaticemacs.com/emacs/fixing-duplicate-uid-errors-when-using-mbsync-and-mu4e/ mu4e-maildir-shortcuts '( ("/Inbox" . ?i) ("/Archive" . ?a) ("/Drafts" . ?d) ("/Deleted Items" . ?t) ("/Sent Items" . ?s)) ;; Message Formatting and sending message-send-mail-function 'smtpmail-send-it message-signature-file "~/Documents/dotfiles/Emacs/.doom.d/.mailsignature" message-citation-line-format "On %a %d %b %Y at %R, %f wrote:\n" message-citation-line-function 'message-insert-formatted-citation-line message-kill-buffer-on-exit t ;; Org mu4e org-mu4e-convert-to-html t )) (set-email-account! " [email protected]" '((user-mail-address . " [email protected]") (user-full-name . "Chris Lockard") (smtpmail-smtp-server . "smtp.office365.com") (smtpmail-smtp-service . 587) (smtpmail-stream-type . starttls) (smtpmail-debug-info . t) (mu4e-drafts-folder . "/Drafts") (mu4e-refile-folder . "/Archive") (mu4e-sent-folder . "/Sent Items") (mu4e-trash-folder . "/Deleted Items") (mu4e-update-interval . 1800) ;(mu4e-sent-messages-behavior . 'delete) ) nil) #+end_example **** Usage Everything is in place to use Doom Emacs as a mail client! Start Emacs and run =M-x mu4e=: [[/images/2019/11-14-1.png]] ***** Compose a message Press =C= to bring up the message composition window: [[/images/2019/11-14-2.png]] To send a message, place the cursor in the header section ( =gg =) and then =SPC m s=. You'll be prompted to enter the passphrase for your gpg key (sometimes twice) and then your message will send once Emacs decrypts your =~/.emacs.d/authinfo.gpg= to retrieve SMTP credentials. ***** Reply to a message From the inbox view, press =R= to reply to a message. Fill out your response, then send the message by again placing point in the message header section ( =gg =) and then =SPC m s=. ***** Capture a message as a task in orgmode From the inbox view, select a message with == to open the message view. With point in the header section (it should be there by default) and press =SPC X= or =M-x org-capture=. With an appropriate [[https://orgmode.org/manual/Capture-templates.html][capture template]], this message will be linked into org mode for use in your GTD workflow. *** References This specific configuration required referencing many resources. I've included these below: Doom Emacs configurations: - [[https://github.com/ragone/.doom.d/blob/master/config.org]] - [[https://gitlab.com/agraul/dotfiles/blob/master/emacs-doom/.doom.d/config.org]] - [[https://github.com/syl20bnr/spacemacs/issues/4669#issuecomment-232273131]] Mbsync configurations: - [[https://unix.stackexchange.com/questions/122773/mbsync-move-subfolders-to-root]] - [https://pastebin.com/h5iW6j87] - [[https://www.reddit.com/r/emacs/comments/8q84dl/tip_how_to_easily_manage_your_emails_with_mu4e/]] - [[https://www.reddit.com/r/emacs/comments/bfsck6/mu4e_for_dummies/]] - [[http://pragmaticemacs.com/emacs/migrating-from-offlineimap-to-mbsync-for-mu4e/]] - [[http://pragmaticemacs.com/emacs/master-your-inbox-with-mu4e-and-org-mode/]] - [[https://groups.google.com/forum/#!topic/mu-discuss/ezd3Wyghhgc]] - [[https://github.com/kzar/davemail/blob/master/.mbsyncrc]] * [[https://skeptric.com/emacs-email/][Don't manage work email with Emacs ·]] :website: [2021-12-05 Sun 21:44] ** Article I do a lot of work in Emacs and at the command line, and I get quite a few emails so it would be great if I could handle my emails there too. Email in Emacs can be surprisingly featureful and handles HTML markup, images and can even send [[https://kitchingroup.cheme.cmu.edu/blog/2016/10/29/Sending-html-emails-from-org-mode-with-org-mime/][org markup with images and equations]] all from the comfort of an Emacs buffer. However it can be a whole /heap/ of work, and as you get deeper into the features your mail client provides the amount of custom integration required grows very rapidly. It's a good way to appreciate all the features of your current mail client, but you may be able to find a better use of your time. Getting the basics of synchronising emails from an IMAP or Exchange server may take some time to setting up (and in some circumstances take a /lot/ of time), but once they're working it will be pretty smooth. Dealing with HTML and images and attachments works pretty well out of the box, unless you get a lot of custom office drawings in your email. Building an address book of frequent contacts is a bit of a pain, but with some work is possible. Synchronising email addresses from the server can be difficult, and may need to be done in batches - but you might be able to manually. Getting calendar invites is possible with a bit of hacking, but seeing other people's calendars is very difficult. Finally if the server configuration is changed (like changing an authentication provider) you may have to spend a lot of time setting it up all over again. The benefits are that it tends to be faster to get through emails (because they are on the local filesystem), you don't need to change environments to use them and you can use all your favourite CLI tools on them. But unless email is a very large part of your working life (and it seems to be slowly losing out to instant messaging clients) it's probably not worth the investment (unless you want to build a custom email automation tool one day!). I'll share some of my experience doing this for those who are hard to discourage. *** Operating Environment If you want to set up email from the command line or Emacs you'll want to be working in a POSIXy environment, because that's where all the tooling is. If your working environment supports Linux or Mac computers then it's happy times. However if you're working in Windows you have a few options. The best Windows option is [[https://docs.microsoft.com/en-us/windows/wsl/faq][Windows Subsystem for Linux]] - it lets you run a whole Linux environment and works pretty well with Windows. There are a couple of creaky edges, mainly the filesystem is slow (which should be fixed in [[https://docs.microsoft.com/en-us/windows/wsl/wsl2-index][WSL2]]), but overall it's the best solution *if* you can get the [[https://docs.microsoft.com/en-us/windows/wsl/install-win10][feature enabled]]. If you can't then working in a [[https://www.virtualbox.org][Virtualbox VM]] for Linux is the next best option; and you can configure it to be fairly seamless. However you can't use it if there's any other virtualisation on your machine like Docker for Windows. In fact some organisations use security software that uses virtualisation making it impossible to install Virtualbox. But if you can get Virtualbox running (or your organisation supports another virtualisation product) then it's generally a good solution. When all else fails there is good ol' [[https://www.cygwin.com/][Cygwin]]. It doesn't require any special permissions, so as long as you can run external applications on your computer it should work. It's a bit clunky, and you may need to build some utilities (like =isync=, see below) yourself, but with a bit of work you can get a usable environment. I've heard [[https://www.msys2.org/][msys2]] is better but have never taken the time to understand it. *** Synchronising email You now need a way to pull email to your local filesystem and push emails back out. For pushing emails [[file:www.postfix.org][Postfix]] works great (and has a =sendmail= interface) and I've never needed anything else. For pulling emails you can run a email server like [[https://www.dovecot.org/][Dovecot]], but it's quite a bit of effort to set up. The easiest solution is to use [[http://isync.sourceforge.net/][isync/mbsync]], or it's slower cousin [[http://www.offlineimap.org/][offlineimap]]. Both [[http://isync.sourceforge.net/mbsync.html#CONFIGURATION][mbsync]] and [[https://github.com/OfflineIMAP/offlineimap/blob/master/offlineimap.conf][offlineimap]] have gnarly configuration options that will make you learn quite a bit about the low level details of email authentication and [[https://en.wikipedia.org/wiki/Maildir][Maildir]]. And if you set the wrong options you might accidentally delete your whole email; so spend a lot of time reading through them and try it out on a test account before you run it on your precious emails. To get authentication details for your email provider the easiest thing to do is to search the web, and if you have a common email provider (like Gmail, Office365, Fastmail) you'll likely find a blog with a sample configuration. If you've got an uncommon provider look in their documentation/settings for SMTP and IMAP; if the Auth method isn't clear it's best to try to set it up with [[https://www.thunderbird.net/en-US/][Thunderbird]] first because it has some magic to automatically detect these settings and is more likely to work out of the box. If your email provider doesn't have IMAP enabled then you're probably out of luck - unless it's an exchange server. If you can't get app passwords and need to use two factor authentication you may spend a /lot/ of time trying to get this set up (and may have to implement the feature!). If you're on an Exchange server or on Office365 but can't access IMAP then you can use the fantastic [[http://davmail.sourceforge.net/][Davmail]]. Davmail also supports CalDAV and CardDAV for calendar and contacts (more on this later). The only issue is finding the Exchange server settings can take some sleuthing (or a beer with your local sysadmin). As before it's best to get it working in Thunderbird before trying another synchronising tool, because it's easiest to get working there. *** Setting up a mail interface So now you've got all your emails sitting in a maildir folder it'd be handy to have a tool for reading and writing email. If you're a serious vim user [[http://www.mutt.org/][mutt]] may be a good option. [[https://notmuchmail.org/][notmuch]] has a powerful tag system, but you have to manually sync it yourself between servers (and the [[https://notmuchmail.org/notmuch-emacs/][Emacs mode]] has too many special screens for my liking). In Emacs [[https://www.gnu.org/software/emacs/manual/html_node/gnus/Maildir.html][gnus]] is built-in, but has a byzantine configuration system that you could spend the rest of your life tweaking (like this [[https://github.com/jwiegley/dot-emacs/blob/master/gnus-settings.el][John Wiegley's]]). But gnus is apparently good if you're on a lot of mailing lists. However for me [[https://www.djcbsoftware.nl/code/mu/][mu]] and it's Emacs counterpart [[https://www.djcbsoftware.nl/code/mu/mu4e.html][mu4e]] work fantastically well - you just have to take the time to learn yet another query language (and if you use evil-mode there are mu4e keybindings in [[https://github.com/emacs-evil/evil-collection/][evil-collection]]). This is generally pretty straightforward (especially if you can crib a configuration file that is close to what you need), but there are some traps like if you use mbsync and mu4e you need to set =mu4e-change-filenames-when-moving= to true or you'll get all sorts of errors when trying to sync. You can then spend a bunch of time configuring [[https://www.reddit.com/r/emacs/comments/9ep5o1/mu4e_stop_emails_setting_backgroundforeground/][how HTML is rendered]], [[http://pragmaticemacs.com/emacs/master-your-inbox-with-mu4e-and-org-mode/][storing links to emails in org-mode]] and [[https://kitchingroup.cheme.cmu.edu/blog/2016/10/29/Sending-html-emails-from-org-mode-with-org-mime/][sending email from org-mode]]. *** Dealing with contacts Now you can write email you may want to store the addresses of people you want to contact. Many email providers support the [[https://en.wikipedia.org/wiki/CardDAV][CardDav]] format and you can synchronise it locally with a tool like [[https://asynk.io/][ASynK]] or [[https://github.com/pimutils/vdirsyncer][vdirsyncer]]. You can then import them into org contacts with [[https://github.com/flexibeast/org-vcard][org-vcard]] and [[https://www.djcbsoftware.nl/code/mu/mu4e/Maintaining-an-address_002dbook-with-org_002dcontacts.html][configure mu4e]] to use them for auto-completion. Or use them with [[https://www.jwz.org/bbdb/][BBDB]] for Emacs email clients that support them, or write a script to convert them to [[https://gitlab.com/muttmua/mutt/-/wikis/MuttGuide/Aliases][Mutt aliases]]. One problem is if you work for an enterprise with thousands of people that's going to be a lot of email addresses, and the syncing or the interface may choke. You can probably get away with just manually copying the addresses of the people you email most often into the configuration of whatever tool you use. But once in a while you'll want to email someone in your organisation and you may have to fall back to another tool to get the address book. *** Calendars and meeting invites Calendars is something where Outlook groupware really shines. You can see everyone's calendar and schedule a meeting in free time using the scheduling assistant (and book meeting rooms!). While this can lead to the problem of [[https://jack.ofspades.com/calendar-tetris-is-an-antipattern/][calendar tetris]] where other people unilaterally fill the blanks in your Calendar, it's generally a useful organisational feature and can sometimes even be used to list and book available meeting rooms. [[/images/outlook_scheduling_assistant.png]] I haven't found anything that quite substitutes for it in an office environment. You could manage your calendar with a command line tool in [[https://github.com/pimutils/khal][khal]] or in Emacs with [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Calendar_002fDiary.html][diary/calendar]] or [[https://orgmode.org/manual/Weekly_002fdaily-agenda.html][org-agenda]] or [[https://github.com/kiwanami/emacs-calfw][calfw]] and synchronise it over iCal. You can probably even get meeting invites into your calendar and respond to the invitation ( [[https://github.com/djcb/mu/issues/994][mu4e supports this]]). But I doubt there's anything like the scheduling assistant and if you organise a lot of meetings in an Outlook office you'll be falling back to Outlook a lot. If you get this far you can spend a lot more time smoothing out the rough edges. It's certainly possible to do, but worth thinking about whether it's really going to pay off for the time investment. But maybe you can walk the path and enjoy the journey as much as I did. * [[https://kdecherf.com/blog/2017/05/01/mbsync-and-office-365/][mbsync and Office 365 | kdecherf ~ %]] :website: [2021-12-05 Sun 21:43] ** Article [[https://kdecherf.com/][kdecherf ~ %]] [[data:image/svg+xml;base64,PHN2ZyBpZD0ibW9vbiIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdib3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSJjdXJyZW50Q29sb3IiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIj4gPHBhdGggZD0iTTIxIDEyLjc5QTkgOSAwIDEgMSAxMS4yMSAzIDcgNyAwIDAgMCAyMSAxMi43OXoiPjwvcGF0aD48L3N2Zz4=]] [[data:image/svg+xml;base64,PHN2ZyBpZD0ic3VuIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld2JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiPiA8Y2lyY2xlIGN4PSIxMiIgY3k9IjEyIiByPSI1Ij48L2NpcmNsZT4gPGxpbmUgeDE9IjEyIiB5MT0iMSIgeDI9IjEyIiB5Mj0iMyI+PC9saW5lPiA8bGluZSB4MT0iMTIiIHkxPSIyMSIgeDI9IjEyIiB5Mj0iMjMiPjwvbGluZT4gPGxpbmUgeDE9IjQuMjIiIHkxPSI0LjIyIiB4Mj0iNS42NCIgeTI9IjUuNjQiPjwvbGluZT4gPGxpbmUgeDE9IjE4LjM2IiB5MT0iMTguMzYiIHgyPSIxOS43OCIgeTI9IjE5Ljc4Ij48L2xpbmU+IDxsaW5lIHgxPSIxIiB5MT0iMTIiIHgyPSIzIiB5Mj0iMTIiPjwvbGluZT4gPGxpbmUgeDE9IjIxIiB5MT0iMTIiIHgyPSIyMyIgeTI9IjEyIj48L2xpbmU+IDxsaW5lIHgxPSI0LjIyIiB5MT0iMTkuNzgiIHgyPSI1LjY0IiB5Mj0iMTguMzYiPjwvbGluZT4gPGxpbmUgeDE9IjE4LjM2IiB5MT0iNS42NCIgeDI9IjE5Ljc4IiB5Mj0iNC4yMiI+PC9saW5lPjwvc3ZnPg==]] - [[https://kdecherf.com/about/][About]] - [[https://kdecherf.com/blog/][Blog]] - [[https://kdecherf.com/le-kdecherf/][*Le Kdecherf]] - [[https://kdecherf.com/disclaimer/][Disclaimer]] - [[https://kdecherf.com/tags/][Tags]] [[https://kdecherf.com/][Home]] » [[https://kdecherf.com/blog/][Blog]] *** mbsync and Office 365 May 1, 2017 · 1 min I observed that offlineimap stops working correctly and starts seeing UID validity issues quite often when syncing my Office 365 account. Considering that a full folder resync is necessary to get rid of these issues I decided to give [[http://isync.sourceforge.net/][mbsync]] a try. After making the configuration of the tool, which is pretty straightforward, I started it and... It failed with cryptic and random error messages like these: #+begin_example IMAP error: bogus FETCH response #+end_example and #+begin_example IMAP command 'UID FETCH x (BODY.PEEK[])' returned an error: UID FETCH x (BODY.* y FETCH (BODY[] {z} #+end_example While trying to find any resource about these errors I [[https://wiki.archlinux.org/index.php/Isync#Exchange_2003][found a note]] on the isync page of ArchLinux's Wiki. It says that Microsoft Exchange 2003 server is unable to handle concurrent IMAP commands, which is the default behavior of mbsync. You must add the following line to the mbsync configuration to disable this feature: #+begin_example PipelineDepth 1 #+end_example It appears that this solution also solves the issue with Office 365. /Enjoy!/ - [[https://kdecherf.com/tags/mbsync/][mbsync]] - [[https://kdecherf.com/tags/office-365/][office 365]] Content under license [[http://creativecommons.org/licenses/by-nc-sa/3.0/][CC BY-NC-SA 3.0]] Powered by [[https://gohugo.io/][Hugo]] & [[https://git.io/hugopapermod][PaperMod]] [[data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdib3g9IjAgMCAxMiA2IiBmaWxsPSJjdXJyZW50Q29sb3IiPiA8cGF0aCBkPSJNMTIgNkgwbDYtNnoiPjwvcGF0aD48L3N2Zz4=]] * [[https://xenodium.com/trying-out-mu4e-with-mbsync/][Trying out mu4e with mbsync]] :website: [2021-12-05 Sun 21:42] ** Article *** Álvaro Ramírez **** 17 June 2018 Trying out mu4e with mbsync The email fun in Emacs continues. After a few weeks since I [[../trying-out-mu4e-and-offlineimap][started using mu4e and offlineimap]], I'm sold. Both are awesome. [[http://isync.sourceforge.net/mbsync.html][Mbsync]] is an [[http://www.offlineimap.org/][offlineimap]] alternative. Despite resyncing all my mail, the transition was fairly smooth. Here's how... ***** Install isync (for mbsync) #+begin_example brew install isync #+end_example ***** Configure mbsync Mbsync uses =~/.mbsyncrc= for configuration. Migrating [[../trying-out-mu4e-and-offlineimap][~/.offlineimaprc]] to =~/.mbsyncrc= looks like: #+begin_example IMAPAccount Personal Host some.imap.host.com User your_user_name PassCmd "gpg --quiet --batch -d ~/.offlineimap_accountname.gpg" Port 993 SSLType IMAPS AuthMechs Login CertificateFile ~/.offlineimapcerts.pem # My IMAP provider doesn't handle concurrent IMAP commands. PipelineDepth 1 IMAPStore Personal-remote Account Personal MaildirStore Personal-local Path ~/IMAP/Personal/ Inbox ~/IMAP/Personal/INBOX Channel Personal Master :Personal-remote: Slave :Personal-local: Patterns * Create Slave Sync All Expunge Both SyncState * #+end_example ***** No concurrent IMAP commands supported My IMAP provider doesn't handle concurrent IMAP commands. [[https://kdecherf.com/blog/2017/05/01/mbsync-and-office-365/][mbsync and Office 365]] had the answer: #+begin_example PipelineDepth 1 #+end_example ***** Initial sync Run initial from the command line sync: #+begin_example mbsync -Va #+end_example While syncing my largest inbox, it sometimes received an unexpected EOF error: #+begin_example IMAP error: unexpected EOF from some.imap.host.com (1.2.3.4:993) #+end_example First few times, I restarted the syncing manually, but then used a loop to automatically restart it. Bash loops: #+begin_example while true; do mbsync -V Personal; sleep 5; done #+end_example #+begin_example for i in {1..5}; do mbsync -V Personal; sleep 5 done #+end_example Eshell loop: #+begin_example for i in (number-sequence 1 10) {mbsync -V Personal; sleep 5} #+end_example ***** Create mu index Reindex using mu, but first remove existing index for offlineimap messages: #+begin_example rm -rf ~/.mu #+end_example Ok, do index now: #+begin_example mu index --maildir=~/IMAP #+end_example ***** Mu4e tweaks The /get mail/ command should now point to mbsync. #+begin_example (csetq mu4e-get-mail-command "mbsync -Va") #+end_example I had issues with duplicate IDs after moving and deleting messages from mu4e. [[http://pragmaticemacs.com/emacs/migrating-from-offlineimap-to-mbsync-for-mu4e/][Migrating from offlineimap to mbsync for mu4e]] had the answer: #+begin_example (csetq mu4e-change-filenames-when-moving t) #+end_example ***** Helpful references - [[https://webgefrickel.de/blog/a-modern-mutt-setup][A modern mutt setup with neomutt, mbsync, msmtp and mu --- part one | webgefrickel]]. - [[http://pragmaticemacs.com/emacs/migrating-from-offlineimap-to-mbsync-for-mu4e/][Migrating from offlineimap to mbsync for mu4e | Pragmatic Emacs]]. - [[https://copyninja.info/blog/email_setup.html][My personal Email setup - Notmuch, mbsync, postfix and dovecot]]. - [[https://github.com/jeremy-compostella/org-msg/blob/master/README.org][org-msg: Compose and reply to emails in a Outlook HTML friendly style]]. - [[http://www.ict4g.net/adolfo/notes/2014/12/27/EmacsIMAP.html][Reading IMAP Mail in Emacs on OSX]].