Configuring mbsync for Apple Mail

As a first step in realizing my goal of running mu4e as my email client, I had to get mbsync running. Mbsync is a process that communicates with one or more IMAP servers to keep your email clients in sync. My primary email is through Apple so one of my goals was to be able to use mu4e on my Macs but still have fully synced access to mail on my iPhone and iPad. That’s pretty easy because Apple mail is IMAP based and keeping multiple clients in sync is the point of IMAP.

There are two problems to solve for getting mbsync working on the Mac. The first is specifying your mail server password to mbsync. You could, of course, just put the password in your mbsync configuration file but that’s horribly insecure and, happily, unnecessary. Here’re the directions for setting up a password in your keychain from the sample configuration that comes with mbsync.

# On Mac OS X, run "KeyChain Access" -- File->New Password Item. Fill out form using
#  "Keychain Item Name" http://IMAPSERVER  (note: the "http://" is a hack)
#  "Account Name" USERNAME
#  "Password" PASSWORD

That brings us to the second problem: what to use for a password. You might think your icloud password is what’s needed here but if you have two-factor authentication enabled—which you almost certainly do if you’re running Sierra or later—you need to generate an application specific password. You can do that by following these instructions. Failure to understand this point was the source of almost all my problems in getting things working.

I keep all my saved emails in a single folder for reasons I’ve discussed before. Your setup may be a little different but if so you just need to adjust the list of mailboxes on the Patterns line in the configuration below. I added an icloud subdirectory under Maildir because I intend to add a separate mail repository for Gmail later. Right now, the configuration communicates only with the Apple mail server.

Here is my .mbsyncrc file. It normally lives in your home directory.

# Based on http://www.macs.hw.ac.uk/~rs46/posts/2014-01-13-mu4e-email-client.html
IMAPAccount icloud
Host imap.mail.me.com
User XXX #not XXX@me.com etc.
PassCmd "security find-generic-password -s mbsync-icloud-password -w"
Port 993
SSLType IMAPS
SSLVersions TLSv1.2
AuthMechs PLAIN

IMAPStore icloud-remote
Account icloud

MaildirStore icloud-local
Path ~/Maildir/icloud/
Inbox ~/Maildir/icloud/inbox
Trash Trash

#
# Channels and Groups 
# (so that we can rename local directories and flatten the hierarchy)
#
#
Channel icloud-folders
Master :icloud-remote:
Slave :icloud-local:
Patterns "INBOX" "Saved" "Drafts" "Archive" "Sent*" "Trash"
Create Both
Expunge Both
SyncState *

Group icloud
Channel icloud-folders

Once you get everything set up you can try retrieving your mail with

mbsync -a

or, if you have more than one mail server configured

mbsync icloud #or whatever your mail group name is

In the case of Apple, the server doesn’t like users sucking up bandwidth so if you have a large repository on the server, it may drop off after a while. That’s not fatal because you can just restart the download and it will take up where it left off. You can help a bit by rate limiting your network I/O as described by Ben Maughan in this post. That post also has a nice configuration for Gmail if that’s what you need. After the initial download everything will work smoothly.

Shortly, I’ll publish my next post in this series about mu4e with a discussion of my mu4e configuration.

Posted in General | Tagged , | 1 Comment

Summer!

As many of you know, the Irreal International Headquarters is in Tampa, Florida. That means that this Kontra tweet resonated:

Kontra is, I think, based in New York City. He should try a Florida summer.

Posted in General | Tagged | Leave a comment

Mu4e at Irreal

Ever since I read Ben Maughan’s post on mastering your inbox with mu4e and Org mode back in 2015, I’ve been insanely jealous of his method and of his use of mu4e for dealing with emails directly in Emacs. Right after I read his post, I combined all my email folders into one and started following his procedures for dealing with emails.

Still, it was a bit clumsy with Apple’s mail app and the searching involved a lot of mouse clicking. And, of course, it wasn’t happening inside of Emacs. Now, finally, I have mu4e up and running and am using it as my mail client. The search capability is amazing: it’s lightning fast and very flexible. You can form complex queries without touching the mouse or being limited to canned searches. The best part is that because it’s all IMAP based my old client and more importantly, my iPhone and iPad mail apps still work and keep everything in sync.

Setting up mu4e turned out to be pretty easy. The tough part was getting mbsync to work with Apple. That’s mostly because I forgot about the two-factor authentication that Apple recently added in the last macOS release so you can chalk up the difficulties to my stupidity.

In the near future, I will post my mbsync configuration and what I had to do to get it to talk to Apple’s IMAP server. That may be useful because it’s really hard to find examples of setting it up with Apple. After that, I will write a post on my mu4e setup and configuration, although most of that was stolen from Ben and Charl Botha.

Next up is moving my RSS to elfeed. Fortunately, Mike Zamansky has three excellent videos on that so it shouldn’t take nearly as long. After that, browsing and iMessage will be my only frequently used applications that don’t run under Emacs. I don’t see much hope for moving either of them to Emacs anytime soon so after elfeed my workflow will be pretty much as Emacs-centric as it’s going to get.

Posted in General | Tagged , | 3 Comments

Updating save-receipt-link

This is tax season here in the United States. My Org-based tax record keeping enabled me to send everything to my accountant as soon as I had all the proper forms from employers, banks, and other sources of income to the vast Irreal empire. As usual, once I’d finished with all the paperwork, I reviewed my procedures to see if there was anything I could do to reduce friction and make things easier.

