mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-27 10:17:18 +00:00
Report: process delivery-status / rfc822-headers
This commit is contained in:
parent
aaa2934af4
commit
0392587d4f
1 changed files with 34 additions and 11 deletions
|
@ -76,6 +76,7 @@ import javax.mail.Session;
|
||||||
import javax.mail.internet.AddressException;
|
import javax.mail.internet.AddressException;
|
||||||
import javax.mail.internet.ContentType;
|
import javax.mail.internet.ContentType;
|
||||||
import javax.mail.internet.InternetAddress;
|
import javax.mail.internet.InternetAddress;
|
||||||
|
import javax.mail.internet.InternetHeaders;
|
||||||
import javax.mail.internet.MailDateFormat;
|
import javax.mail.internet.MailDateFormat;
|
||||||
import javax.mail.internet.MimeBodyPart;
|
import javax.mail.internet.MimeBodyPart;
|
||||||
import javax.mail.internet.MimeMessage;
|
import javax.mail.internet.MimeMessage;
|
||||||
|
@ -640,37 +641,59 @@ public class MessageHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] getReferences() throws MessagingException {
|
String[] getReferences() throws MessagingException {
|
||||||
|
List<String> result = new ArrayList<>();
|
||||||
String refs = imessage.getHeader("References", null);
|
String refs = imessage.getHeader("References", null);
|
||||||
|
if (refs != null)
|
||||||
|
result.addAll(Arrays.asList(MimeUtility.unfold(refs).split("\\s+")));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Merge references of original message for threading
|
// Merge references of original message for threading
|
||||||
if (imessage.isMimeType("multipart/report")) {
|
if (imessage.isMimeType("multipart/report")) {
|
||||||
ContentType ct = new ContentType(imessage.getContentType());
|
ContentType ct = new ContentType(imessage.getContentType());
|
||||||
if ("delivery-status".equalsIgnoreCase(ct.getParameter("report-type"))) {
|
String reportType = ct.getParameter("report-type");
|
||||||
|
if ("delivery-status".equalsIgnoreCase(reportType) ||
|
||||||
|
"disposition-notification".equalsIgnoreCase(reportType)) {
|
||||||
|
String amsgid = null;
|
||||||
|
String arefs = null;
|
||||||
|
|
||||||
MessageParts parts = new MessageParts();
|
MessageParts parts = new MessageParts();
|
||||||
getMessageParts(imessage, parts, null);
|
getMessageParts(imessage, parts, null);
|
||||||
for (AttachmentPart apart : parts.attachments)
|
for (AttachmentPart apart : parts.attachments)
|
||||||
if ("message/rfc822".equalsIgnoreCase(apart.attachment.type)) {
|
if ("text/rfc822-headers".equalsIgnoreCase(apart.attachment.type)) {
|
||||||
|
InternetHeaders iheaders = new InternetHeaders(apart.part.getInputStream());
|
||||||
|
amsgid = iheaders.getHeader("Message-Id", null);
|
||||||
|
arefs = iheaders.getHeader("References", null);
|
||||||
|
break;
|
||||||
|
} else if ("message/rfc822".equalsIgnoreCase(apart.attachment.type)) {
|
||||||
Properties props = MessageHelper.getSessionProperties();
|
Properties props = MessageHelper.getSessionProperties();
|
||||||
Session isession = Session.getInstance(props, null);
|
Session isession = Session.getInstance(props, null);
|
||||||
MimeMessage amessage = new MimeMessage(isession, apart.part.getInputStream());
|
MimeMessage amessage = new MimeMessage(isession, apart.part.getInputStream());
|
||||||
String arefs = amessage.getHeader("References", null);
|
amsgid = amessage.getHeader("Message-Id", null);
|
||||||
if (arefs != null) {
|
arefs = amessage.getHeader("References", null);
|
||||||
Log.i("rfc822 refs=" + arefs);
|
|
||||||
if (refs == null)
|
|
||||||
refs = arefs;
|
|
||||||
else
|
|
||||||
refs += " " + arefs;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (amsgid != null) {
|
||||||
|
String msgid = MimeUtility.unfold(amsgid);
|
||||||
|
if (!result.contains(msgid)) {
|
||||||
|
Log.i("rfc822 id=" + msgid);
|
||||||
|
result.add(msgid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arefs != null)
|
||||||
|
for (String ref : MimeUtility.unfold(arefs).split("\\s+"))
|
||||||
|
if (!result.contains(ref)) {
|
||||||
|
Log.i("rfc822 ref=" + ref);
|
||||||
|
result.add(ref);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
Log.w(ex);
|
Log.w(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (refs == null ? new String[0] : MimeUtility.unfold(refs).split("\\s+"));
|
return result.toArray(new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
String getDeliveredTo() throws MessagingException {
|
String getDeliveredTo() throws MessagingException {
|
||||||
|
|
Loading…
Reference in a new issue