JavaPopper

Description
Fake POP3 mail server that routes mail from KMail.

Why?
Because it scratched an itch. We used to have a demon.co.uk account and that allowed different email address on the same domain to download their individual emails. With my current ISP we get unlimited email addresses but can only download all or nothing.
I got fed up with Sarah wanting to use my machine just for "quick" emails. How?
You are probably familiar with email filters that move incoming emails to specific folders (if not then you missing out a great tool and most email programs do it), well KMail (from KDE has a number of other actions that can be applied to incoming emails. Couple this with ease of developing TCP/IP application with Java and you have a POP3 mail server that can be accessed by another machine on the network via a standard email client. Hmmm sounds complex
Not really, I broke it down into a number of small tasks.

How did you get the emails out of KMail?
I created a filter that the action was set to "Pipe through" instead of the more common "move to folder".
If you 'pipe' a process through another, you are simply redirecting their output, so for a test I put
cat > test.txt
in the "Pipe through" filter action and when the filter matched I ended up with a file called test.txt with the complete email, including all the headers etc.
But of course I needed each email to be saved to a unique file name, mktemp does this and with the shells ability to interpret the output of programs directly I ended up with
cat > `mktemp -p \some\directory\for\keeping\emails\`
note: those are back ticks not single quotes.
if I run
mktemp -p \some\directory\for\keeping\emails\
on its own I end up with a unique temp file in \some\directory\for\keeping\emails\ and the command line shows that new file name. when enclosing it in back ticks the command gets run before the cat and the cat command only sees the filename its output is being redirected to.
i.e. cat > \some\directory\for\keeping\emails\tmp.XXXXiwFpuJ

How did you model an entire POP3 server in Java?
I did the absolute bare minimum to support RFC1939.
The login and authentication are as good as none existent but then only Sarah would be able to connect (firewall keeps everyone else out).
She is using outlook express so I could get away with implementing just seven commands

What problems did you encounter and resolve?
First off was that you have to return a CR/LF pair for the RETR command but outlook express accept a Linux LF on all other commands (RFC makes it clear that on CR/LF should be accepted).
Thunderbird was not playing nicely (but this was before I fixed the CR/LF issue so who knows) and desperately wanted be to implement the extended POP3 commands, but I am lazy so hats never gonna happen.

What now?
Well I am going to make it into a multi-threaded server, meaning I do not have to run it separately each time and I also need to set it up to run on boot.
For the interested you could easily enhance it to check logins and serve only that users email.
Not to mention the extended POP3 commands and command line parameters.

Show me the code
version 1 - single threaded, program ends on connect ending, run as root to serve from standard POP3 port.
version 2 - multi threaded, allows any number of connections.
version 3 - true multi threaded, plays nice with Outlook XP.

email

root




Disclaimer:
This page is by me for me, if you are not me then please be aware of the following
I am not responsible for anything that works or does not work including files and pages made available at www.jumpstation.co.uk I am also not responsible for any information(or what you or others do with it) available at www.jumpstation.co.uk
In fact I'm not responsible for anything ever, so there!