Resort search results in SquirrelMail
Apart from an IMAP/POP service we provide a webmail front end to interact with our mail server via SquirrelMail. This tool has a very annoying feature, search results are ordered by date, but in the wrong way: From old to new!
SquirrelMail is a very simple to administrate front end, not very nice, but if my experimental icedove doesn’t work I use it too. Furthermore we have staff members, who only use this tool and aren’t impressed by real user-side clients like icedove or sylpheed.. What ever, I had to resort these search results!
Searching for a solutions doesn’t result in a solution, so I had three options: Modifying the SquirrelMail code itself (very bad idea, I know), providing a plugin for SquirrelMail, or writing a userscript.
Ok, hacking the core of SquirrelMail is deprecated, writing a plugin is to much work for now, so I scripted some JavaScript.
The layout of this website is lousy! I think the never heard of div’s or CSS, everything is managed by tables in tables of tables and inline layout specifications -.-
So detecting of the right table wasn’t that easy. I had to find the table that contains a headline with the key From
:
var tds = document.getElementsByTagName ('td');
var table = 0;
for (var i = 0; i < tds.length; i++)
{
if(tds[i].innerHTML.match(/^\\s*<b>From<\\/b>\\s*$/))
{
table = tds[i].parentNode.parentNode;
break;
}
}
If I’ve found such a table, all the rows have to be sorted from last to first. Except the first ones defining the headline of that table. So I modified the DOM:
if (table)
{
var old = table.cloneNode (true);
var tru = false;
var oldi = old.childNodes.length - 1;
var tablelen = table.childNodes.length;
for (var i = 0; i < tablelen; i++)
{
// don't sort the head to the end...
if (!tru)
{
if (table.childNodes[i].innerHTML && table.childNodes[i].innerHTML.replace(/\\n/g,'').match (/<b>From<\\/b>.*<b>Date<\\/b>.*<b>Subject<\\/b>/))
tru = true;
continue;
}
table.replaceChild (old.childNodes[oldi--], table.childNodes[i]);
}
}
Ok, that’s it! Using this script the search results are ordered in the correct way. Let’s wait for a response from these nerdy SquirrelMail-user ;-)
- hacked (25) ,
- mail (11) ,
- network (81) ,
- programming (75) ,
- thunderbird (6) ,
- icedove (6) ,
- ugly (26) ,
- university (42) ,
- userscript (6)
Leave a comment
There are multiple options to leave a comment: