OfflineIMAP and Byobu hacks

October 18th, 2010  |  Published in FYI, Tutorial  |  3 Comments

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.

Responses

  1. Mariano says:

    October 18th, 2010 at 15:34:57 (#)

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

    [1] http://club-ubuntu.pastebin.com/ST7wQBtg

  2. Dustin Kirkland says:

    October 20th, 2010 at 09:07:14 (#)

    Nice!

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

    ustin

  3. nixternalNo Gravatar says:

    October 20th, 2010 at 11:08:43 (#)

    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 :)

Leave a Response

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">