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.

OfflineIMAP
First, here is my ~/.offlineimaprc configuration:

[general]
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 = imap.gmail.com
remoteuser = your_gmail_login@gmail.com
remotepass = your_gmail_password
ssl = yes
realdelete = no

To fire off OfflineIMAP, I use a cronjob:

*/5 * * * * $HOME/bin/cron-run-offlineimap.sh

And my ~/bin/cron-run-offlineimap.sh looks like this:

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

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.

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

#!/bin/sh
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. Trackbacks are closed, but you can post a comment.
  • Archives


semidetached
semidetached
semidetached
semidetached