Added workaround for Yahoo JP

pull/205/head
M66B 3 years ago
parent 82cc2fc620
commit 7ed38b50fe

@ -1112,6 +1112,18 @@ public class IMAPMessage extends MimeMessage implements ReadableMime {
try { try {
IMAPProtocol p = getProtocol(); IMAPProtocol p = getProtocol();
checkExpunged(); // Insure that this message is not expunged checkExpunged(); // Insure that this message is not expunged
if (flag.contains(javax.mail.Flags.Flag.DELETED) &&
"imap.mail.yahoo.co.jp".equals(p.getInetAddress().getHostName())) {
// NO [CANNOT] STORE It's not possible to perform specified operation
long uid = ((IMAPFolder) getFolder()).getUID(this);
Response[] r = p.command("UID STORE " + uid +
" " + (set ? '+' : '-') + "FLAGS (\\Deleted)", null);
p.notifyResponseHandlers(r);
p.handleResult(r[r.length - 1]);
flag.remove(javax.mail.Flags.Flag.DELETED);
if (flag.getSystemFlags().length == 0)
return;
}
p.storeFlags(getSequenceNumber(), flag, set); p.storeFlags(getSequenceNumber(), flag, set);
} catch (ConnectionException cex) { } catch (ConnectionException cex) {
throw new FolderClosedException(folder, cex.getMessage()); throw new FolderClosedException(folder, cex.getMessage());

@ -368,7 +368,7 @@ class Core {
Log.w(folder.name + " ignored=" + op.name); Log.w(folder.name + " ignored=" + op.name);
} }
else { else {
ensureUid(context, folder, message, op, (IMAPFolder) ifolder); ensureUid(context, account, folder, message, op, (IMAPFolder) ifolder);
switch (op.name) { switch (op.name) {
case EntityOperation.SEEN: case EntityOperation.SEEN:
@ -445,7 +445,7 @@ class Core {
break; break;
case EntityOperation.PURGE: case EntityOperation.PURGE:
onPurgeFolder(context, jargs, folder, (IMAPFolder) ifolder); onPurgeFolder(context, jargs, account, folder, (IMAPFolder) ifolder);
break; break;
case EntityOperation.EXPUNGE: case EntityOperation.EXPUNGE:
@ -685,7 +685,7 @@ class Core {
} }
} }
private static void ensureUid(Context context, EntityFolder folder, EntityMessage message, EntityOperation op, IMAPFolder ifolder) throws MessagingException { private static void ensureUid(Context context, EntityAccount account, EntityFolder folder, EntityMessage message, EntityOperation op, IMAPFolder ifolder) throws MessagingException, IOException {
if (folder.local) if (folder.local)
return; return;
if (message == null || message.uid != null) if (message == null || message.uid != null)
@ -707,7 +707,7 @@ class Core {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
Long uid = findUid(context, ifolder, message.msgid, false); Long uid = findUid(context, account, ifolder, message.msgid, false);
if (uid == null) { if (uid == null) {
if (EntityOperation.MOVE.equals(op.name) && if (EntityOperation.MOVE.equals(op.name) &&
EntityFolder.DRAFTS.equals(folder.type)) EntityFolder.DRAFTS.equals(folder.type))
@ -729,15 +729,25 @@ class Core {
message.uid = uid; message.uid = uid;
} }
private static Long findUid(Context context, IMAPFolder ifolder, String msgid, boolean purge) throws MessagingException { private static Long findUid(Context context, EntityAccount account, IMAPFolder ifolder, String msgid, boolean purge) throws MessagingException, IOException {
String name = ifolder.getFullName(); String name = ifolder.getFullName();
Log.i(name + " searching for msgid=" + msgid); Log.i(name + " searching for msgid=" + msgid);
Long uid = null; Long uid = null;
Message[] imessages = ifolder.search(new MessageIDTerm(msgid)); Message[] imessages;
// https://stackoverflow.com/questions/18891509/how-to-get-message-from-messageidterm-for-yahoo-imap-profile
if (account.isYahooJp())
imessages = ifolder.search(new ReceivedDateTerm(ComparisonTerm.GE, new Date()));
else
imessages = ifolder.search(new MessageIDTerm(msgid));
if (imessages != null) { if (imessages != null) {
for (Message iexisting : imessages) { for (Message iexisting : imessages) {
if (account.isYahooJp()) {
MessageHelper helper = new MessageHelper((MimeMessage) iexisting, context);
if (!msgid.equals(helper.getMessageID()))
continue;
}
long muid = ifolder.getUID(iexisting); long muid = ifolder.getUID(iexisting);
if (muid < 0) if (muid < 0)
continue; continue;
@ -1137,7 +1147,7 @@ class Core {
// Some providers do not list the new message yet // Some providers do not list the new message yet
try { try {
Long found = findUid(context, ifolder, message.msgid, true); Long found = findUid(context, account, ifolder, message.msgid, true);
if (found != null) if (found != null)
if (newuid == null) if (newuid == null)
newuid = found; newuid = found;
@ -1175,7 +1185,7 @@ class Core {
int count = 0; int count = 0;
Long found = newuid; Long found = newuid;
while (found == null && count++ < FIND_RETRY_COUNT) { while (found == null && count++ < FIND_RETRY_COUNT) {
found = findUid(context, ifolder, message.msgid, false); found = findUid(context, account, ifolder, message.msgid, false);
if (found == null) if (found == null)
try { try {
Thread.sleep(FIND_RETRY_DELAY); Thread.sleep(FIND_RETRY_DELAY);
@ -1263,7 +1273,10 @@ class Core {
} }
// Some servers return different capabilities for different sessions // Some servers return different capabilities for different sessions
boolean canMove = MessageHelper.hasCapability(ifolder, "MOVE"); // NO [CANNOT] MOVE It's not possible to perform specified operation
// https://stackoverflow.com/questions/56148668/cannot-delete-emails-of-domain-co-jp-type
boolean canMove = !account.isYahooJp() &&
MessageHelper.hasCapability(ifolder, "MOVE");
// Some providers do not support the COPY operation for drafts // Some providers do not support the COPY operation for drafts
boolean draft = (EntityFolder.DRAFTS.equals(folder.type) || EntityFolder.DRAFTS.equals(target.type)); boolean draft = (EntityFolder.DRAFTS.equals(folder.type) || EntityFolder.DRAFTS.equals(target.type));
@ -1400,7 +1413,7 @@ class Core {
if (TextUtils.isEmpty(msgid)) if (TextUtils.isEmpty(msgid))
throw new IllegalArgumentException("move: msgid missing"); throw new IllegalArgumentException("move: msgid missing");
Long uid = findUid(context, itarget, msgid, false); Long uid = findUid(context, account, itarget, msgid, false);
if (uid == null) if (uid == null)
throw new IllegalArgumentException("move: uid not found"); throw new IllegalArgumentException("move: uid not found");
@ -2312,7 +2325,7 @@ class Core {
Log.i(folder.name + " subscribed=" + subscribe); Log.i(folder.name + " subscribed=" + subscribe);
} }
private static void onPurgeFolder(Context context, JSONArray jargs, EntityFolder folder, IMAPFolder ifolder) throws MessagingException { private static void onPurgeFolder(Context context, JSONArray jargs, EntityAccount account, EntityFolder folder, IMAPFolder ifolder) throws MessagingException {
// Delete all messages from folder // Delete all messages from folder
try { try {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
@ -2333,6 +2346,10 @@ class Core {
} }
EntityLog.log(context, folder.name + " purging=" + idelete.size() + "/" + imessages.length); EntityLog.log(context, folder.name + " purging=" + idelete.size() + "/" + imessages.length);
if (account.isYahooJp()) {
for (Message imessage : idelete)
imessage.setFlag(Flags.Flag.DELETED, true);
} else
ifolder.setFlags(idelete.toArray(new Message[0]), new Flags(Flags.Flag.DELETED), true); ifolder.setFlags(idelete.toArray(new Message[0]), new Flags(Flags.Flag.DELETED), true);
Log.i(folder.name + " purge deleted"); Log.i(folder.name + " purge deleted");

@ -158,6 +158,10 @@ public class EntityAccount extends EntityOrder implements Serializable {
return "imap.gmail.com".equalsIgnoreCase(host); return "imap.gmail.com".equalsIgnoreCase(host);
} }
boolean isYahooJp() {
return "imap.mail.yahoo.co.jp".equalsIgnoreCase(host);
}
boolean isTransient(Context context) { boolean isTransient(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean enabled = prefs.getBoolean("enabled", true); boolean enabled = prefs.getBoolean("enabled", true);

Loading…
Cancel
Save