Next: , Previous: , Up: Getting started   [Contents]

2.7 Retrieval and indexing with mu4e

As we have seen, we can do all of the mail retrieval outside of emacs/mu4e. However, you can also do it from within mu4e.

2.7.1 Basics

To set up mail-retrieval from withing mu4e, set the variable mu4e-get-mail-command to the program or shell command you want to use for retrieving mail. You can then get your e-mail using M-x mu4e-update-mail-and-index, or C-S-u in all mu4e-views; alternatively, you can use C-c C-u, which may be more convenient if you use emacs in a terminal.

You can interrupt the (foreground) update process with q.

It is possible to update your mail and index periodically in the background or foreground, by setting the variable mu4e-update-interval to the number of seconds between these updates. If set to nil, it won’t update at all. After you make changes to mu4e-update-interval, mu4e must be restarted before the changes take effect. By default, this will run in background and to change it to run in foreground, set mu4e-index-update-in-background to nil

2.7.2 Handling errors during mail retrieval

If the mail-retrieval process returns with a non-zero exit code, mu4e shows a warning (unless mu4e-index-update-error-warning is set to nil), but then try to index your maildirs anyway (unless mu4e-index-update-error-continue is set to nil).

Reason for these defaults is that some of the mail-retrieval programs may return non-zero, even when the updating process succeeded; however, it is hard to tell such pseudo-errors from real ones like ’login failed’.

If you need more refinement, it may be useful to wrap the mail-retrieval program in a shell-script, for example fetchmail returns 1 to indicate ’no mail’; we can handle that with:

(setq mu4e-get-mail-command "fetchmail -v || [ $? -eq 1 ]")

A similar approach can be used with other mail retrieval programs, although not all of them have their exit codes documented.

2.7.3 Implicit mail retrieval

If you don’t have a specific command for getting mail, for example because you are running your own mail-server, you can leave mu4e-get-mail-command at "true" (the default), in which case mu4e won’t try to get new mail, but still re-index your messages.

2.7.4 Speeding up indexing

If you have a large number of e-mail messages in your store, (re)indexing might take a while. The defaults for indexing are to ensure the we always have correct, up-to-date information about your messages, even if other programs have modified the Maildir.

The downside of this thoroughness (which is the default) is that it is relatively slow, something that can be noticeable with large e-mail corpa. For a faster approach, you can use the following:

  mu4e-index-cleanup nil      ;; don't do a full cleanup check
  mu4e-index-lazy-check t)    ;; don't consider up-to-date dirs

In many cases, the mentioned thoroughness might not be needed, and these settings give a very significant speed-up. Note that you can of course occasionally run a thorough indexing round. For further details, please refer to the mu-index manpage.

2.7.5 Example setup

A simple setup could look something like:

  mu4e-get-mail-command "offlineimap"   ;; or fetchmail, or ...
  mu4e-update-interval 300)             ;; update every 5 minutes

A hook mu4e-update-pre-hook is available which is run right before starting the process. That can be useful, for example, to influence, mu4e-get-mail-command based on the the current situation (location, time of day, ...).

It is possible to get notifications when the indexing process does any updates - for example when receiving new mail. See mu4e-index-updated-hook and some tips on its usage in the FAQ.

Next: , Previous: , Up: Getting started   [Contents]