Custom Toolbar Buttons for Thunderbird
If you watched the video and wondered what the JavaScript code was for my "Move Junk" button in Thunderbird, then read on. If you haven't watched the video, this article describes how to add custom toolbar buttons to Thunderbird using the Custom Buttons addon.
The Custom Buttons addon for Thunderbird allows you to add buttons to Thunderbird's toolbar. The addon is simple to use: once it's installed, right click on the toolbar and select "Add new button...", give the button a name, pick an image to use, and then supply some JavaScript code for the button. Well, ok so that last step isn't so easy. Since you need to know how to write JavaScript and you need to know the Thunderbird API. Here's a couple of buttons that I use.
The first empties the Trash folder. My image for it is:
The code is simple:
MsgEmptyTrash();
Enter that under the "Code" tab and you should have a button for emptying the trash.
The second button moves all the junk mail in the current folder to the Junk folder. Thunderbird has the option to do this automatically as it downloads email and classifies it as Junk, but I like to see what's going into the Junk folder beforehand so that I have a chance to police Thunderbird's decisions. My image for this button is:
The code here is much more involved, and I didn't develop it from scratch, I used an existing function that I found in the Thunderbird source that deleted junk in the current folder. All I did is change it so that it moves it rather than deletes it.
//=====================================================================
// Modification of deleteJunkInFolder().
//
function junkJunkInFolder()
{
MsgJunkMailInfo(true);
var view = GetDBView();
// Get junk mail folder.
var msgURI = view.getURIForViewIndex(0);
var msgHdr = messenger.msgHdrFromURI(msgURI);
var server = msgHdr.folder.server;
var spamSettings = server.spamSettings;
var spamFolderURI = spamSettings.spamFolderURI;
var currentFolderURI = msgHdr.folder.folderURL
if ( !spamFolderURI ) {
dump('no spam folder!');
return;
}
//alert("Current folder is: " + currentFolderURI + "\nJunk folder is: " + spamFolderURI);
if ( currentFolderURI == spamFolderURI ) {
//alert("Current folder is the Junk folder");
return;
}
var junkTargetFolder = GetMsgFolderFromUri(spamFolderURI);
// Select junk messages.
// Need to expand all threads, so we find everything
view.doCommand(nsMsgViewCommandType.expandAll);
var treeView = view.QueryInterface(Components.interfaces.nsITreeView);
var count = treeView.rowCount;
if ( !count ) return;
var treeSelection = treeView.selection;
var clearedSelection = false;
for ( var i = 0; i < count; ++i ) {
var messageUri = view.getURIForViewIndex(i);
var msgHdr = messenger.msgHdrFromURI(messageUri);
var junkScore = msgHdr.getStringProperty("junkscore");
var isJunk = ((junkScore != "") && (junkScore != "0"));
// if the message is junk, select it.
if ( isJunk ) {
// only do this once
if ( !clearedSelection ) {
// clear the current selection
// since we will be deleting all selected messages
treeSelection.clearSelection();
clearedSelection = true;
treeSelection.selectEventsSuppressed = true;
}
treeSelection.rangedSelect(i, i, true /* augment */);
}
}
// If we didn't clear the selection there was no junk, so bail.
if ( !clearedSelection ) return;
treeSelection.selectEventsSuppressed = false;
// delete the selected messages
SetNextMessageAfterDelete();
view.doCommandWithFolder(nsMsgViewCommandType.moveMessages, junkTargetFolder);
treeSelection.clearSelection();
}
//=====================================================================
junkJunkInFolder();
I won't explain the code in detail, particularily since I didn't write most of it, but the operation is fairly simple: get a reference to the current folder and the junk folder, then loop through all the messages in the current folder and select the junk messages. After the loop if any messages are selected move them to the junk folder.
| Attachment | Size |
|---|---|
| move-junk.png | 1.4 KB |
| empty-trash.png | 1.84 KB |
Mitch Frazier is an Associate Editor for Linux Journal.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
- New Products
- Linux Systems Administrator
- Senior Perl Developer
- Technical Support Rep
- UX Designer
- Web & UI Developer (JavaScript & j Query)
- Designing Electronics with Linux
- Dynamic DNS—an Object Lesson in Problem Solving
- Using Salt Stack and Vagrant for Drupal Development
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?



3 hours 58 min ago
4 hours 14 min ago
6 hours 5 min ago
11 hours 57 min ago
16 hours 29 min ago
16 hours 29 min ago
18 hours 30 min ago
1 day 3 hours ago
1 day 3 hours ago
1 day 4 hours ago