Improved remote file handling with attachments. First steps in fixing #1910