|
|
|
@ -464,21 +464,30 @@ class Core {
|
|
|
|
|
// Move message
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
|
|
|
|
|
|
Message imessage = ifolder.getMessageByUID(message.uid);
|
|
|
|
|
if (imessage == null)
|
|
|
|
|
throw new MessageRemovedException();
|
|
|
|
|
|
|
|
|
|
// Get arguments
|
|
|
|
|
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 source message
|
|
|
|
|
Message imessage = ifolder.getMessageByUID(message.uid);
|
|
|
|
|
if (imessage == null)
|
|
|
|
|
throw new MessageRemovedException();
|
|
|
|
|
|
|
|
|
|
// Get target folder
|
|
|
|
|
EntityFolder target = db.folder().getFolder(id);
|
|
|
|
|
if (target == null)
|
|
|
|
|
throw new FolderNotFoundException();
|
|
|
|
|
IMAPFolder itarget = (IMAPFolder) istore.getFolder(target.name);
|
|
|
|
|
|
|
|
|
|
// Get message ID
|
|
|
|
|
String msgid;
|
|
|
|
|
if (copy || message.msgid == null) {
|
|
|
|
|
msgid = EntityMessage.generateMessageId();
|
|
|
|
|
Log.i(target.name + " generated message id=" + msgid);
|
|
|
|
|
} else
|
|
|
|
|
msgid = message.msgid;
|
|
|
|
|
|
|
|
|
|
// Serialize source message
|
|
|
|
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
|
|
|
imessage.writeTo(bos);
|
|
|
|
@ -487,13 +496,6 @@ class Core {
|
|
|
|
|
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
|
|
|
|
|
Message icopy = new MimeMessage(isession, bis);
|
|
|
|
|
|
|
|
|
|
// Make sure the message has a message ID
|
|
|
|
|
if (copy || message.msgid == null) {
|
|
|
|
|
String msgid = EntityMessage.generateMessageId();
|
|
|
|
|
Log.i(target.name + " generated message id=" + msgid);
|
|
|
|
|
icopy.setHeader("Message-ID", msgid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// Needed to read flags
|
|
|
|
|
itarget.open(Folder.READ_WRITE);
|
|
|
|
@ -513,6 +515,8 @@ class Core {
|
|
|
|
|
if (itarget.getPermanentFlags().contains(Flags.Flag.DRAFT))
|
|
|
|
|
icopy.setFlag(Flags.Flag.DRAFT, true);
|
|
|
|
|
|
|
|
|
|
icopy.setHeader("Message-ID", msgid);
|
|
|
|
|
|
|
|
|
|
// Append target
|
|
|
|
|
long uid = append(istore, itarget, (MimeMessage) icopy);
|
|
|
|
|
if (newid != null) {
|
|
|
|
@ -520,6 +524,10 @@ class Core {
|
|
|
|
|
db.message().setMessageUid(newid, uid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fixed timing issue of at least Courier based servers
|
|
|
|
|
itarget.close(false);
|
|
|
|
|
itarget.open(Folder.READ_WRITE);
|
|
|
|
|
|
|
|
|
|
// Some providers, like Gmail, don't honor the appended seen flag
|
|
|
|
|
if (itarget.getPermanentFlags().contains(Flags.Flag.SEEN)) {
|
|
|
|
|
boolean seen = (autoread || message.ui_seen);
|
|
|
|
@ -671,10 +679,6 @@ class Core {
|
|
|
|
|
} else
|
|
|
|
|
ifolder.appendMessages(new Message[]{imessage});
|
|
|
|
|
|
|
|
|
|
// Fixed timing issue of at least Courier based servers
|
|
|
|
|
ifolder.close(false);
|
|
|
|
|
ifolder.open(Folder.READ_WRITE);
|
|
|
|
|
|
|
|
|
|
if (uid <= 0) {
|
|
|
|
|
Log.i("Searching for appended msgid=" + msgid);
|
|
|
|
|
Message[] messages = ifolder.search(new MessageIDTerm(msgid));
|
|
|
|
|