Sanitize incoming attachment mime type

This commit is contained in:
M66B
2019-11-20 12:40:56 +01:00
parent df7b74c456
commit e3aa66d844
2 changed files with 29 additions and 9 deletions

View File

@@ -52,6 +52,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.webkit.MimeTypeMap;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.CheckBox;
@@ -647,6 +648,20 @@ public class Helper {
return filename.substring(index + 1);
}
static String guessMimeType(String filename) {
String type = null;
String extension = Helper.getExtension(filename);
if (extension != null)
type = MimeTypeMap.getSingleton()
.getMimeTypeFromExtension(extension.toLowerCase(Locale.ROOT));
if (TextUtils.isEmpty(type))
type = "application/octet-stream";
return type;
}
static void writeText(File file, String content) throws IOException {
try (FileOutputStream out = new FileOutputStream(file)) {
if (content != null)