Set the right extension on saving an attachment

For issue #276