mirror of https://github.com/M66B/FairEmail.git
Send inline content as related
This commit is contained in:
parent
2c531aa76d
commit
96c3ab83a0
|
@ -349,40 +349,61 @@ public class MessageHelper {
|
||||||
StringBuilder htmlContent = new StringBuilder();
|
StringBuilder htmlContent = new StringBuilder();
|
||||||
htmlContent.append(body.toString()).append("\n");
|
htmlContent.append(body.toString()).append("\n");
|
||||||
|
|
||||||
|
// multipart/mixed
|
||||||
|
// multipart/related
|
||||||
|
// multipart/alternative
|
||||||
|
// text/plain
|
||||||
|
// text/html
|
||||||
|
// inlines
|
||||||
|
// attachments
|
||||||
|
|
||||||
BodyPart plainPart = new MimeBodyPart();
|
BodyPart plainPart = new MimeBodyPart();
|
||||||
plainPart.setContent(plainContent, "text/plain; charset=" + Charset.defaultCharset().name());
|
plainPart.setContent(plainContent, "text/plain; charset=" + Charset.defaultCharset().name());
|
||||||
|
|
||||||
BodyPart htmlPart = new MimeBodyPart();
|
BodyPart htmlPart = new MimeBodyPart();
|
||||||
htmlPart.setContent(htmlContent.toString(), "text/html; charset=" + Charset.defaultCharset().name());
|
htmlPart.setContent(htmlContent.toString(), "text/html; charset=" + Charset.defaultCharset().name());
|
||||||
|
|
||||||
Multipart alternativePart = new MimeMultipart("alternative");
|
Multipart altMultiPart = new MimeMultipart("alternative");
|
||||||
alternativePart.addBodyPart(plainPart);
|
altMultiPart.addBodyPart(plainPart);
|
||||||
alternativePart.addBodyPart(htmlPart);
|
altMultiPart.addBodyPart(htmlPart);
|
||||||
|
|
||||||
int available = 0;
|
boolean plain_only = (message.plain_only != null && message.plain_only);
|
||||||
|
|
||||||
|
int availableAttachments = 0;
|
||||||
|
boolean hasInline = false;
|
||||||
for (EntityAttachment attachment : attachments)
|
for (EntityAttachment attachment : attachments)
|
||||||
if (attachment.available)
|
if (attachment.available) {
|
||||||
available++;
|
availableAttachments++;
|
||||||
Log.i("Attachments available=" + available);
|
if (attachment.isInline())
|
||||||
|
hasInline = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (available == 0)
|
if (availableAttachments == 0)
|
||||||
if (message.plain_only != null && message.plain_only)
|
if (plain_only)
|
||||||
imessage.setContent(plainContent, "text/plain; charset=" + Charset.defaultCharset().name());
|
imessage.setContent(plainContent, "text/plain; charset=" + Charset.defaultCharset().name());
|
||||||
else
|
else
|
||||||
imessage.setContent(alternativePart);
|
imessage.setContent(altMultiPart);
|
||||||
else {
|
else {
|
||||||
Multipart mixedPart = new MimeMultipart("mixed");
|
Multipart mixedMultiPart = new MimeMultipart("mixed");
|
||||||
|
Multipart relatedMultiPart = new MimeMultipart("related");
|
||||||
|
|
||||||
BodyPart attachmentPart = new MimeBodyPart();
|
BodyPart bodyPart = new MimeBodyPart();
|
||||||
if (message.plain_only != null && message.plain_only)
|
if (plain_only)
|
||||||
attachmentPart.setContent(plainContent, "text/plain; charset=" + Charset.defaultCharset().name());
|
bodyPart.setContent(plainContent, "text/plain; charset=" + Charset.defaultCharset().name());
|
||||||
else
|
else
|
||||||
attachmentPart.setContent(alternativePart);
|
bodyPart.setContent(altMultiPart);
|
||||||
mixedPart.addBodyPart(attachmentPart);
|
|
||||||
|
if (hasInline && !plain_only) {
|
||||||
|
relatedMultiPart.addBodyPart(bodyPart);
|
||||||
|
MimeBodyPart relatedPart = new MimeBodyPart();
|
||||||
|
relatedPart.setContent(relatedMultiPart);
|
||||||
|
mixedMultiPart.addBodyPart(relatedPart);
|
||||||
|
} else
|
||||||
|
mixedMultiPart.addBodyPart(bodyPart);
|
||||||
|
|
||||||
for (final EntityAttachment attachment : attachments)
|
for (final EntityAttachment attachment : attachments)
|
||||||
if (attachment.available) {
|
if (attachment.available) {
|
||||||
BodyPart bpAttachment = new MimeBodyPart();
|
BodyPart attachmentPart = new MimeBodyPart();
|
||||||
|
|
||||||
File file = attachment.getFile(context);
|
File file = attachment.getFile(context);
|
||||||
|
|
||||||
|
@ -412,18 +433,21 @@ public class MessageHelper {
|
||||||
return getContentType(new File(filename));
|
return getContentType(new File(filename));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
bpAttachment.setDataHandler(new DataHandler(dataSource));
|
attachmentPart.setDataHandler(new DataHandler(dataSource));
|
||||||
|
|
||||||
bpAttachment.setFileName(attachment.name);
|
attachmentPart.setFileName(attachment.name);
|
||||||
if (attachment.disposition != null)
|
if (attachment.disposition != null)
|
||||||
bpAttachment.setDisposition(attachment.disposition);
|
attachmentPart.setDisposition(attachment.disposition);
|
||||||
if (attachment.cid != null)
|
if (attachment.cid != null)
|
||||||
bpAttachment.setHeader("Content-ID", attachment.cid);
|
attachmentPart.setHeader("Content-ID", attachment.cid);
|
||||||
|
|
||||||
mixedPart.addBodyPart(bpAttachment);
|
if (attachment.isInline() && !plain_only)
|
||||||
|
relatedMultiPart.addBodyPart(attachmentPart);
|
||||||
|
else
|
||||||
|
mixedMultiPart.addBodyPart(attachmentPart);
|
||||||
}
|
}
|
||||||
|
|
||||||
imessage.setContent(mixedPart);
|
imessage.setContent(mixedMultiPart);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue