Automated EPUB production?

I am writing an agent to automatically create an epub version of our phone directory and mail it to users who request it for use with their iPads, iPhones, Nooks, etc.

The epub format is nothing but a bunch of HTML files, a TOC.NCX file, a content.opf file, a style.css file and a cover.jpg file. I have the code that is generating all of these things automatically.

The problem is that all of these components have to be put into a ZIP file and then the extension changed to .EPUB and I can’t figure out how to do this automatically from within the agent.

Any ideas?