Uploading Files and Sending MIME Mail
By Randal L. Schwartz
Most of us have a junk drawer in our house. You know, the one with the random bits of discarded stuff we hope will come in handy in the future, like the last part of a roll of duct tape, a couple of nuts and washers that for some reason weren't needed when we reassembled the shelves this time, and so on. When something needs to get done, we rummage through the drawer looking for the right part or widget, only to pass the same useless items time after time. But every once in a while we find something that's actually useful and we think, "Yeah, I'm so glad I saved that!"
Well, as a software toolsmith, I have a virtual junk drawer as well. I collect little snippets of code that I see float by, in hopes of reassembling them into some useful tool someday. Recently, I needed to do some file uploads as well as learn how to send MIME mail; three snippets I'd happened to save came together in such a nice way that I thought I'd share the program with you. Of course, you can take the program as is, but I hope you instead throw this program into your virtual junk drawer so that if anyone asks you to upload a file, send a MIME attachment, or strip a MacBinary resource fork, you'll find these gems in your drawer.
So, this month we'll do some simple tasks in a nice way. Upload a file, send it as email somewhere. And if the file happens to be uploaded as a MacBinary encapsulated file, we'll even extract the data fork, if requested. And that brings us to the program in
|