8

I'm thinking about switching to mutt for email. However, I have a few requirements.

  1. I'd like to be able to store the email offline.
  2. I'd like to have email pushed immediately to my local computer as opposed to periodic polling (e.g. using IMAP IDLE).

For offline storage, I could use imapoffline or isync. I understand that the latter is more stable. However, to have email pushed on demand, the only option I've found for isync is mswatch. Unfortunately, this requires a program to be installed on the remote email server, which is not possible. Is there a solution that will allow me to use mutt, with offline email storage and instant email delivery?

  • have you considered asking your email server's sysadmin? – cas Sep 22 '15 at 1:02
  • @cas Yes, but I figured it might be simpler and quicker to just test it myself. And a more "definitive" answer, since it's probably a rare case. – Sparhawk Sep 22 '15 at 1:04
  • you should ask them anyway because they may object to you installing mswatch or other software on their server – cas Sep 22 '15 at 1:05
  • @cas Perhaps I misunderstand, but I thought that mswatch was only installed locally. – Sparhawk Sep 22 '15 at 1:07
  • 1
    the mswatch web site says "mswatch monitors mailstores for changes by running itself on both the client and server (shell access to each is required)". i presume that means it needs to be installed on both. – cas Sep 22 '15 at 1:15
5

The only way to 'push' mail immediately to your client is for the server to do it as soon as the mail is delivered. This will inevitably require software to be installed and run on the mail server, so every potential solution is going to have the same problem as mswatch.

Frequent polling is probably your best option.

In my experience, running offlineimap or similar from cron every few minutes works well enough.

Some imap-fetching programs support the imap IDLE command. IDLE is not exactly 'push' (since the mail is still pulled from the server by the client) but generally results in almost instant updates to your local mailbox.

offlineimap supports it but the manual says "IDLE support is incomplete and experimental. Bugs may be encountered."

fetchmail supports IDLE since version 5.0

  • Perhaps (again) I misunderstand. Currently with Thunderbird, I can set it to "Use IDLE command if the server supports it". I think this sets up a permanent connection with the email server, so that email delivery is instant. This works fine out-of-the-box for my email servers (NetOrigin, Gmail, mail.com, etc.). – Sparhawk Sep 22 '15 at 1:41
  • yes, that's true. but practically there's little or no difference to the end user - IDLE keeps a connection open (using resources such as file descriptors on the server), and polling connects & disconnects frequently. there's slightly more overhead with polling, but if your mail server can't cope with that then there are larger problems for the sysadmins to solve. – cas Sep 22 '15 at 1:44
  • BTW, offlineimap has some support for IDLE but the manual says "IDLE support is incomplete and experimental. Bugs may be encountered." – cas Sep 22 '15 at 1:48
  • In my experience IDLE has (at most) a few seconds delay before fetching the email. OTOH, many email clients have a default polling time of the order of ~5 minutes. I'd imagine that setting it to (say) 10 seconds would not be ideal. From searching the web, an early hit says Don't set the automatic send/receive interval too short [less than 5 minutes] or you could end up endlessly polling the mail server, send/receive errors and sometimes even duplicates (although this is for a specific client). – Sparhawk Sep 22 '15 at 1:50
  • fetchmail also supports IDLE since v5.0 fetchmail.info/fetchmail-features.html – cas Sep 22 '15 at 1:51
4

Unfortunately, the two possibilities suggested in the other answer were imperfect. offlineimap was fairly buggy at the best of times. For example, there is no way to automatically run a script after new mail arrives. fetchmail doesn't synchronise bidirectionally.

Instead, the solution that I ended up using was a combination of imapnotify and isync. I configured imapnotify to run a script when new mail is triggered (via IDLE).

This script runs mbsync "${channel}:INBOX" depending on which account has mail. Next it runs notmuch new. Finally, it records the number of unread emails to a file as below. The contents of this file is displayed on a panel of my desktop environment.

mail_count_file="/home/foo/.cache/new_mail_count"
new_count=$(find ~/.mail/*/Inbox/new -type f | wc -l)
if [[ $new_count > 0 ]]; then
  echo $new_count > "$mail_count_file"
else
  if [[ -f "$mail_count_file" ]]; then
    rm "$mail_count_file"
  fi
fi

Update

imapnotify (nodejs-imapnotify) disconnects regularly with no warnings/errors, and often misses new mail. python-imapnotify also works intermittently. However, goimapnotify works very well in my experience. It rarely drops out, and when it does (e.g. because of network disconnects and/or suspend cycles), it quickly restarts itself without fuss.

  • You can run a script immediately after mail arrives with offlineimap: using the postsynchook option in the config; that is how I run notmuch new... – jasonwryan Oct 4 '15 at 7:02
  • @jasonwryan Is that for IDLE specifically? I'm not 100% if I understand correctly, but this says "No hook exists for “run after an IDLE response”. Email will show up, but may not be processed until the next refresh cycle." – Sparhawk Oct 4 '15 at 7:23
  • No, I don't use Idle... – jasonwryan Oct 4 '15 at 7:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.