I’ve been toying with building a simple Java spam filter for a while, and last night I actually got things off the ground. First things first, I need to get the stuff off the server, so I had a scout for some POP3 libs. Turns out there’s a few out there, but I figure that JavaMail from Sun has got to be worth a look (and I’ve got Elliotte Rusty Harold’s excellent “Java Network Programming” sitting around with a whole chapter on it).
One of the advantages of going with JavaMail is that the transport is pluggable. I can change between the Pop3 store and the Imap store *relatively* painlessly. The other advantage is that you get serious message parsing for free. Rather than have to do your own parsing of the message contents using RegExp or whatever, Sun have implemented the RFC for you, so you get to recipients as an Address. Loving their work. Need to get to the source contents of the message? Message.writeTo(OutputStream) .. in my case a ByteArrayOutputStream… but whatever. It’s there and it’s good.
The javadoc says that the Message objects I’m getting back are “lightweight” – meaning their contents only gets filled when you make a call against a getter. Not sure if it *really* works like that (maybe for Imap, unlikely for Pop3). Must give it a try.
Anyways, my messages are now downloading. Next step is to get them into a db or filesystem so I can keep them around till in case the engine I develop is too aggressive.