Fix stupid inversion
Implement changes discussed in #1821
Made some changes to respect the old logic of the setAttachments method
Cherry-picked 4e54cabc5147e3b9e21d640627fd13a0bd3750c2
Make sure all changes from 4e54cabc5147e3b9e21d640627fd13a0bd3750c2 were brought back