The explanation is not clear about what to do with extensions > 10 characters.
What did work for my code and made me jump from 95% to 100% is creating the list of mime types, include EXT but truncate them to the FIRST 10 characters.
When searching the filenames extension also check only the first 10 characters of the filename extension you find.
Your code should map
“verylongex” mime-type to “text/longextensiontext”
and check the filename extension “.verylongextension” as “verylongex” thus find the appropriate mime-type.