NUL is a string terminator

This was causing valgrind errors, which I guess I should have checked
earlier.  Maybe I should have tests?... :)
Don't attempt to write 0-length outputs

This may be papering over a bigger problem, but for some reason my
base64 decoder appears to sometimes output 0-length decoded outputs.
Obviously they're going to result in 0-length writes, so there's no
reason to fail them when they end up writing nothing.
Automatically determine attachment names

This makes detaching attachments actually feasible...