MCPcopy Create free account
hub / github.com/M66B/FairEmail / guessMimeType

Method guessMimeType

app/src/main/java/eu/faircode/email/Helper.java:2920–2954  ·  view source on GitHub ↗
(String filename)

Source from the content-addressed store, hash-verified

2918 }
2919
2920 static String guessMimeType(String filename) {
2921 String type = null;
2922
2923 String extension = Helper.getExtension(filename);
2924 if (extension != null) {
2925 extension = extension.toLowerCase(Locale.ROOT);
2926
2927 if (extension.endsWith(")")) {
2928 int p = extension.lastIndexOf('(');
2929 if (p > 0 && p < extension.length() - 1)
2930 if (TextUtils.isDigitsOnly(extension.substring(p + 1, extension.length() - 1)))
2931 extension = extension.substring(0, p).trim();
2932 }
2933
2934 type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
2935 }
2936
2937 if (TextUtils.isEmpty(type))
2938 if ("csv".equals(extension))
2939 return "text/csv";
2940 else if ("eml".equals(extension))
2941 return "message/rfc822";
2942 else if ("gpx".equals(extension))
2943 return "application/gpx+xml";
2944 else if ("log".equals(extension))
2945 return "text/plain";
2946 else if ("ovpn".equals(extension))
2947 return "application/x-openvpn-profile";
2948 else if ("mbox".equals(extension))
2949 return "application/mbox"; // https://tools.ietf.org/html/rfc4155
2950 else
2951 return "application/octet-stream";
2952
2953 return type;
2954 }
2955
2956 static String guessExtension(String mimeType) {
2957 String extension = null;

Callers 11

getMetadataMethod · 0.95
getScaledBitmapMethod · 0.95
_decodeImageMethod · 0.95
onTextContextMenuItemMethod · 0.95
getInfoMethod · 0.95
filterMethod · 0.95
decodeCompressedMethod · 0.95
decodeTNEFMethod · 0.95
decodeOutlookMethod · 0.95
getMessagePartsMethod · 0.95
getMimeTypeMethod · 0.95

Calls 5

getExtensionMethod · 0.95
trimMethod · 0.80
lengthMethod · 0.45
isEmptyMethod · 0.45
equalsMethod · 0.45

Tested by

no test coverage detected