December 20, 2003
super-simple spam counter

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, 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="" > 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, that url is constructed by putting in a "new/" before the question mark, like "" (notice that's pulled from a different servername, too, just "", not "") ... 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 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 "" , 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

     * ^X-Spam-Status: Yes
...change that to
     * ^X-Spam-Status: Yes
     * ^X-Spam-Status: Yes
     | /usr/bin/curl "" 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 \"\" 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

Posted by ryan at December 20, 2003 01:07 AM


Nice idea - did it for my weblog too.

Posted by: Thomas on January 12, 2004 12:31 PM
Post a comment

Email Address:



Remember info?

type this number in, to prove you're human, and not some spam-robot: