I just whipped this up, and didn't know who to tell about it, so I figured I'd blog it, and then maybe when it comes up in conversation, I can just say "look on my blog for that."
For quite awhile now, I've had a couple of neat "personal odometers" over on the righthand side of my blog, including my friendster counter, and the number of spam messages I've blocked since May, 2003. That's all done server-side on my systems, generating the number as a little image I then include in my blog template. Cute, and a little elaborate.
It occurred to me that anyone out there with a templatable blog, regardless of how simple, could do the same thing with any of the free web-counters that are available out there, if they're using procmail or mac-mail to filter their mail:
1) sign up for a free counter at a web-counter service. For my example, I used xcounters.com, whom I found using Google. They're pretty easy to set up. Once you've signed up with them, you'll get a chunk of html code that you'd normally put on your web page... don't do that just yet.
2) the chunk of html you're given by xcounters (or any of the other free web-counter services that work in the same way) give you a <img src="http://a.xcounters.com/?userid" > tag (where "userid" is your accountname) that you're supposed to include on your homepage/blog/whateverpage. When you fetch that image, it increments a counter in a database someplace, and then spits back to the requestor a GIF image of that number, which is displayed on your page.
What we want to do is fetch that image, and thereby increment our counter, every time a spam message is caught.
Note that most web counters have a "don't increment" image you can include for "admin" pages or whatever... with xcounters.com, that url is constructed by putting in a "new/" before the question mark, like "http://xcounters.com/new/?userid" (notice that's pulled from a different servername, too, just "xcounters.com", not "a.xcounters.com") ... THIS is the image we want to include on our page. It's also nice to not be a total sponge, and include the links back to xcounters they ask us for, to support their website.
This is what the little number towards the bottom of the http://www.ryan.net page is.
3) Now that you have a non-incrementing counter on your web page, we want to increment it by requesting that first url, the one that looks like "http://a.xcounters.com/?userid" , every time we receive some spam.
3a) if you're on unix, using procmail, you're golden... in your .procmailrc file, where you'd normally have a rule like
:0 * ^X-Spam-Status: Yes /home/ryan/mail/spam...change that to
:0c * ^X-Spam-Status: Yes /home/ryan/mail/spam :0 * ^X-Spam-Status: Yes | /usr/bin/curl "http://a.xcounters.com/?userid" 2>&1 > /dev/null
....if you can't find "curl" installed on your unix system, try replacing that with "wget -q -O - "
...this should result in a copy of each spam message (that's flagged by spamassassin with the "X-Spam-Status: Yes" header) getting piped into the command-line URL-getter (either curl or wget)... they ignore the input of your message, but they hit that URL, which increments the counter image, and bingo, your spam count goes up by one.
3b) if you're not on unix and procmail, but you use something like Mac Mail, you're still in luck.
If (on your mac, running osX) you fire up "Script Editor", and enter:
do shell script "curl -si \"http://a.xcounters.com/?userid\" 2>&1 > /dev/null
...into the window, and click "run", you should notice your counter increment by one in your browser (upon reloading the page)
Save this AppleScript as a script, and name it something like "spam-increment.scpt", in your homedir.
In Mac Mail, under "Preferences...", under the "Rules" tab, add a rule. Name the rule "spam-counter increment"
Under the conditions, you can select "Message is Junk Mail"
Under "Perform the following actions:", select "Run Applescript", and then use the "choose..." button to select the small applescript you just saved.
That's it... every time that script is called now, your mac (or procmail system) should go out and hit that url, and increment your spam counter, greatly improving your blog's blinkenlights quotient.
questions, comments to email@example.com...