mirror of https://github.com/M66B/FairEmail.git
Fix attachment disposition
This commit is contained in:
parent
18f0e29437
commit
0fbff8cfdf
|
@ -53,6 +53,7 @@ import com.sun.mail.imap.protocol.UID;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
|
import org.jsoup.nodes.Element;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
|
@ -89,6 +90,7 @@ import javax.mail.FolderNotFoundException;
|
||||||
import javax.mail.Message;
|
import javax.mail.Message;
|
||||||
import javax.mail.MessageRemovedException;
|
import javax.mail.MessageRemovedException;
|
||||||
import javax.mail.MessagingException;
|
import javax.mail.MessagingException;
|
||||||
|
import javax.mail.Part;
|
||||||
import javax.mail.Session;
|
import javax.mail.Session;
|
||||||
import javax.mail.Store;
|
import javax.mail.Store;
|
||||||
import javax.mail.UIDFolder;
|
import javax.mail.UIDFolder;
|
||||||
|
@ -739,6 +741,8 @@ class Core {
|
||||||
parts.isPlainOnly(),
|
parts.isPlainOnly(),
|
||||||
HtmlHelper.getPreview(body),
|
HtmlHelper.getPreview(body),
|
||||||
parts.getWarnings(message.warning));
|
parts.getWarnings(message.warning));
|
||||||
|
|
||||||
|
fixAttachments(context, message.id, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void onAttachment(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, EntityOperation op, IMAPFolder ifolder) throws JSONException, MessagingException, IOException {
|
private static void onAttachment(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, EntityOperation op, IMAPFolder ifolder) throws JSONException, MessagingException, IOException {
|
||||||
|
@ -1702,6 +1706,7 @@ class Core {
|
||||||
parts.getWarnings(message.warning));
|
parts.getWarnings(message.warning));
|
||||||
Log.i(folder.name + " downloaded message id=" + message.id +
|
Log.i(folder.name + " downloaded message id=" + message.id +
|
||||||
" size=" + message.size + "/" + (body == null ? null : body.length()));
|
" size=" + message.size + "/" + (body == null ? null : body.length()));
|
||||||
|
fixAttachments(context, message.id, body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1718,6 +1723,20 @@ class Core {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void fixAttachments(Context context, long id, String body) {
|
||||||
|
DB db = DB.getInstance(context);
|
||||||
|
for (Element element : Jsoup.parse(body).select("img")) {
|
||||||
|
String src = element.attr("src");
|
||||||
|
if (src.startsWith("cid:")) {
|
||||||
|
EntityAttachment attachment = db.attachment().getAttachment(id, "<" + src.substring(4) + ">");
|
||||||
|
if (attachment != null && !attachment.isInline()) {
|
||||||
|
Log.i("Setting attachment type to inline id=" + attachment.id);
|
||||||
|
db.attachment().setDisposition(attachment.id, Part.INLINE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void notifyReset(Context context) {
|
static void notifyReset(Context context) {
|
||||||
lastUnseen = -1;
|
lastUnseen = -1;
|
||||||
Widget.update(context, -1);
|
Widget.update(context, -1);
|
||||||
|
|
|
@ -92,6 +92,11 @@ public interface DaoAttachment {
|
||||||
" WHERE id = :id")
|
" WHERE id = :id")
|
||||||
void setError(long id, String error);
|
void setError(long id, String error);
|
||||||
|
|
||||||
|
@Query("UPDATE attachment" +
|
||||||
|
" SET disposition = :disposition" +
|
||||||
|
" WHERE id = :id")
|
||||||
|
void setDisposition(long id, String disposition);
|
||||||
|
|
||||||
@Query("UPDATE attachment" +
|
@Query("UPDATE attachment" +
|
||||||
" SET cid = :cid" +
|
" SET cid = :cid" +
|
||||||
" WHERE id = :id")
|
" WHERE id = :id")
|
||||||
|
|
Loading…
Reference in New Issue