Refactoring

pull/194/merge
M66B 3 years ago
parent 9d84dca6d7
commit 35e0e0e923

@ -123,6 +123,7 @@ public class MessageHelper {
private boolean ensuredStructure = false; private boolean ensuredStructure = false;
private MimeMessage imessage; private MimeMessage imessage;
private String hash = null; private String hash = null;
private InternetHeaders reportHeaders = null;
private static File cacheDir = null; private static File cacheDir = null;
@ -1170,51 +1171,25 @@ public class MessageHelper {
if (refs != null) if (refs != null)
result.addAll(Arrays.asList(getReferences(refs))); result.addAll(Arrays.asList(getReferences(refs)));
try { // Merge references of reported message for threading
// Merge references of original message for threading InternetHeaders iheaders = getReportHeaders();
if (imessage.isMimeType("multipart/report")) { if (iheaders != null) {
ContentType ct = new ContentType(imessage.getContentType()); String arefs = iheaders.getHeader("References", null);
String reportType = ct.getParameter("report-type"); if (arefs != null)
if ("delivery-status".equalsIgnoreCase(reportType) || for (String ref : getReferences(arefs))
"disposition-notification".equalsIgnoreCase(reportType)) { if (!result.contains(ref)) {
String arefs = null; Log.i("rfc822 ref=" + ref);
String amsgid = null; result.add(ref);
MessageParts parts = new MessageParts();
getMessageParts(imessage, parts, null);
for (AttachmentPart apart : parts.attachments)
if ("text/rfc822-headers".equalsIgnoreCase(apart.attachment.type)) {
InternetHeaders iheaders = new InternetHeaders(apart.part.getInputStream());
arefs = iheaders.getHeader("References", null);
amsgid = iheaders.getHeader("Message-Id", null);
break;
} else if ("message/rfc822".equalsIgnoreCase(apart.attachment.type)) {
Properties props = MessageHelper.getSessionProperties();
Session isession = Session.getInstance(props, null);
MimeMessage amessage = new MimeMessage(isession, apart.part.getInputStream());
arefs = amessage.getHeader("References", null);
amsgid = amessage.getHeader("Message-Id", null);
break;
}
if (arefs != null)
for (String ref : getReferences(arefs))
if (!result.contains(ref)) {
Log.i("rfc822 ref=" + ref);
result.add(ref);
}
if (amsgid != null) {
String msgid = MimeUtility.unfold(amsgid);
if (!result.contains(msgid)) {
Log.i("rfc822 id=" + msgid);
result.add(msgid);
}
} }
String amsgid = iheaders.getHeader("Message-Id", null);
if (amsgid != null) {
String msgid = MimeUtility.unfold(amsgid);
if (!result.contains(msgid)) {
Log.i("rfc822 id=" + msgid);
result.add(msgid);
} }
} }
} catch (Throwable ex) {
Log.w(ex);
} }
return result.toArray(new String[0]); return result.toArray(new String[0]);
@ -1247,42 +1222,50 @@ public class MessageHelper {
if (header != null) if (header != null)
header = MimeUtility.unfold(header); header = MimeUtility.unfold(header);
if (header == null) if (header == null) {
try { // Use reported message ID as synthetic in-reply-to
if (imessage.isMimeType("multipart/report")) { InternetHeaders iheaders = getReportHeaders();
ContentType ct = new ContentType(imessage.getContentType()); if (iheaders != null) {
String reportType = ct.getParameter("report-type"); header = iheaders.getHeader("Message-Id", null);
if ("delivery-status".equalsIgnoreCase(reportType) || if (header != null)
"disposition-notification".equalsIgnoreCase(reportType)) { Log.i("rfc822 id=" + header);
MessageParts parts = new MessageParts();
getMessageParts(imessage, parts, null);
for (AttachmentPart apart : parts.attachments)
if ("text/rfc822-headers".equalsIgnoreCase(apart.attachment.type)) {
InternetHeaders iheaders = new InternetHeaders(apart.part.getInputStream());
String amsgid = iheaders.getHeader("Message-Id", null);
if (amsgid != null) {
Log.i("rfc822 id=" + amsgid);
return amsgid;
}
} else if ("message/rfc822".equalsIgnoreCase(apart.attachment.type)) {
Properties props = MessageHelper.getSessionProperties();
Session isession = Session.getInstance(props, null);
MimeMessage amessage = new MimeMessage(isession, apart.part.getInputStream());
String amsgid = amessage.getHeader("Message-Id", null);
if (amsgid != null) {
Log.i("rfc822 id=" + amsgid);
return amsgid;
}
}
}
}
} catch (Throwable ex) {
Log.w(ex);
} }
}
return header; return header;
} }
private InternetHeaders getReportHeaders() {
try {
ensureStructure();
if (imessage.isMimeType("multipart/report")) {
ContentType ct = new ContentType(imessage.getContentType());
String reportType = ct.getParameter("report-type");
if ("delivery-status".equalsIgnoreCase(reportType) ||
"disposition-notification".equalsIgnoreCase(reportType)) {
MessageParts parts = new MessageParts();
getMessageParts(imessage, parts, null);
for (AttachmentPart apart : parts.attachments)
if ("text/rfc822-headers".equalsIgnoreCase(apart.attachment.type)) {
reportHeaders = new InternetHeaders(apart.part.getInputStream());
break;
} else if ("message/rfc822".equalsIgnoreCase(apart.attachment.type)) {
Properties props = MessageHelper.getSessionProperties();
Session isession = Session.getInstance(props, null);
MimeMessage amessage = new MimeMessage(isession, apart.part.getInputStream());
reportHeaders = amessage.getHeaders();
break;
}
}
}
} catch (Throwable ex) {
Log.w(ex);
}
return reportHeaders;
}
String getThreadId(Context context, long account, long folder, long uid) throws MessagingException { String getThreadId(Context context, long account, long folder, long uid) throws MessagingException {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

@ -2008,6 +2008,10 @@ public class MimeMessage extends Message implements MimePart {
headers.removeHeader(name); headers.removeHeader(name);
} }
public InternetHeaders getHeaders() {
return headers;
}
/** /**
* Return all the headers from this Message as an enumeration * Return all the headers from this Message as an enumeration
* of Header objects. <p> * of Header objects. <p>

Loading…
Cancel
Save