Triggering mail collection

Gaute Hope edited this page Sep 29, 2015 · 5 revisions
Clone this wiki locally

How to get sup to collect mail from remote servers. ~/.sup/hooks/before-poll.rb

  File: ~/.sup/hooks/before-poll.rb
  Executes immediately before a poll for new messages commences.
  No variables.

Run fetchmail before polling for new messages:

if (@last_fetchmail_time || < - 60
  say "Running fetchmail..."
  system "fetchmail > /dev/null 2>&1"
  say "Done running fetchmail."
@last_fetchmail_time =

A similar example for offlineimap:

def offlineimap(*folders)
  cmd = "offlineimap -q -u Noninteractive.Basic"
  cmd << " -f #{folders * ','}" unless folders.compact.empty?
  `#{cmd} 2>&1`

def folder_names(sources) { |s| s.uri.split('/').last }

def inbox_sources(sources = Index.usual_sources)
  sources.find_all { |s| !s.archived? }.sort_by {|s| }

if (@last_fetch || < - 120
  say "Running offlineimap..."
  # only check non-auto-archived sources on the first run
  log offlineimap(@last_fetch ? nil : folder_names(inbox_sources))
  say "Finished offlineimap run."
@last_fetch =

A suggestion for before-poll.rb on a laptop

If your internet connection comes and goes like when you are using a laptop, you may want to check for internet connectivity before running offlineimap. A simple (but probably not foolproof) way of doing this is as follows


system "ping -c2 &> /dev/null"

if $? == 0
  say "Running offlineimap..."
  system "offlineimap", "-o", "-u", "quiet"