Blog Post

OfflineIMAP and Byobu hacks

Just a quick post showing a couple of hacks I have done using OfflineIMAP and Byobu on my server. I use OfflineIMAP to download my email from GMail and then use Mutt to read that email. I use Byobu on my server because I run Irssi, Mutt, and a shell, and of course Byobu makes this easy. So here we go.

First, here is my ~/.offlineimaprc configuration:

metadata = ~/.offlineimap
accounts = GMAIL
maxsyncaccounts = 1
ui = Noninteractive.Quiet
[Account GMAIL]
localrepository = LocalGmail
remoterepository = RemoteGmail
[Repository LocalGmail]
type = Maildir
localfolders = ~/.maildb/GMAIL
#restoretime = no
[Repository RemoteGmail]
type = Gmail
remotehost =
remoteuser =
remotepass = your_gmail_password
ssl = yes
realdelete = no

To fire off OfflineIMAP, I use a cronjob:

*/5 * * * * $HOME/bin/

And my ~/bin/ looks like this:

ps aux | grep "\/usr\/bin\/offlineimap"
if [ $? -eq "0" ]; then
    logger -i -t offlineimap "Another instance of offlineimap running. Exiting."
    exit 0
    logger -i -t offlineimap "Starting offlineimap..."
    chmod +x $HOME/.byobu/bin/1234_OFFLINEIMAP
    logger -i -t offlineimap "Done offlineimap..."
    chmod -x $HOME/.byobu/bin/1234_OFFLINEIMAP
    exit 0

You can see that this script changes the file mode bits to executable when it runs, and removes the executable bit when it finishes, on the ~/.byobu/bibn/1234_OFFLINEIMAP file which is a Byobu script.

Here is what ~/.byobu/bin/1234_OFFLINEIMAP looks like:

printf "\005{= rw}IMAP\005{-}"

So now every time my OfflineIMAP cronjob runs, I will get IMAP in my Byobu bar.

A super simple hack that lets me know when OfflineIMAP is running. Another reason I use this is because sometimes OfflineIMAP hangs, and when it does, I will know this if IMAP stays displayed in Byobu after a minute or so. Then I can check /var/log/syslog to see exactly when OfflineIMAP started. Normally OfflineIMAP runs for about a minute on my server every check. This could all be streamlined into one script as well with Byobu, but I know you don’t want to fire off processes or other things that may cause resource hogging.

This entry was posted in Application and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.
  • Mariano

    Nice! One little comment though: I use the following script [1] to store my remote server password in the gnome-keyring.


  • Dustin Kirkland


    I’m curious about the ‘1234’ timer… You only want this to run once every 20 minutes?


  • nixternal

    Not really using the timer here, as when it gets made executable it runs. Before it reaches 1234 seconds the executable bit is removed. Also, another reason is I had it at like 1000_ or 2000_, can’t remember, and when I would change anything in the script and run it, it wouldn’t show the changes. When I changed the 1000_ to 1234_ it worked for me then, so it just stuck :)

  • Subscribe to

     Subscribe in a reader

    Or, subscribe via email:
    Enter your email address:

  • Archives

%d bloggers like this: