Improved sent/received date handling

pull/184/head
M66B 5 years ago
parent de4efc9297
commit 7b3c7b665c

@ -136,7 +136,6 @@ class Core {
private static final int SYNC_BATCH_SIZE = 20; private static final int SYNC_BATCH_SIZE = 20;
private static final int DOWNLOAD_BATCH_SIZE = 20; private static final int DOWNLOAD_BATCH_SIZE = 20;
private static final long YIELD_DURATION = 200L; // milliseconds private static final long YIELD_DURATION = 200L; // milliseconds
private static final long FUTURE_RECEIVED = 30 * 24 * 3600 * 1000L; // milliseconds
private static final int LOCAL_RETRY_MAX = 3; private static final int LOCAL_RETRY_MAX = 3;
private static final long LOCAL_RETRY_DELAY = 10 * 1000L; // milliseconds private static final long LOCAL_RETRY_DELAY = 10 * 1000L; // milliseconds
private static final int TOTAL_RETRY_MAX = LOCAL_RETRY_MAX * 10; private static final int TOTAL_RETRY_MAX = LOCAL_RETRY_MAX * 10;
@ -1829,8 +1828,11 @@ class Core {
Log.i(folder.name + " POP sync=" + uidl); Log.i(folder.name + " POP sync=" + uidl);
Long sent = helper.getSent(); Long sent = helper.getSent();
if (sent == null) Long received = helper.getReceivedHeader();
sent = 0L; if (received == null)
received = sent;
if (received == null)
received = 0L;
String[] authentication = helper.getAuthentication(); String[] authentication = helper.getAuthentication();
MessageHelper.MessageParts parts = helper.getMessageParts(); MessageHelper.MessageParts parts = helper.getMessageParts();
@ -1867,7 +1869,7 @@ class Core {
message.content = false; message.content = false;
message.encrypt = parts.getEncryption(); message.encrypt = parts.getEncryption();
message.ui_encrypt = message.encrypt; message.ui_encrypt = message.encrypt;
message.received = sent; message.received = received;
message.sent = sent; message.sent = sent;
message.seen = false; message.seen = false;
message.answered = false; message.answered = false;
@ -2448,8 +2450,12 @@ class Core {
dup.thread = thread; dup.thread = thread;
if (EntityFolder.SENT.equals(folder.type)) { if (EntityFolder.SENT.equals(folder.type)) {
dup.received = helper.getReceived(); Long sent = helper.getSent();
dup.sent = helper.getSent(); Long received = helper.getReceived();
if (sent != null)
dup.sent = sent;
if (received != null)
dup.received = received;
} }
dup.error = null; dup.error = null;
@ -2466,18 +2472,25 @@ class Core {
if (message == null) { if (message == null) {
Long sent = helper.getSent(); Long sent = helper.getSent();
long received;
if (account.use_date) Long received;
received = (sent == null ? 0 : sent); if (account.use_date) {
else if (account.use_received) { received = sent;
Long rh = helper.getReceivedHeader(); if (received == null)
received = (rh == null ? helper.getReceived() : rh); received = helper.getReceived();
if (received == null)
received = helper.getReceivedHeader();
} else if (account.use_received) {
received = helper.getReceivedHeader();
if (received == null)
received = helper.getReceived();
} else { } else {
received = helper.getReceived(); received = helper.getReceived();
if (received == 0 || received > new Date().getTime() + FUTURE_RECEIVED) if (received == null)
if (sent != null) received = helper.getReceivedHeader();
received = sent;
} }
if (received == null)
received = 0L;
String[] authentication = helper.getAuthentication(); String[] authentication = helper.getAuthentication();
MessageHelper.MessageParts parts = helper.getMessageParts(); MessageHelper.MessageParts parts = helper.getMessageParts();

@ -1305,17 +1305,21 @@ public class MessageHelper {
return (size < 0 ? null : size); return (size < 0 ? null : size);
} }
long getReceived() throws MessagingException { Long getReceived() throws MessagingException {
ensureMessage(false); ensureMessage(false);
Date received = imessage.getReceivedDate(); Date received = imessage.getReceivedDate();
if (received == null) if (received == null)
received = imessage.getSentDate(); return null;
return (received == null ? new Date() : received).getTime(); return received.getTime();
} }
Long getReceivedHeader() throws MessagingException { Long getReceivedHeader() throws MessagingException {
ensureMessage(false);
// https://tools.ietf.org/html/rfc5321#section-4.4
// https://tools.ietf.org/html/rfc5322#section-3.6.7
String[] received = imessage.getHeader("Received"); String[] received = imessage.getHeader("Received");
if (received == null || received.length == 0) if (received == null || received.length == 0)
return null; return null;
@ -1338,8 +1342,9 @@ public class MessageHelper {
Date sent = imessage.getSentDate(); Date sent = imessage.getSentDate();
if (sent == null) if (sent == null)
sent = imessage.getReceivedDate(); return null;
return (sent == null ? new Date() : sent).getTime();
return sent.getTime();
} }
String getHeaders() throws MessagingException { String getHeaders() throws MessagingException {

Loading…
Cancel
Save