Deal better with uppercase extensions
Don't use mimetypes.guess_extension for extensions
Use mimetypes instead of extensions where possible