I know that there is some work coming down the pipe on attachments in the composer, after some of that lands, this function will probably be rewritten to work with that anyway, perhaps we could just tack this refactor in then?