free hit counter


My Links
Java J2EE Practise
Windows Tips
Windows XP Tips
Troubleshooting Tips
AMCP Tech Blog
Techno-Freek
Technology News Etc
Xtreme Hacking Tips
Showcase for New Blogs

Downloads
Click here to download latest softwares from Amazon.

Software

Sunday, March 06, 2005

Adding Persistent Searches to Gmail

As told by the creator....
Persistent searches (a.k.a. smart folders or saved searches) seem to be the feature du jour of email clients. Thunderbird has them, Evolution has them, and Mail.app soon will. On the other hand, Gmail is the web mail app to use. While one doesn't normally think of web apps as having such advanced power user features, it recently occurred to me that it should be possible to add persistent searches to Gmail:


If you haven't already, install the excellent greasemonkey Firefox extension.
Open up this user script (in Firefox).
From the "Tools" menu, select "Install User Script.." and confirm all of the various prompts.
Go to your Gmail account (some refreshing may be necessary).
There should now be a "Searches" box on the left size, below the "Labels" and "Invite a friend" ones.
Clicking on a search executes the saved query. To refresh result counts, click on the refresh icon in the upper right corner.
Use the "Edit searches" link to customize your persistent searches.
As a bonus feature, all threads now have a "Toggle font" link which switches the message font to a fixed size one - great for reading source code.
There are some caveats. Saved searches are stored in a cookie. This means that you cannot easily share them between computers. Ideally this could be remedied by storing the searches within Gmail itself (perhaps as a dummy contact or a special filter), but I'm not quite sure how to do that yet. Furthermore, result counts may not be accurate beyond a certain limit (e.g. Gmail itself reports "about 80" results when there are in fact 77). In general, the smaller the result size, the more accurate the search is.

The user script has a pretty straightforward implementation. It looks for the "Labels" box, and if it finds one, it inserts a "Searches" one. As previously mentioned, I store all the searches in a cookie. To actually perform a search, I created a an XMLHttpRequest object and use it to fetch the search results for each saved search. The response contains in it the total number of messages that matched the query. It would've been nice to use the DOM (and then a JavaScript eval()) to parse it, but this turned out to be more difficult than expected (XMLHttpRequest only provides a parsed DOM for XML documents).

Rather than specifying all of the CSS properties inline or via the JavaScript style object, an approach which separated appearance from structure was used. Effectively, a style sheet was embedded into the user script and inserted upon initialization. This style sheet was also used for the toggling of the font (the message body always appears to be in a <div> of class mb). It also has the advantage of making the script self-contained, since it doesn't depend on an external CSS file. Also for the same goal of encapsulation, the font toggling icon was embedded in the script itself via a data: URL (generated with hixie's tool).

Google for Related Stuff:

0 Comments:

Post a Comment

<< Home