How-To Backup Gmail with OfflineImap

Gmail’s content can be retrieved via IMAP, and we’ll use this way to backup all our mails thanks to OfflineImap, a generic IMAP synchronization utility.

Let’s start by creating a dedicated configuration file in your home directory. Its content is quite straight-forward, as you can see in my /home/kevin/.offlineimaprc, which backup two Gmail accounts:

[general]
accounts = gmail_account1, gmail_account2
maxsyncaccounts = 3
ui = Noninteractive.Basic

[Account gmail_account1]
localrepository = gmail_account1_local
remoterepository = gmail_account1_remote

[Repository gmail_account1_local]
type = Maildir
localfolders = ~/gmail-backup-account1

[Repository gmail_account1_remote]
type = IMAP
remotehost = imap.gmail.com
remoteport = 993
remoteuser = account1@gmail.com
remotepass = XXXXXXXX
ssl = yes
maxconnections = 1
realdelete = no
folderfilter = lambda foldername: foldername not in ['[Gmail]/%s' % f for f in ['All Mail', 'Trash', 'Spam', 'Starred', 'Important']]

[Account gmail_account2]
localrepository = gmail_account2_local
remoterepository = gmail_account2_remote

[Repository gmail_account2_local]
type = Maildir
localfolders = ~/gmail-backup-account2

[Repository gmail_account2_remote]
type = IMAP
remotehost = imap.gmail.com
remoteport = 993
remoteuser = account2@gmail.com
remotepass = XXXXXXXX
ssl = yes
maxconnections = 1
realdelete = no
folderfilter = lambda foldername: foldername not in ['[Gmail]/%s' % f for f in ['All Mail', 'Trash', 'Spam', 'Starred', 'Important']]

Notice how we use a Python lambda expressions to filter out some Gmail’s virtual folders.

Then all you have to do is to launch the offlineimap command-line itself with the right user, for example in a cron job:

00 20 * * * kevin offlineimap

A final warning: OfflineImap is fully bi-directional. This mean local deletion propagates to the remote server. This is can be quite dangerous so be careful not touching your local folders. If for any reason you’d like to reset your backups, stop OfflineImap processes first, then remove its cache folder (~/.offlineimap/) before removing the local folders themselves (~/gmail-backup-account*).

Also, intensively playing with OfflineImap to adjust its configuration may trigger the infamous Gmail’s “Temporary Error 500″. In this case don’t panic: it seems to be a common Gmail’s auto-immune response against suspect activity. It happened to me and in the end my account and mails were safe: I just had to wait a few hours to let it resume normal operations.

Increase OpenERP 6.0 web-client session timeout

Another week working with OpenERP means another trick learned to answer some intricate customer’s needs.

Today I was asked to keep users logged-in on OpenERP’s 6.0 web client. The latter being powered by CherryPy, it was a matter of adding the following configuration directive in the web client configuration file to increase the session timeout:

tools.sessions.timeout = 720

Now this will keep any client sessions opened for 12 hours (12h * 60 minutes = 720 minutes) before expiring. This is enough to keep employees not complaining about having to login to OpenERP several times a day.

Problem solved !

Oh, and another way to address this issue consist in implementing some kind of Single Sign-On. And you know what ? We have that in store thanks to the smile_sso module for OpenERP ! :)

How-to add a warning banner to OpenERP’s web client

When working with multiple OpenERP instances in different stages, you can be sure your customer will one day mix up your pre-production and production instance, which can have catastrophic effects.

A quick and dirty hack to prevent such events is to add a hard-coded warning message to all content produced by OpenERP:

The result above was produced on OpenERP 6.0 thanks to the following patch on the header.mako template file:

--- addons/openerp/controllers/templates/header.mako.orig       2012-02-20 11:13:08.228864937 +0000
+++ addons/openerp/controllers/templates/header.mako    2012-02-20 11:12:41.361480113 +0000
@@ -115,3 +115,18 @@
         });
     });
 </script>
+
+<!-- Custom header banner -->
+</tr><tr>
+<style type="text/css">
+    #warning-banner {
+        background-color: #c00;
+        color: #fff;
+        text-align: center;
+        font-weight: bold;
+        padding: 0.6em;
+    }
+</style>
+<td id="warning-banner" colspan="3">
+    <p>Warning: this is a pre-production OpenERP instance.</p>
+</td>

Check Point’s SNX client on Ubuntu 11.04

Last month I had no other alternative but to reach a server through a Check Point‘s VPN. Fortunately the editor provides a Linux client to access its proprietary stack.

The version I found to work on my Ubuntu 11.04 is the SSL Network Extender (SNX) R71 package that can be downloaded there (source).

Just for reference, the build working for me is numbered 800005013, and here is a copy of what to expect when the connection succeed:

$ snx -s vpn.example.net -u my_user
Check Point's Linux SNX
build 800005013
Please enter your password:

SNX - connected.

Session parameters:
===================
Office Mode IP      : 10.32.10.23
DNS Server          : 10.168.10.1
Secondary DNS Server: 10.168.10.2
Timeout             : 3 hours