Improved remote file handling with attachments. Fixes #1910.