This article is excerpted from Google Hacks, 3rd Edition, by Rael Dornfest, Paul Bausch and Tara Calishain, published August 2006 by O'Reilly Media Inc. Copyright 2006, 2005 and 2003, all rights reserved. Reprinted with permission.
What I wouldn't give for a couple spare gigs of networked filesystem on which to stash a backup of my work in progress or as an intermediary between two firewalled systems (thus, they're not directly reachable from one to the other).
GmailFS puts your gigs of Gmail storage to work for just such a purpose. It provides a mountable Linux filesystem and repurposes your Gmail account as its storage medium.
GmailFS is a Python application that uses the FUSE userland filesystem infrastructure to help provide a filesystem and the libgmail library to communicate with Gmail.
GmailFS supports most file operations, such as read, write, open, close, stat, symlink, link, unlink, truncate and rename. This means you can use the lion's share of your favorite Unix command-line tools (cp, ls, mv, rm, ln, grep, et al.) to operate on files stored on Google's Gmail servers.
So, what can you store on the Gmail filesystem, and what can you do with it? About anything you can with any other (possibly unreliable) networked filesystem built on a cool hack or three. Figure 1 shows the Firefox Web browser launched from an executable stored as a message in my Gmail account.
Figure 1. Reading Gmail via the Firefox Web browser launched from an executable stored on the selfsame Gmail account
Warning: This is my first foray into Python, and I'm sure the code is far from elegant. That said, the language has a reputation as an excellent choice for rapid prototyping — and this was borne out in my experience. The first working version of GmailFS took about two days of coding with an additional day and a half spent on performance tuning and bug fixing. Given that this includes the learning curve of the language itself, the reputation seems well deserved.
A special mention should go to libgmail and FUSE, as both greatly contributed to the short development time.
(I'm particularly concerned with my attempts to manipulate mutable byte arrays. I'm sure there's a less clumsy way of doing it than the nasty list -> array -> string path I'm currently using.)So, do be careful using the GmailFS and certainly don't use it for anything important.