Browse Source

Workaround for providers erasing the message ID

Fixes #109
main
M66B 6 years ago
parent
commit
7a1053691c
3 changed files with 18 additions and 17 deletions
  1. +3
    -2
      app/src/main/java/eu/faircode/email/DaoMessage.java
  2. +8
    -8
      app/src/main/java/eu/faircode/email/MessageHelper.java
  3. +7
    -7
      app/src/main/java/eu/faircode/email/ServiceSynchronize.java

+ 3
- 2
app/src/main/java/eu/faircode/email/DaoMessage.java View File

@ -109,8 +109,9 @@ public interface DaoMessage {
@Query("SELECT message.* FROM message" +
" JOIN folder ON folder.id = message.folder" +
" WHERE message.account = :account" +
" AND message.msgid = :msgid")
List<EntityMessage> getMessageByMsgId(long account, String msgid);
" AND (message.msgid = :msgid" +
" OR message.msgid = :reference)")
List<EntityMessage> getMessageByMsgId(long account, String msgid, String reference);
@Query("SELECT message.* FROM message" +
" JOIN folder ON folder.id = message.folder" +


+ 8
- 8
app/src/main/java/eu/faircode/email/MessageHelper.java View File

@ -136,9 +136,16 @@ public class MessageHelper {
return props;
}
static MimeMessageEx from(Context context, EntityMessage message, List<EntityAttachment> attachments, Session isession) throws MessagingException, IOException {
static MimeMessageEx from(Context context, EntityMessage message, EntityMessage reply, List<EntityAttachment> attachments, Session isession) throws MessagingException, IOException {
MimeMessageEx imessage = new MimeMessageEx(isession, message.msgid);
if (reply == null)
imessage.addHeader("References", message.msgid);
else {
imessage.addHeader("In-Reply-To", reply.msgid);
imessage.addHeader("References", (reply.references == null ? "" : reply.references + " ") + reply.msgid);
}
imessage.setFlag(Flags.Flag.SEEN, message.seen);
if (message.from != null && message.from.length > 0)
@ -198,13 +205,6 @@ public class MessageHelper {
return imessage;
}
static MimeMessageEx from(Context context, EntityMessage message, EntityMessage reply, List<EntityAttachment> attachments, Session isession) throws MessagingException, IOException {
MimeMessageEx imessage = from(context, message, attachments, isession);
imessage.addHeader("In-Reply-To", reply.msgid);
imessage.addHeader("References", (reply.references == null ? "" : reply.references + " ") + reply.msgid);
return imessage;
}
MessageHelper(MimeMessage message) {
this.imessage = message;
}


+ 7
- 7
app/src/main/java/eu/faircode/email/ServiceSynchronize.java View File

@ -974,7 +974,7 @@ public class ServiceSynchronize extends LifecycleService {
private void doAdd(EntityFolder folder, Session isession, IMAPFolder ifolder, EntityMessage message, JSONArray jargs, DB db) throws MessagingException, JSONException, IOException {
// Append message
List<EntityAttachment> attachments = db.attachment().getAttachments(message.id);
MimeMessage imessage = MessageHelper.from(this, message, attachments, isession);
MimeMessage imessage = MessageHelper.from(this, message, null, attachments, isession);
AppendUID[] uid = ifolder.appendUIDMessages(new Message[]{imessage});
db.message().setMessageUid(message.id, uid[0].uid);
Log.i(Helper.TAG, "Appended uid=" + uid[0].uid);
@ -1014,7 +1014,7 @@ public class ServiceSynchronize extends LifecycleService {
ifolder.expunge();
}
MimeMessageEx icopy = MessageHelper.from(this, message, attachments, isession);
MimeMessageEx icopy = MessageHelper.from(this, message, null, attachments, isession);
Folder itarget = istore.getFolder(target.name);
itarget.appendMessages(new Message[]{icopy});
}
@ -1054,10 +1054,7 @@ public class ServiceSynchronize extends LifecycleService {
MimeMessage imessage;
EntityMessage reply = (message.replying == null ? null : db.message().getMessage(message.replying));
List<EntityAttachment> attachments = db.attachment().getAttachments(message.id);
if (reply == null)
imessage = MessageHelper.from(this, message, attachments, isession);
else
imessage = MessageHelper.from(this, message, reply, attachments, isession);
imessage = MessageHelper.from(this, message, reply, attachments, isession);
if (ident.replyto != null)
imessage.setReplyTo(new Address[]{new InternetAddress(ident.replyto)});
@ -1385,7 +1382,10 @@ public class ServiceSynchronize extends LifecycleService {
if (message == null) {
// Will fetch headers within database transaction
String msgid = helper.getMessageID();
for (EntityMessage dup : db.message().getMessageByMsgId(folder.account, msgid)) {
String[] refs = helper.getReferences();
String reference = (refs.length == 1 && refs[0].indexOf(BuildConfig.APPLICATION_ID) > 0 ? refs[0] : msgid);
Log.i(Helper.TAG, "Searching for " + msgid + " / " + reference);
for (EntityMessage dup : db.message().getMessageByMsgId(folder.account, msgid, reference)) {
EntityFolder dfolder = db.folder().getFolder(dup.folder);
boolean outbox = EntityFolder.OUTBOX.equals(dfolder.type);
Log.i(Helper.TAG, folder.name + " found as id=" + dup.id +


Loading…
Cancel
Save