"So long as the specific code used to implement a method is different, anyone is free under the Copyright Act to write his or her own code to carry out exactly the same function or specification of any methods used in the Java API. It does not matter that the declaration or method header lines are identical. Under the rules of Java, they must be identical to declare a method specifying the same functionality -- even when the implementation is different. When there is only one way to express an idea or function, then everyone is free to do so and no one can monopolize that expression."
Groklaw also has a PDF version of the ruling if that's easier to read.
If you'd like to do this with an agent instead, here's some LotusScript that will give you the same sort of output:
There's a function in there that writes the MIME boundaries a little differently than the rest of the MIME content. I wrote this a long time ago so I can't remember exactly what the condition was where this was necessary, but I do remember that my Mac client was sometimes generating invalid UTF-8 output if I didn't do that. It could be a Mac-specific or version-specific thing, or it could be one of those things that never happens to anyone but me. I don't know. Feel free to take that part out and try without it if you're curious.
Anyway, I thought I published this a while back but I can't seem to find it anywhere, so there you go.