|
|
|
@ -108,8 +108,8 @@ import biweekly.ICalendar;
|
|
|
|
|
|
|
|
|
|
public class MessageHelper {
|
|
|
|
|
private boolean ensuredEnvelope = false;
|
|
|
|
|
private boolean ensuredEnvelopeAll = false;
|
|
|
|
|
private boolean ensuredBody = false;
|
|
|
|
|
private boolean ensuredHeaders = false;
|
|
|
|
|
private boolean ensuredStructure = false;
|
|
|
|
|
private MimeMessage imessage;
|
|
|
|
|
|
|
|
|
|
private static File cacheDir = null;
|
|
|
|
@ -823,7 +823,7 @@ public class MessageHelper {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String getMessageID() throws MessagingException {
|
|
|
|
|
ensureMessage(false, false);
|
|
|
|
|
ensureEnvelope();
|
|
|
|
|
|
|
|
|
|
// Outlook outbox -> sent
|
|
|
|
|
String header = imessage.getHeader(HEADER_CORRELATION_ID, null);
|
|
|
|
@ -833,7 +833,7 @@ public class MessageHelper {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String[] getReferences() throws MessagingException {
|
|
|
|
|
ensureMessage(false);
|
|
|
|
|
ensureHeaders();
|
|
|
|
|
|
|
|
|
|
List<String> result = new ArrayList<>();
|
|
|
|
|
String refs = imessage.getHeader("References", null);
|
|
|
|
@ -895,7 +895,7 @@ public class MessageHelper {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String getDeliveredTo() throws MessagingException {
|
|
|
|
|
ensureMessage(false);
|
|
|
|
|
ensureHeaders();
|
|
|
|
|
|
|
|
|
|
String header = imessage.getHeader("Delivered-To", null);
|
|
|
|
|
if (header == null)
|
|
|
|
@ -911,15 +911,13 @@ public class MessageHelper {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String getInReplyTo() throws MessagingException {
|
|
|
|
|
ensureMessage(false);
|
|
|
|
|
ensureHeaders();
|
|
|
|
|
|
|
|
|
|
String header = imessage.getHeader("In-Reply-To", null);
|
|
|
|
|
return (header == null ? null : MimeUtility.unfold(header));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String getThreadId(Context context, long account, long uid) throws MessagingException {
|
|
|
|
|
ensureMessage(false);
|
|
|
|
|
|
|
|
|
|
if (imessage instanceof GmailMessage) {
|
|
|
|
|
// https://developers.google.com/gmail/imap/imap-extensions#access_to_the_gmail_thread_id_x-gm-thrid
|
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
@ -995,7 +993,7 @@ public class MessageHelper {
|
|
|
|
|
Integer getPriority() throws MessagingException {
|
|
|
|
|
Integer priority = null;
|
|
|
|
|
|
|
|
|
|
ensureMessage(false);
|
|
|
|
|
ensureHeaders();
|
|
|
|
|
|
|
|
|
|
// https://tools.ietf.org/html/rfc2156
|
|
|
|
|
// https://docs.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-oxcmail/2bb19f1b-b35e-4966-b1cb-1afd044e83ab
|
|
|
|
@ -1068,20 +1066,20 @@ public class MessageHelper {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean getReceiptRequested() throws MessagingException {
|
|
|
|
|
ensureMessage(false);
|
|
|
|
|
ensureHeaders();
|
|
|
|
|
|
|
|
|
|
return (imessage.getHeader("Return-Receipt-To") != null ||
|
|
|
|
|
imessage.getHeader("Disposition-Notification-To") != null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Address[] getReceiptTo() throws MessagingException {
|
|
|
|
|
ensureMessage(false);
|
|
|
|
|
ensureHeaders();
|
|
|
|
|
|
|
|
|
|
return getAddressHeader("Disposition-Notification-To");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String[] getAuthentication() throws MessagingException {
|
|
|
|
|
ensureMessage(false);
|
|
|
|
|
ensureHeaders();
|
|
|
|
|
|
|
|
|
|
String[] headers = imessage.getHeader("Authentication-Results");
|
|
|
|
|
if (headers == null)
|
|
|
|
@ -1121,7 +1119,7 @@ public class MessageHelper {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String getReceivedFromHost() throws MessagingException {
|
|
|
|
|
ensureMessage(false);
|
|
|
|
|
ensureHeaders();
|
|
|
|
|
|
|
|
|
|
String[] received = imessage.getHeader("Received");
|
|
|
|
|
if (received == null || received.length == 0)
|
|
|
|
@ -1156,7 +1154,7 @@ public class MessageHelper {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Address[] getAddressHeader(String name) throws MessagingException {
|
|
|
|
|
ensureMessage(false);
|
|
|
|
|
ensureHeaders();
|
|
|
|
|
|
|
|
|
|
String header = imessage.getHeader(name, ",");
|
|
|
|
|
if (header == null)
|
|
|
|
@ -1217,7 +1215,7 @@ public class MessageHelper {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Address[] getListPost() throws MessagingException {
|
|
|
|
|
ensureMessage(false);
|
|
|
|
|
ensureHeaders();
|
|
|
|
|
|
|
|
|
|
String list;
|
|
|
|
|
try {
|
|
|
|
@ -1257,7 +1255,7 @@ public class MessageHelper {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String getListUnsubscribe() throws MessagingException {
|
|
|
|
|
ensureMessage(false);
|
|
|
|
|
ensureHeaders();
|
|
|
|
|
|
|
|
|
|
String list;
|
|
|
|
|
try {
|
|
|
|
@ -1305,7 +1303,7 @@ public class MessageHelper {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String getAutocrypt() throws MessagingException {
|
|
|
|
|
ensureMessage(false);
|
|
|
|
|
ensureHeaders();
|
|
|
|
|
|
|
|
|
|
String autocrypt = imessage.getHeader("Autocrypt", null);
|
|
|
|
|
if (autocrypt == null)
|
|
|
|
@ -1315,7 +1313,7 @@ public class MessageHelper {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String getSubject() throws MessagingException {
|
|
|
|
|
ensureMessage(false);
|
|
|
|
|
ensureHeaders();
|
|
|
|
|
|
|
|
|
|
String subject = imessage.getHeader("Subject", null);
|
|
|
|
|
if (subject == null)
|
|
|
|
@ -1333,14 +1331,14 @@ public class MessageHelper {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Long getSize() throws MessagingException {
|
|
|
|
|
ensureMessage(false);
|
|
|
|
|
ensureEnvelope();
|
|
|
|
|
|
|
|
|
|
long size = imessage.getSize();
|
|
|
|
|
return (size < 0 ? null : size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Long getReceived() throws MessagingException {
|
|
|
|
|
ensureMessage(false);
|
|
|
|
|
ensureEnvelope();
|
|
|
|
|
|
|
|
|
|
Date received = imessage.getReceivedDate();
|
|
|
|
|
if (received == null)
|
|
|
|
@ -1350,7 +1348,7 @@ public class MessageHelper {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Long getReceivedHeader() throws MessagingException {
|
|
|
|
|
ensureMessage(false);
|
|
|
|
|
ensureHeaders();
|
|
|
|
|
|
|
|
|
|
// https://tools.ietf.org/html/rfc5321#section-4.4
|
|
|
|
|
// https://tools.ietf.org/html/rfc5322#section-3.6.7
|
|
|
|
@ -1372,7 +1370,7 @@ public class MessageHelper {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Long getSent() throws MessagingException {
|
|
|
|
|
ensureMessage(false);
|
|
|
|
|
ensureEnvelope();
|
|
|
|
|
|
|
|
|
|
Date sent = imessage.getSentDate();
|
|
|
|
|
if (sent == null)
|
|
|
|
@ -1382,7 +1380,7 @@ public class MessageHelper {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String getHeaders() throws MessagingException {
|
|
|
|
|
ensureMessage(false);
|
|
|
|
|
ensureHeaders();
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
Enumeration<Header> headers = imessage.getAllHeaders();
|
|
|
|
@ -2209,7 +2207,7 @@ public class MessageHelper {
|
|
|
|
|
MessageParts getMessageParts() throws IOException, MessagingException {
|
|
|
|
|
MessageParts parts = new MessageParts();
|
|
|
|
|
|
|
|
|
|
ensureMessage(true);
|
|
|
|
|
ensureStructure();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
MimePart part = imessage;
|
|
|
|
@ -2436,28 +2434,38 @@ public class MessageHelper {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ensureMessage(boolean body) throws MessagingException {
|
|
|
|
|
ensureMessage(body, true);
|
|
|
|
|
private void ensureEnvelope() throws MessagingException {
|
|
|
|
|
_ensureMessage(false, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ensureMessage(boolean body, boolean all) throws MessagingException {
|
|
|
|
|
if (body ? ensuredBody : ensuredEnvelopeAll || (ensuredEnvelope && !all))
|
|
|
|
|
return;
|
|
|
|
|
private void ensureHeaders() throws MessagingException {
|
|
|
|
|
_ensureMessage(false, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (body)
|
|
|
|
|
ensuredBody = true;
|
|
|
|
|
else {
|
|
|
|
|
if (all)
|
|
|
|
|
ensuredEnvelopeAll = true;
|
|
|
|
|
else
|
|
|
|
|
ensuredEnvelope = true;
|
|
|
|
|
private void ensureStructure() throws MessagingException {
|
|
|
|
|
_ensureMessage(true, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void _ensureMessage(boolean structure, boolean headers) throws MessagingException {
|
|
|
|
|
if (structure) {
|
|
|
|
|
if (ensuredStructure)
|
|
|
|
|
return;
|
|
|
|
|
ensuredStructure = true;
|
|
|
|
|
} else if (headers) {
|
|
|
|
|
if (ensuredHeaders)
|
|
|
|
|
return;
|
|
|
|
|
ensuredHeaders = true;
|
|
|
|
|
} else {
|
|
|
|
|
if (ensuredEnvelope)
|
|
|
|
|
return;
|
|
|
|
|
ensuredEnvelope = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log.i("Ensure body=" + body + " all=" + all);
|
|
|
|
|
Log.i("Ensure structure=" + structure + " headers=" + headers);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (imessage instanceof IMAPMessage) {
|
|
|
|
|
if (body) {
|
|
|
|
|
if (structure) {
|
|
|
|
|
String contentType = imessage.getContentType(); // force loadBODYSTRUCTURE
|
|
|
|
|
|
|
|
|
|
// Workaround protocol parameter missing
|
|
|
|
@ -2483,11 +2491,10 @@ public class MessageHelper {
|
|
|
|
|
throw new MessagingException("Failed to load IMAP envelope");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// force loadEnvelope
|
|
|
|
|
if (all)
|
|
|
|
|
imessage.getAllHeaders();
|
|
|
|
|
if (headers)
|
|
|
|
|
imessage.getAllHeaders(); // force loadHeaders
|
|
|
|
|
else
|
|
|
|
|
imessage.getMessageID();
|
|
|
|
|
imessage.getMessageID(); // force loadEnvelope
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (MessagingException ex) {
|
|
|
|
|