Five years ago, I wrote about one such improvement: a bit of Elisp to save links to scanned receipts in my Org files. Here, for reference, is that Elisp from the above link:

(defconst current-tax-file "tax12")

(defun save-receipt-link (doc)
  "Make a link to a receipt in the current tax file."
  (interactive "sDocument Name: ")
  (insert (concat "[[file:~/tax/" current-tax-file "/receipts/" doc
                  "][receipt]]")))

The save-receipt-link function worked well and I’ve been using it throughout the last 5 years as I get receipts that I need to save for tax purposes. There are, however, a couple of problems with it. The first is that I often get the file name of the scanned receipt wrong. Most often this involves leaving off the .pdf at the end. I could solve most instances of that problem by just programmatically adding the .pdf but some documents have a different extension and sometimes I just mistype the name so appending the .pdf doesn’t really solve the problem.

The other problem appeared at the beginning of the year. I was still getting receipts from the previous year but also getting receipts for the current year. That meant I had to hand-edit the receipt links.

Obviously, since I’ve been using this method for 5 years, neither of these problems is fatal but they do inject a bit of friction. This year I decided to fix things. I did that by changing save-receipt-link to be

(defconst prev-tax-file "~/tax/tax16/receipts")
(defconst current-tax-file "~/tax/tax17/receipts")

(defun save-receipt-link (prevp)
  "Make a link to a receipt in the current or previous tax file.
Use the previous tax file if called with the universal argument."
  (interactive "P")
  (insert (format "[[file:%s][receipt]]"
                  (completing-read "Document: "
                                   (directory-files
                                    (if prevp prev-tax-file current-tax-file) t)))))

By adding the completing-read, I get a list of the files and merely have to pick the correct one. That makes the entry faster while eliminating the errors I kept making with the old version.

If I call save-receipt-link with the universal argument, I will use last year’s directory instead of the current year’s. That eliminates the confusion at the change of year.

None of this is going to make dealing with taxes pleasurable, of course, but it does make it a little easier.

Posted in General | Tagged | Leave a comment

AI Loosely Defined

Since this is April 1st and no post will be taken seriously anyway, I offer this piece of wisdom, which Jean-Philippe Paradis retweeted:

Posted in General | Tagged , | Leave a comment

The Emacs rx Macro

I’ve long been aware of the rx macro in Emacs as a way of lispifying regular expressions but it always seemed too complicated to learn. Now Francis Murillo (I think) has published an excellent post on using the rx macro. The post has an explanation of the syntax and several worked examples.

If you are one of those people who have a hard time writing or reading regular expressions, you should take a look. It may make writing those regular expressions easier, especially if you feel comfortable with Elisp.

Posted in General | Tagged | Leave a comment

The Richness of ibuffer

Marcin Borkowski (mbork) has a handy reminder about the richness of ibuffer. It really is very flexible and it’s worth reading the help as mbork suggests.

Posted in General | Tagged | Leave a comment

Abo-abo on Implementing a C++ IDE on Emacs

A couple of days ago, I wrote about Baris Yuksel’s videos on making an Emacs C++ IDE. Today, I saw a post by abo-abo on how he improved his Emacs C++ environment. Abo-abo says he was motivated to improve his environment when he needed to do some C++ work for his job.

The first thing he did was to get RTags working. The RTags developers claim that it works a bit better than the other solutions, such as GNU global, for C++ so if you’re a C++ programmer, you might want to give it a try.

The second thing he did was to install irony for completion. This follows pretty much the same process that Yuksel used. Of course, he also integrated into his counsel package so that the normal counsel regex tricks work. He has some screen shots of this in his post.

If you follow Yuksel and abo-abo, you can have a first rate C++ IDE pretty easily.

Posted in General | Tagged | 1 Comment

Comments on the Thompson Hack

I’ve written several times (1, 2, 3) about Ken Thompson’s beautiful if terrifying hack that invisibly inserted a back door into all programs generated with the C compiler. “Invisibly” here means that there’s nothing in the C compiler’s source code that indicates what’s happening.

The other day I came across this interesting discussion of the Thompson Hack that makes it clear, in a way that Thompson’s paper did not, just how devastating the hack is. It’s a nice discussion and anyone serious about programming or security should take a look at it. Of course, as I’ve said before, you’ll never trust your tools again.

Posted in General | Tagged , | Leave a comment

Emacs as a C/C++ IDE

This is another of a series of posts on how to use Emacs as a C/C++ IDE. I’m always seeing queries about how to do that so it’s worth another post on the subject. This time, I want to discuss a series of videos by Baris Yuksel.

There are four videos. The first two cover the usual subjects of completion, yasnippets, iedit, flymake, and even google-cpplint. Most active developers probably have all that installed already (with the possible exception of google-cpplint). Still, if you’re starting from scratch, Yuksel shows what these do and why you might want to install them. These two videos cover the same ground—but in a different way—as Mike Zamasky’s C++ video.

The second two videos are the most interesting. They cover how to give Emacs semantic knowledge of C++. The third video illustrates this with cedit and the fourth shows how to do the same thing with irony/sarcasm if you’re a clang user. Either of these two methods give Emacs intellisence capabilities and you should definitely take a look if you do a lot of C/C++ programming.

The first 3 videos are all together in a panel with the first video. The fourth is separate but can be found here. The videos are all 6 to 8 minutes long so it’s easy to find time to watch them. The videos are from 2014 so they discuss previous versions of Emacs and the packages but most if not all of the material still applies today.

Posted in Programming | Tagged | 5 Comments