Save hours by reading mailing lists in Emacs over IMAP

Tagged:  •  

Emacs' built-in newsreader Gnus is made for efficiently keeping up with high-volume lists; I show how to hook it into your IMAP account.

With features like configurable message threading, kill-files and per-thread and per-poster scoring, Gnus has the potential to save a lot of the time you would normally spend wading through high-volume mailing lists.

Nowadays most people read mailing lists via IMAP-enabled mail accounts, e.g. Gmail. Gnus supports IMAP directly, but it doesn't work well when the remote folders have thousands of messages, as is the case with many mailing lists. As a workaround, we can use offlineimap to maintain a local copy of our folders. As a side benefit, we can then read mail off-line.

We can use the excellent Dovecot to provide an IMAP interface to that local copy so that Gnus can access it; and we can do this without configuring Dovecot as a full IMAP server, which would need to run constantly and be configured for authentication etc.

On a Mac, you can install dovecot and offlineimap with Homebrew, MacPorts or, presumably, Fink.

In ~/.dovecotrc:

protocols = imap
mail_location = maildir:~/Library/Caches/OfflineImap
auth default {
}

And in ~/.offlineimaprc:

[general]
accounts = Mail
maxsyncaccounts = 1
ui = TTY.TTYUI
[Account Mail]
localrepository = Local
remoterepository = Remote
[Repository Local]
type = IMAP
preauthtunnel = dovecot -c ~/.dovecotrc --exec-mail imap
[Repository Remote]
type = IMAP
# or "type = Gmail", if applicable
remotehost = my.mail.server
remoteuser = myuser
remotepass = mypassword
ssl = yes
maxconnections = 1
realdelete = no
folderfilter = lambda foldername: re.search("^Lists\.", foldername)

Now, simply running "offlineimap" should sync your mailing lists into ~/Library/Caches/OfflineImap. (You'll need to do this regularly, e.g. before and after reading your lists. Julien Danjou recently wrote a nice elisp wrapper for offlineimap.)

All that remains is to tell Gnus how to access your local mail cache.

In .gnus:

(setq imap-shell-program "dovecot -c ~/.dovecotrc --exec-mail imap")
(setq gnus-select-method '(nnimap "Mail"
                                  (nnimap-stream shell)))

Now you can start Gnus with "M-x gnus", and then press "^" to enter the server buffer. Drill down into the "nnimap+Mail" server and use "u" to subscribe to each of the mailing lists. They should then appear in Gnus' main "*Group*" buffer.

That's enough to get started reading mail more efficiently, and as with all things Emacs, there's great potential for customising Gnus to suit your own preferences.

Further reading

As of dovecot version 2, the line

preauthtunnel = dovecot -c ~/.dovecotrc --exec-mail imap

does not work because there is a new, plain command, 'imap', as per the upgrade notes on http://wiki2.dovecot.org/Upgrading/2.0.

On my machine (os x), with dovecot installed via homebrew, the correct line is

preauthtunnel = /usr/local/Cellar/dovecot/2.0.15/libexec/dovecot/imap

That was the first thing I tried, works fine from outside Emacs. Oh well, I'll eventually figure it out. Thanks you took the time to reply! :-)

Sounds like Emacs had trouble running the command "dovecot -c ~/.dovecotrc --exec-mail imap" in order to access the Gnus "Mail" account. Try running that command in a terminal window and see if there's an obvious problem.

Hm, everything seems to be working with offlineimap, but when trying to start gnus I get the following message:

Warning: Opening nnimap server on Mail...failed: ; Denied server nnimap+Mail; Opening nnimap server on Mail...failed: ; Denied server nnimap+Mail; Unable to open server nnimap+Mail due to: Process *nnimap* not running

Any ideas? I googled for a bit, but I haven't really used gnus before, so don't fully understand how all the parts fit together. If you don't know I'll just search more myself, but I figured I'll take a shot and maybe you know something...

You probably have two different versions of Emacs and/or Gnus. Which step doesn't work for you?

This works in terminal Emacs, but doesn't seem to work in the Cocoa version of Emacs, is there something that has to be changed to get it working in the Cocoa version?

On my end, I had to disable gnus-agent for gmail, otherwise the summary buffers showed all kinds of odd stuff.

Each daily digest of a busy mailing list might contain hundreds of irrelevant messages that my Gnus setup helps me skip over based on the threads I've been reading or marked as uninteresting.

I tackle with the issue of keeping up with high-volume mailing lists, simply by subscribing to the digest version of those lists. You get only one email from the list every day. While this may not be an optimal setup for those that wish to respond ASAP on certain mails from the group, for me it works well since mails sent to a mailing list group are definitely not urgent and can wait a day (until the digest arrives in my inbox and if i choose to respond it within 24 hours, which i deem an acceptable time lag).

Syndicate content