Added setting to use received header

This commit is contained in:
M66B 2020-07-22 14:57:47 +02:00
parent a3133282bc
commit 3d66251cde
9 changed files with 2345 additions and 6 deletions

File diff suppressed because it is too large Load Diff

View File

@ -2469,7 +2469,10 @@ class Core {
long received;
if (account.use_date)
received = (sent == null ? 0 : sent);
else {
else if (account.use_received) {
Long rh = helper.getReceivedHeader();
received = (rh == null ? helper.getReceived() : rh);
} else {
received = helper.getReceived();
if (received == 0 || received > new Date().getTime() + FUTURE_RECEIVED)
if (sent != null)

View File

@ -62,7 +62,7 @@ import io.requery.android.database.sqlite.SQLiteDatabase;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 171,
version = 172,
entities = {
EntityIdentity.class,
EntityAccount.class,
@ -1692,6 +1692,13 @@ public abstract class DB extends RoomDatabase {
db.execSQL("DROP TRIGGER IF EXISTS `attachment_delete`");
createTriggers(db);
}
})
.addMigrations(new Migration(171, 172) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `account` ADD COLUMN `use_received` INTEGER NOT NULL DEFAULT 0");
}
});
}

View File

@ -126,7 +126,9 @@ public class EntityAccount extends EntityOrder implements Serializable {
@NonNull
public Boolean ignore_size = false;
@NonNull
public Boolean use_date = false;
public Boolean use_date = false; // Date header
@NonNull
public Boolean use_received = false; // Received header
public String prefix; // namespace, obsolete
public Long quota_usage;
@ -237,6 +239,7 @@ public class EntityAccount extends EntityOrder implements Serializable {
json.put("partial_fetch", partial_fetch);
json.put("ignore_size", ignore_size);
json.put("use_date", use_date);
json.put("use_received", use_received);
// not prefix
// not created
// not tbd
@ -315,6 +318,7 @@ public class EntityAccount extends EntityOrder implements Serializable {
account.partial_fetch = json.optBoolean("partial_fetch", true);
account.ignore_size = json.optBoolean("ignore_size", false);
account.use_date = json.optBoolean("use_date", false);
account.use_received = json.optBoolean("use_received", false);
return account;
}
@ -349,6 +353,7 @@ public class EntityAccount extends EntityOrder implements Serializable {
this.partial_fetch == other.partial_fetch &&
this.ignore_size == other.ignore_size &&
this.use_date == other.use_date &&
this.use_received == other.use_received &&
Objects.equals(this.quota_usage, other.quota_usage) &&
Objects.equals(this.quota_limit, other.quota_limit) &&
Objects.equals(this.created, other.created) &&

View File

@ -118,6 +118,7 @@ public class FragmentAccount extends FragmentBase {
private CheckBox cbPartialFetch;
private CheckBox cbIgnoreSize;
private CheckBox cbUseDate;
private CheckBox cbUseReceived;
private Button btnCheck;
private ContentLoadingProgressBar pbCheck;
@ -223,6 +224,7 @@ public class FragmentAccount extends FragmentBase {
cbPartialFetch = view.findViewById(R.id.cbPartialFetch);
cbIgnoreSize = view.findViewById(R.id.cbIgnoreSize);
cbUseDate = view.findViewById(R.id.cbUseDate);
cbUseReceived = view.findViewById(R.id.cbUseReceived);
btnCheck = view.findViewById(R.id.btnCheck);
pbCheck = view.findViewById(R.id.pbCheck);
@ -832,6 +834,7 @@ public class FragmentAccount extends FragmentBase {
args.putBoolean("partial_fetch", cbPartialFetch.isChecked());
args.putBoolean("ignore_size", cbIgnoreSize.isChecked());
args.putBoolean("use_date", cbUseDate.isChecked());
args.putBoolean("use_received", cbUseReceived.isChecked());
args.putSerializable("drafts", drafts);
args.putSerializable("sent", sent);
@ -894,6 +897,7 @@ public class FragmentAccount extends FragmentBase {
boolean partial_fetch = args.getBoolean("partial_fetch");
boolean ignore_size = args.getBoolean("ignore_size");
boolean use_date = args.getBoolean("use_date");
boolean use_received = args.getBoolean("use_received");
EntityFolder drafts = (EntityFolder) args.getSerializable("drafts");
EntityFolder sent = (EntityFolder) args.getSerializable("sent");
@ -985,6 +989,8 @@ public class FragmentAccount extends FragmentBase {
return true;
if (!Objects.equals(account.use_date, use_date))
return true;
if (!Objects.equals(account.use_received, use_received))
return true;
EntityFolder edrafts = db.folder().getFolderByType(account.id, EntityFolder.DRAFTS);
if (!Objects.equals(edrafts == null ? null : edrafts.id, drafts == null ? null : drafts.id))
@ -1117,6 +1123,7 @@ public class FragmentAccount extends FragmentBase {
account.partial_fetch = partial_fetch;
account.ignore_size = ignore_size;
account.use_date = use_date;
account.use_received = use_received;
if (!update)
account.created = now;
@ -1478,6 +1485,7 @@ public class FragmentAccount extends FragmentBase {
cbPartialFetch.setChecked(account == null ? true : account.partial_fetch);
cbIgnoreSize.setChecked(account == null ? false : account.ignore_size);
cbUseDate.setChecked(account == null ? false : account.use_date);
cbUseReceived.setChecked(account == null ? false : account.use_received);
auth = (account == null ? EmailService.AUTH_TYPE_PASSWORD : account.auth_type);
provider = (account == null ? null : account.provider);

View File

@ -56,6 +56,7 @@ import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.NoSuchAlgorithmException;
import java.text.Normalizer;
import java.text.ParsePosition;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@ -1310,9 +1311,28 @@ public class MessageHelper {
Date received = imessage.getReceivedDate();
if (received == null)
received = imessage.getSentDate();
return (received == null ? new Date() : received).getTime();
}
Long getReceivedHeader() throws MessagingException {
String[] received = imessage.getHeader("Received");
if (received == null || received.length == 0)
return null;
String last = MimeUtility.unfold(received[0]);
int semi = last.lastIndexOf(';');
if (semi < 0)
return null;
MailDateFormat mdf = new MailDateFormat();
Date date = mdf.parse(last, new ParsePosition(semi + 1));
if (date == null)
return null;
return date.getTime();
}
Long getSent() throws MessagingException {
ensureMessage(false);

View File

@ -47,6 +47,7 @@ public class TupleAccountState extends EntityAccount {
this.partial_fetch.equals(other.partial_fetch) &&
this.ignore_size.equals(other.ignore_size) &&
this.use_date.equals(other.use_date) &&
this.use_received.equals(other.use_received) &&
this.folders == other.folders &&
Objects.equals(this.tbd, other.tbd));
} else

View File

@ -571,6 +571,15 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbIgnoreSize" />
<CheckBox
android:id="@+id/cbUseReceived"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_use_received"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbUseDate" />
<!-- check -->
<Button
@ -581,7 +590,7 @@
android:tag="disable"
android:text="@string/title_check"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbUseDate" />
app:layout_constraintTop_toBottomOf="@id/cbUseReceived" />
<eu.faircode.email.ContentLoadingProgressBar
android:id="@+id/pbCheck"
@ -956,7 +965,7 @@
cbBrowse,tvBrowseHint,
cbAutoSeen,
tvInterval,etInterval,tvIntervalRemark,
cbPartialFetch,tvPartialFetchRemark,cbIgnoreSize,cbUseDate" />
cbPartialFetch,tvPartialFetchRemark,cbIgnoreSize,cbUseDate,cbUseReceived" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpFolders"

View File

@ -632,7 +632,8 @@
<string name="title_keep_alive_interval">Keep-alive/poll interval (minutes)</string>
<string name="title_partial_fetch" translatable="false">Partial fetch</string>
<string name="title_ignore_size" translatable="false">Ignore bodystructure size</string>
<string name="title_use_date">Use date header sent time instead of server received time</string>
<string name="title_use_date">Use \'Date\' header instead of server received time</string>
<string name="title_use_received">Use \'Received\' header instead of server received time</string>
<string name="title_related_identity">Add related identity</string>
<string name="title_check">Check</string>
<string name="title_trust">Trust server certificate with fingerprint %1$s</string>