Fix attachment disposition

This commit is contained in:
M66B 2019-07-06 14:18:14 +02:00
parent 18f0e29437
commit 0fbff8cfdf
2 changed files with 24 additions and 0 deletions

View File

@ -53,6 +53,7 @@ import com.sun.mail.imap.protocol.UID;
import org.json.JSONArray;
import org.json.JSONException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
@ -89,6 +90,7 @@ import javax.mail.FolderNotFoundException;
import javax.mail.Message;
import javax.mail.MessageRemovedException;
import javax.mail.MessagingException;
import javax.mail.Part;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.UIDFolder;
@ -739,6 +741,8 @@ class Core {
parts.isPlainOnly(),
HtmlHelper.getPreview(body),
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 {
@ -1702,6 +1706,7 @@ class Core {
parts.getWarnings(message.warning));
Log.i(folder.name + " downloaded message id=" + message.id +
" 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) {
lastUnseen = -1;
Widget.update(context, -1);

View File

@ -92,6 +92,11 @@ public interface DaoAttachment {
" WHERE id = :id")
void setError(long id, String error);
@Query("UPDATE attachment" +
" SET disposition = :disposition" +
" WHERE id = :id")
void setDisposition(long id, String disposition);
@Query("UPDATE attachment" +
" SET cid = :cid" +
" WHERE id = :id")