|
|
|
@ -63,7 +63,6 @@ import java.util.TimeZone;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
import javax.activation.DataHandler;
|
|
|
|
|
import javax.activation.DataSource;
|
|
|
|
|
import javax.activation.FileDataSource;
|
|
|
|
|
import javax.activation.FileTypeMap;
|
|
|
|
|
import javax.mail.Address;
|
|
|
|
@ -499,48 +498,59 @@ public class MessageHelper {
|
|
|
|
|
Document document = JsoupEx.parse(message.getFile(context));
|
|
|
|
|
|
|
|
|
|
// When sending message
|
|
|
|
|
List<BodyPart> contents = new ArrayList<>();
|
|
|
|
|
if (identity != null) {
|
|
|
|
|
document.select("div[fairemail=signature],div[fairemail=reference]").removeAttr("fairemail");
|
|
|
|
|
|
|
|
|
|
for (Element img : document.select("img")) {
|
|
|
|
|
String source = img.attr("src");
|
|
|
|
|
if (!source.startsWith("content:"))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
String cid = BuildConfig.APPLICATION_ID + ".content." + contents.size();
|
|
|
|
|
img.attr("src", "cid:" + cid);
|
|
|
|
|
|
|
|
|
|
final Uri uri = Uri.parse(source);
|
|
|
|
|
final DocumentFile dfile = DocumentFile.fromSingleUri(context, uri);
|
|
|
|
|
|
|
|
|
|
BodyPart part = new MimeBodyPart();
|
|
|
|
|
part.setFileName(uri.getLastPathSegment());
|
|
|
|
|
part.setDisposition(Part.INLINE);
|
|
|
|
|
part.setHeader("Content-ID", "<" + cid + ">");
|
|
|
|
|
part.setDataHandler(new DataHandler(new DataSource() {
|
|
|
|
|
@Override
|
|
|
|
|
public InputStream getInputStream() throws IOException {
|
|
|
|
|
return context.getContentResolver().openInputStream(uri);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public OutputStream getOutputStream() throws IOException {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getContentType() {
|
|
|
|
|
return dfile.getType();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getName() {
|
|
|
|
|
return uri.getLastPathSegment();
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
|
try {
|
|
|
|
|
db.beginTransaction();
|
|
|
|
|
|
|
|
|
|
for (Element img : document.select("img")) {
|
|
|
|
|
String source = img.attr("src");
|
|
|
|
|
if (!source.startsWith("content:"))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
Uri uri = Uri.parse(source);
|
|
|
|
|
DocumentFile dfile = DocumentFile.fromSingleUri(context, uri);
|
|
|
|
|
if (dfile == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
String name = dfile.getName();
|
|
|
|
|
String type = dfile.getType();
|
|
|
|
|
|
|
|
|
|
if (TextUtils.isEmpty(name))
|
|
|
|
|
name = uri.getLastPathSegment();
|
|
|
|
|
if (TextUtils.isEmpty(type))
|
|
|
|
|
type = "image/*";
|
|
|
|
|
|
|
|
|
|
EntityAttachment attachment = new EntityAttachment();
|
|
|
|
|
attachment.message = message.id;
|
|
|
|
|
attachment.sequence = db.attachment().getAttachmentSequence(message.id) + 1;
|
|
|
|
|
attachment.name = name;
|
|
|
|
|
attachment.type = type;
|
|
|
|
|
attachment.disposition = Part.INLINE;
|
|
|
|
|
attachment.cid = null;
|
|
|
|
|
attachment.size = null;
|
|
|
|
|
attachment.progress = 0;
|
|
|
|
|
|
|
|
|
|
attachment.id = db.attachment().insertAttachment(attachment);
|
|
|
|
|
|
|
|
|
|
String cid = BuildConfig.APPLICATION_ID + "." + attachment.id;
|
|
|
|
|
attachment.cid = "<" + BuildConfig.APPLICATION_ID + "." + attachment.id + ">";
|
|
|
|
|
db.attachment().setCid(attachment.id, attachment.cid);
|
|
|
|
|
|
|
|
|
|
attachment.size = Helper.copy(context, uri, attachment.getFile(context));
|
|
|
|
|
attachment.progress = null;
|
|
|
|
|
attachment.available = true;
|
|
|
|
|
db.attachment().setDownloaded(attachment.id, attachment.size);
|
|
|
|
|
|
|
|
|
|
attachments.add(attachment);
|
|
|
|
|
img.attr("src", "cid:" + cid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
contents.add(part);
|
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
|
} finally {
|
|
|
|
|
db.endTransaction();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -565,8 +575,8 @@ public class MessageHelper {
|
|
|
|
|
altMultiPart.addBodyPart(plainPart);
|
|
|
|
|
altMultiPart.addBodyPart(htmlPart);
|
|
|
|
|
|
|
|
|
|
int availableAttachments = contents.size();
|
|
|
|
|
boolean hasInline = contents.size() > 0;
|
|
|
|
|
int availableAttachments = 0;
|
|
|
|
|
boolean hasInline = false;
|
|
|
|
|
for (EntityAttachment attachment : attachments)
|
|
|
|
|
if (attachment.available) {
|
|
|
|
|
availableAttachments++;
|
|
|
|
@ -645,9 +655,6 @@ public class MessageHelper {
|
|
|
|
|
mixedMultiPart.addBodyPart(attachmentPart);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (BodyPart content : contents)
|
|
|
|
|
relatedMultiPart.addBodyPart(content);
|
|
|
|
|
|
|
|
|
|
imessage.setContent(mixedMultiPart);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|