MDL-44257 message: check if the attachment exists before remove it

Credit goes to Mark Nielsen, thanks.
MDL-44257 message: added test to make sure the stored file still exists
MDL-44257 lib: fix the attachment code to accept tempdir and dataroot.

Credit goes to Damyon, thanks.