Copy attachments to sent folder

pull/147/head
M66B 7 years ago
parent 5d8ad7ef9c
commit ee7771dedd

@ -22,6 +22,8 @@ package eu.faircode.email;
import android.content.Context;
import java.io.File;
import java.io.IOException;
import java.util.List;
import javax.mail.Part;
@ -79,6 +81,26 @@ public class EntityAttachment {
return new File(dir, Long.toString(id));
}
static void copy(Context context, DB db, long oldid, long newid) {
List<EntityAttachment> attachments = db.attachment().getAttachments(oldid);
for (EntityAttachment attachment : attachments) {
long aid = attachment.id;
attachment.id = null;
attachment.message = newid;
attachment.progress = null;
attachment.id = db.attachment().insertAttachment(attachment);
if (attachment.available)
try {
Helper.copy(
EntityAttachment.getFile(context, aid),
EntityAttachment.getFile(context, attachment.id));
} catch (IOException ex) {
Log.e(ex);
db.attachment().setProgress(attachment.id, null);
}
}
}
@Override
public boolean equals(Object obj) {
if (obj instanceof EntityAttachment) {

@ -27,7 +27,6 @@ import org.json.JSONException;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import androidx.annotation.NonNull;
import androidx.room.Entity;
@ -184,23 +183,7 @@ public class EntityOperation {
db.message().setMessageContent(newid, false, null);
}
List<EntityAttachment> attachments = db.attachment().getAttachments(message.id);
for (EntityAttachment attachment : attachments) {
long aid = attachment.id;
attachment.id = null;
attachment.message = newid;
attachment.progress = null;
attachment.id = db.attachment().insertAttachment(attachment);
if (attachment.available)
try {
Helper.copy(
EntityAttachment.getFile(context, aid),
EntityAttachment.getFile(context, attachment.id));
} catch (IOException ex) {
Log.e(ex);
db.attachment().setProgress(attachment.id, null);
}
}
EntityAttachment.copy(context, db, message.id, newid);
}
} else if (DELETE.equals(name))

@ -1822,6 +1822,8 @@ public class ServiceSynchronize extends LifecycleService {
message.ui_seen = false;
message.ui_browsed = false;
message.ui_hide = false;
EntityAttachment.copy(this, db, message.id, sid);
}
Address[] to = imessage.getAllRecipients();

Loading…
Cancel
Save