Refactor copying attachments forward to a new revision.

This also fixes the potential bug of not escaping filenames