|
|
@ -22,7 +22,6 @@ package eu.faircode.email;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.os.Build;
|
|
|
|
import android.os.Build;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.webkit.MimeTypeMap;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.room.Entity;
|
|
|
|
import androidx.room.Entity;
|
|
|
@ -35,7 +34,6 @@ import java.io.IOException;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Locale;
|
|
|
|
|
|
|
|
import java.util.Objects;
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.mail.Part;
|
|
|
|
import javax.mail.Part;
|
|
|
@ -173,26 +171,7 @@ public class EntityAttachment {
|
|
|
|
if (extension == null)
|
|
|
|
if (extension == null)
|
|
|
|
return type;
|
|
|
|
return type;
|
|
|
|
|
|
|
|
|
|
|
|
String gtype = MimeTypeMap.getSingleton()
|
|
|
|
// Fix types
|
|
|
|
.getMimeTypeFromExtension(extension.toLowerCase(Locale.ROOT));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (gtype != null) {
|
|
|
|
|
|
|
|
if (TextUtils.isEmpty(type) || "*/*".equals(type))
|
|
|
|
|
|
|
|
type = gtype;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Some servers erroneously remove dots from mime types
|
|
|
|
|
|
|
|
if (gtype.replace(".", "").equals(type))
|
|
|
|
|
|
|
|
type = gtype;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ("csv".equals(extension))
|
|
|
|
|
|
|
|
return "text/csv";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ("eml".equals(extension))
|
|
|
|
|
|
|
|
return "message/rfc822";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ("gpx".equals(extension))
|
|
|
|
|
|
|
|
return "application/gpx+xml";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ("text/plain".equals(type) && "ics".equals(extension))
|
|
|
|
if ("text/plain".equals(type) && "ics".equals(extension))
|
|
|
|
return "text/calendar";
|
|
|
|
return "text/calendar";
|
|
|
@ -211,17 +190,20 @@ public class EntityAttachment {
|
|
|
|
if ("application/vnd.ms-pps".equals(type))
|
|
|
|
if ("application/vnd.ms-pps".equals(type))
|
|
|
|
return "application/vnd.ms-powerpoint";
|
|
|
|
return "application/vnd.ms-powerpoint";
|
|
|
|
|
|
|
|
|
|
|
|
if (TextUtils.isEmpty(type) ||
|
|
|
|
// Guess types
|
|
|
|
type.startsWith("unknown/") || type.endsWith("/unknown") ||
|
|
|
|
String gtype = Helper.guessMimeType(name);
|
|
|
|
"application/octet-stream".equals(type) || "application/zip".equals(type)) {
|
|
|
|
if (gtype != null) {
|
|
|
|
if ("log".equalsIgnoreCase(extension))
|
|
|
|
if (TextUtils.isEmpty(type) ||
|
|
|
|
return "text/plain";
|
|
|
|
"*/*".equals(type) ||
|
|
|
|
|
|
|
|
type.startsWith("unknown/") ||
|
|
|
|
if (gtype == null || gtype.equals(type))
|
|
|
|
type.endsWith("/unknown") ||
|
|
|
|
return type;
|
|
|
|
"application/octet-stream".equals(type) ||
|
|
|
|
|
|
|
|
"application/zip".equals(type))
|
|
|
|
|
|
|
|
return gtype;
|
|
|
|
|
|
|
|
|
|
|
|
Log.w("Guessing file=" + name + " type=" + gtype);
|
|
|
|
// Some servers erroneously remove dots from mime types
|
|
|
|
return gtype;
|
|
|
|
if (gtype.replace(".", "").equals(type))
|
|
|
|
|
|
|
|
return gtype;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return type;
|
|
|
|
return type;
|
|
|
|