Autoupdate Thunderbird Signature with Your Latest WordPress Post
Tuesday, August 18th 2009Here's dirty hack for sh*ts and giggles. Ever get bored of having the same old signature line in Thunderbird? Instead of a stale link back to your blog, why not have a link to the latest post on your blog?
Note: In order for this setup to work, you need to have PHP installed locally. If you webdev, this will be easy.
So this is what we're going to do: First, we'll write a quick local PHP script that parses the RSS feed of your blog, to get the latest blog post's URL and title. Then, we'll save that information to a .txt file, which you will set as your signature in Thunderbird. Finally, we'll write .vbs and .bat files that will open your script, update the .txt file, and then close themselves as your computer boots. All you need is a text editor to do this.
First, download this RSS parser and drop it in a folder in your webdev directory. Next, create a file in the same folder called signature-get.php, with the following code:
<?php
$doc = new DOMDocument();
$doc->load('http://www.dquinn.net/feed/');
$titles = array();
$permalink = array();
foreach ($doc->getElementsByTagName('item') as $node) {
$titles[] = $node->getElementsByTagName('title')->item(0)->nodeValue;
$permalink[] = $node->getElementsByTagName('link')->item(0)->nodeValue;
}
$titles[0] = str_replace("’","'",$titles[0]);
$titles[0] = str_replace("“",'"',$titles[0]);
$titles[0] = str_replace("”",'"',$titles[0]);
$signature .= $titles[0] . "\n";
$signature .= $permalink[0] . "\n\n";
$signature .= "read more @ http://www.dquinn.net"."\n";
$sigfile = "Signature.txt";
$fh = fopen($sigfile, 'w') or die("can't open file");
$sigtext = $signature;
fwrite($fh, $sigtext);
fclose($fh);
?>
Be sure to replace my URL and feed with your own. This was written for a WordPress feed, but with minimal tweaking it should work with any valid RSS. Next, make a blank signature file—mine is called "Signature.txt"—in the same folder. This is what the PHP script will write to. You must assign this file as your signature in Thunderbird, like so:

Thunderbird account settings
At this point, if you run the script from your local webserver, you should find that your Signature.txt gets updated with the latest blog post, like so:
District 9 is Good Science Fiction; Neill Blomkamp Raises the Bar http://www.dquinn.net/district-9-neill-blomkamp-raises-the-bar/ read more @ http://www.dquinn.net
Now we need to run this guy whenever we start our comp, because we are lazy. We don't want a browser window to open up and stay open when we start up the computer (because that's annoying), so we'll command Internet Explorer to open the URL of our script in the background (I do love ordering IE around to do mundane, non-webpage-related tasks. Since the web is clearly not it's specialty...):
Create a .vbs file in the same folder, called "IE.vbs." (I scrubbed this code from a forum.) Put the following in it:
Option Explicit
Dim objIEA
Set objIEA = CreateObject("InternetExplorer.Application")
objIEA.Navigate "http://localhost/thunderbird/signature-get.php"
While objIEA.Busy
Wend
Set objIEA = Nothing
Okay, so far so good. Make sure that the path "http://localhost/thunderbird/signature-get.php" matches the path to your script on your local webserver. Next, let's run IE.vb in a batch file. Call this guy "update.bat" and save it in the same folder you've saved everything else:
@ECHO OFF :1 echo >wait.vbs wscript.sleep 30000 cscript wait.vbs del wait.vbs cscript.exe IE.vbs exit
The "exit" may or may not be necessary. Too lazy to double-check. What's happening here is that we create a .vbs script that waits for 30 seconds and then gets deleted after the wait, effectively delaying our setup long enough for your webserver to kick in, before our PHP script runs.
Finally, drag and drop a shortcut to update.bat into your Startup folder in the Start Menu, and you're good to go. At startup, the command window will stay open for a few seconds while the script runs, and then go away by itself.
Obviously, there are better ways to go about doing this, but this works great for me, so I thought I'd share.
