mirror of https://github.com/M66B/FairEmail.git
Better IMAP compatibility
This commit is contained in:
parent
8580e29bd4
commit
dfc8fee370
|
@ -18,6 +18,7 @@ import android.text.TextUtils;
|
||||||
|
|
||||||
import com.sun.mail.iap.ConnectionException;
|
import com.sun.mail.iap.ConnectionException;
|
||||||
import com.sun.mail.iap.Response;
|
import com.sun.mail.iap.Response;
|
||||||
|
import com.sun.mail.imap.AppendUID;
|
||||||
import com.sun.mail.imap.IMAPFolder;
|
import com.sun.mail.imap.IMAPFolder;
|
||||||
import com.sun.mail.imap.IMAPMessage;
|
import com.sun.mail.imap.IMAPMessage;
|
||||||
import com.sun.mail.imap.IMAPStore;
|
import com.sun.mail.imap.IMAPStore;
|
||||||
|
@ -423,7 +424,7 @@ class Core {
|
||||||
imessage.setFlag(Flags.Flag.DRAFT, true);
|
imessage.setFlag(Flags.Flag.DRAFT, true);
|
||||||
|
|
||||||
// Add message
|
// Add message
|
||||||
long uid = append(ifolder, imessage);
|
long uid = append(istore, ifolder, imessage);
|
||||||
Log.i(folder.name + " appended id=" + message.id + " uid=" + uid);
|
Log.i(folder.name + " appended id=" + message.id + " uid=" + uid);
|
||||||
db.message().setMessageUid(message.id, uid);
|
db.message().setMessageUid(message.id, uid);
|
||||||
|
|
||||||
|
@ -467,30 +468,17 @@ class Core {
|
||||||
if (imessage == null)
|
if (imessage == null)
|
||||||
throw new MessageRemovedException();
|
throw new MessageRemovedException();
|
||||||
|
|
||||||
// Get target folder
|
// Get arguments
|
||||||
long id = jargs.getLong(0);
|
long id = jargs.getLong(0);
|
||||||
|
boolean autoread = (jargs.length() > 1 && jargs.getBoolean(1));
|
||||||
|
Long newid = (jargs.length() > 2 && !jargs.isNull(2) ? jargs.getLong(2) : null);
|
||||||
|
|
||||||
|
// Get target folder
|
||||||
EntityFolder target = db.folder().getFolder(id);
|
EntityFolder target = db.folder().getFolder(id);
|
||||||
if (target == null)
|
if (target == null)
|
||||||
throw new FolderNotFoundException();
|
throw new FolderNotFoundException();
|
||||||
IMAPFolder itarget = (IMAPFolder) istore.getFolder(target.name);
|
IMAPFolder itarget = (IMAPFolder) istore.getFolder(target.name);
|
||||||
|
|
||||||
boolean autoread = (jargs.length() > 1 && jargs.getBoolean(1));
|
|
||||||
|
|
||||||
if (!copy &&
|
|
||||||
istore.hasCapability("MOVE") &&
|
|
||||||
!EntityFolder.DRAFTS.equals(folder.type) &&
|
|
||||||
!EntityFolder.DRAFTS.equals(target.type)) {
|
|
||||||
// Autoread
|
|
||||||
if (ifolder.getPermanentFlags().contains(Flags.Flag.SEEN))
|
|
||||||
if (autoread && !imessage.isSet(Flags.Flag.SEEN))
|
|
||||||
imessage.setFlag(Flags.Flag.SEEN, true);
|
|
||||||
|
|
||||||
// Move message to target folder
|
|
||||||
ifolder.moveMessages(new Message[]{imessage}, itarget);
|
|
||||||
} else {
|
|
||||||
if (!copy)
|
|
||||||
Log.w(folder.name + " MOVE by DELETE/APPEND");
|
|
||||||
|
|
||||||
// Serialize source message
|
// Serialize source message
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
imessage.writeTo(bos);
|
imessage.writeTo(bos);
|
||||||
|
@ -526,7 +514,11 @@ class Core {
|
||||||
icopy.setFlag(Flags.Flag.DRAFT, true);
|
icopy.setFlag(Flags.Flag.DRAFT, true);
|
||||||
|
|
||||||
// Append target
|
// Append target
|
||||||
long uid = append(itarget, (MimeMessage) icopy);
|
long uid = append(istore, itarget, (MimeMessage) icopy);
|
||||||
|
if (newid != null) {
|
||||||
|
Log.i("Moved id=" + newid + " uid=" + uid);
|
||||||
|
db.message().setMessageUid(newid, uid);
|
||||||
|
}
|
||||||
|
|
||||||
// Some providers, like Gmail, don't honor the appended seen flag
|
// Some providers, like Gmail, don't honor the appended seen flag
|
||||||
if (itarget.getPermanentFlags().contains(Flags.Flag.SEEN)) {
|
if (itarget.getPermanentFlags().contains(Flags.Flag.SEEN)) {
|
||||||
|
@ -558,7 +550,6 @@ class Core {
|
||||||
itarget.close();
|
itarget.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static void onDelete(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, IMAPFolder ifolder) throws MessagingException {
|
private static void onDelete(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, IMAPFolder ifolder) throws MessagingException {
|
||||||
// Delete message
|
// Delete message
|
||||||
|
@ -665,11 +656,18 @@ class Core {
|
||||||
parts.downloadAttachment(context, sequence - 1, attachment.id);
|
parts.downloadAttachment(context, sequence - 1, attachment.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static long append(IMAPFolder ifolder, MimeMessage imessage) throws MessagingException {
|
private static long append(IMAPStore istore, IMAPFolder ifolder, MimeMessage imessage) throws MessagingException {
|
||||||
String msgid = imessage.getMessageID();
|
String msgid = imessage.getMessageID();
|
||||||
if (msgid == null)
|
if (msgid == null)
|
||||||
throw new IllegalArgumentException("Message ID missing");
|
throw new IllegalArgumentException("Message ID missing");
|
||||||
|
|
||||||
|
if (istore.hasCapability("UIDPLUS")) {
|
||||||
|
AppendUID[] uids = ifolder.appendUIDMessages(new Message[]{imessage});
|
||||||
|
if (uids != null && uids.length > 0) {
|
||||||
|
Log.i("Appended uid=" + uids[0].uid);
|
||||||
|
return uids[0].uid;
|
||||||
|
}
|
||||||
|
} else
|
||||||
ifolder.appendMessages(new Message[]{imessage});
|
ifolder.appendMessages(new Message[]{imessage});
|
||||||
|
|
||||||
// Fixed timing issue of at least Courier based servers
|
// Fixed timing issue of at least Courier based servers
|
||||||
|
|
Loading…
Reference in New Issue